Class RegistryImpl

    • Constructor Detail

      • RegistryImpl

        public RegistryImpl​(Collection<ModuleDef2> moduleDefs,
                            PlasticProxyFactory proxyFactory,
                            LoggerSource loggerSource,
                            OperationTracker operationTracker)
        Constructs the registry from a set of module definitions and other resources.
        Parameters:
        moduleDefs - defines the modules (and builders, decorators, etc., within)
        proxyFactory - used to create new proxy objects
        loggerSource - used to obtain Logger instances
        operationTracker -
    • Method Detail

      • performRegistryStartup

        public void performRegistryStartup()
        It's not unreasonable for an eagerly-loaded service to decide to start a thread, at which point we raise issues about improper publishing of the Registry instance from the RegistryImpl constructor. Moving eager loading of services out to its own method should ensure thread safety.
        Specified by:
        performRegistryStartup in interface Registry
      • shutdown

        public void shutdown()
        Description copied from interface: Registry
        Shuts down a Registry instance. Notifies all listeners that the registry has shutdown. Further method invocations on the Registry are no longer allowed, and the Registry instance should be discarded.
        Specified by:
        shutdown in interface Registry
        See Also:
        RegistryShutdownHub, RegistryShutdownListener
      • getService

        public <T> T getService​(String serviceId,
                                Class<T> serviceInterface)
        Description copied from interface: ObjectLocator
        Obtains a service via its unique service id. Returns the service's proxy. The service proxy implements the same interface as the actual service, and is used to instantiate the actual service only as needed (this is transparent to the application).
        Specified by:
        getService in interface ObjectLocator
        Parameters:
        serviceId - unique Service id used to locate the service object (may contain symbols, which will be expanded), case is ignored
        serviceInterface - the interface implemented by the service (or an interface extended by the service interface)
        Returns:
        the service instance
      • getUnorderedConfiguration

        public <T> Collection<T> getUnorderedConfiguration​(ServiceDef3 serviceDef,
                                                           Class<T> objectType)
        Description copied from interface: InternalRegistry
        Builds up an unordered collection by invoking service contributor methods that target the service (from any module, unless the service is private).
        Specified by:
        getUnorderedConfiguration in interface InternalRegistry
        Parameters:
        serviceDef - defines the service for which configuration data is being assembled
        objectType - identifies the type of object allowed into the collection
        Returns:
        the final collection
      • getOrderedConfiguration

        public <T> List<T> getOrderedConfiguration​(ServiceDef3 serviceDef,
                                                   Class<T> objectType)
        Description copied from interface: InternalRegistry
        Builds up an ordered collection by invoking service contributor methods that target the service (from any module, unless the service is private). Once all values have been added (each with an id, and pre/post constraints), the values are ordered, null values dropped, and the final sorted list is returned.
        Specified by:
        getOrderedConfiguration in interface InternalRegistry
        Parameters:
        serviceDef - defines the service for which configuration data is being assembled
        objectType - identifies the type of object allowed into the collection
        Returns:
        the final ordered list
      • getMappedConfiguration

        public <K,​V> Map<K,​V> getMappedConfiguration​(ServiceDef3 serviceDef,
                                                                 Class<K> keyType,
                                                                 Class<V> objectType)
        Description copied from interface: InternalRegistry
        Builds up a map of key/value pairs by invoking service contribution methods that target the service (from any module, unless the service is private). Values and keys may not be null. Invalid values (keys or values that are the wrong type, or duplicate keys) result in warnings and are ignored.
        Specified by:
        getMappedConfiguration in interface InternalRegistry
        Parameters:
        serviceDef - defines the service for which configuration data is being assembled
        keyType - identifies the type of key object allowed into the map
        objectType - identifies the type of value object allowed into the map
        Returns:
        the final ordered list
      • getService

        public <T> T getService​(Class<T> serviceInterface)
        Description copied from interface: ObjectLocator
        Locates a service given a service interface and (optionally) some marker annotation types. A single service must implement the service interface (which * can be hard to guarantee) and by marked by all the marker types. The search takes into account inheritance of the service interface (not the service implementation), which may result in a failure due to extra matches.
        Specified by:
        getService in interface ObjectLocator
        Parameters:
        serviceInterface - the interface the service implements
        Returns:
        the service's proxy
        See Also:
        Marker
      • getService

        public <T> T getService​(Class<T> serviceInterface,
                                Class<? extends Annotation>... markerTypes)
        Description copied from interface: ObjectLocator
        Locates a service given a service interface and (optionally) some marker annotation types. A single service must implement the service interface (which * can be hard to guarantee) and by marked by all the marker types. The search takes into account inheritance of the service interface (not the service implementation), which may result in a failure due to extra matches. The ability to specify marker annotation types was added in 5.3
        Specified by:
        getService in interface ObjectLocator
        Parameters:
        serviceInterface - the interface the service implements
        markerTypes - Markers used to select a specific service that implements the interface
        Returns:
        the service's proxy
        See Also:
        Marker
      • getObject

        public <T> T getObject​(Class<T> objectType,
                               AnnotationProvider annotationProvider)
        Description copied from interface: ObjectLocator
        Obtains an object indirectly, using the MasterObjectProvider service.
        Specified by:
        getObject in interface ObjectLocator
        Parameters:
        objectType - the type of object to be returned
        annotationProvider - provides access to annotations on the field or parameter for which a value is to be obtained, which may be utilized in selecting an appropriate object, use null when annotations are not available (in which case, selection will be based only on the object type)
        Returns:
        the requested object
        See Also:
        ObjectProvider
      • autobuild

        public <T> T autobuild​(Class<T> clazz)
        Description copied from interface: ObjectLocator
        Autobuilds a class by finding the public constructor with the most parameters. Services and other resources or dependencies will be injected into the parameters of the constructor and into private fields marked with the Inject annotation. There are two cases: constructing a service implementation, and constructing an arbitrary object. In the former case, many service resources are also available for injection, not just dependencies or objects provided via the MasterObjectProvider service.
        Specified by:
        autobuild in interface ObjectLocator
        Parameters:
        clazz - the type of object to instantiate
        Returns:
        the instantiated instance
      • proxy

        public <T> T proxy​(Class<T> interfaceClass,
                           Class<? extends T> implementationClass)
        Description copied from interface: ObjectLocator
        Creates a proxy. The proxy will defer invocation of ObjectLocator.autobuild(Class) until just-in-time (that is, first method invocation). In a limited number of cases, it is necessary to use such a proxy to prevent service construction cycles, particularly when contributing (directly or indirectly) to the MasterObjectProvider (which is itself at the heart of autobuilding). If the class file for the class is a file on the file system (not a file packaged in a JAR), then the proxy will autoreload: changing the class file will result in the new class being reloaded and re-instantiated (with dependencies).
        Specified by:
        proxy in interface ObjectLocator
        Parameters:
        interfaceClass - the interface implemented by the proxy
        implementationClass - a concrete class that implements the interface
        Returns:
        a proxy
        See Also:
        ObjectLocator.autobuild(Class)
      • proxy

        public <T> T proxy​(Class<T> interfaceClass,
                           Class<? extends T> implementationClass,
                           ObjectLocator locator)
        Description copied from interface: InternalRegistry
        Creates a just-in-time (and possibly, live reloading) proxy for the indicated class and interface, using the provided locator to autobuild the implementationClass (when necessary).
        Specified by:
        proxy in interface InternalRegistry