Class AbstractModulesRegistryImpl

  • All Implemented Interfaces:
    ModuleChangeListener, ModulesRegistry
    Direct Known Subclasses:
    ModulesRegistryImpl

    public abstract class AbstractModulesRegistryImpl
    extends Object
    implements ModulesRegistry
    The Modules Registry maintains the registry of all available module. TODO: concurrency bug in the acess of the repositories field.
    Author:
    Jerome Dochez, Sanjeeb.Sahoo@Sun.COM
    • Field Detail

      • parent

        protected final ModulesRegistry parent
        ModulesRegistry can form a tree structure by using this pointer. It works in a way similar to the classloader tree. Modules defined in the parent are visible to children.
      • providers

        protected final Map<String,​Module> providers
        Service provider class names and which modules they are in.

        This is used for the classloader punch-in hack — to work nicely with classic service loader implementation, we need to be able to allow any modules to see these classes.

    • Constructor Detail

      • AbstractModulesRegistryImpl

        protected AbstractModulesRegistryImpl​(ModulesRegistry parent)
    • Method Detail

      • addRepository

        public void addRepository​(Repository repository,
                                  int weight)
        Add a new Repository to this registry. From now on the repository will be used to procure requested module not yet registered in this registry instance. Repository can be searched in a particular order (to accomodate performance requirements like looking at local repositories first), a search order (1 to 100) can be specified when adding a repository to the registry (1 is highest priority).
        Specified by:
        addRepository in interface ModulesRegistry
        Parameters:
        repository - new repository to attach to this registry
        weight - int value from 1 to 100 to specify the search order
      • addRepository

        public void addRepository​(Repository repository)
        Add a new Repository to this registry. From now on the repository will be used to procure requested nodule not registered in this instance.
        Specified by:
        addRepository in interface ModulesRegistry
        Parameters:
        repository - new repository to attach to this registry
      • removeRepository

        public void removeRepository​(String name)
        Remove a repository from the list of attached repositories to this instances. After this call, the Repository name will not be used to procure missing modules any longer
        Specified by:
        removeRepository in interface ModulesRegistry
        Parameters:
        name - name of the repository to remove
      • getRepository

        public Repository getRepository​(String name)
        Get a repository from the list of attached repositories
        Specified by:
        getRepository in interface ModulesRegistry
        Parameters:
        name - name of the repository to return
        Returns:
        the repository or null if not found
      • makeModuleFor

        public Module makeModuleFor​(String name,
                                    String version)
                             throws ResolveError
        Returns the Module instance giving a name and version constraints.
        Specified by:
        makeModuleFor in interface ModulesRegistry
        Parameters:
        name - the module name
        version - the module version.
        Returns:
        the module instance or null if none can be found
        Throws:
        ResolveError - if the module dependencies cannot be resolved
      • makeModuleFor

        public Module makeModuleFor​(String name,
                                    String version,
                                    boolean resolve)
                             throws ResolveError
        Description copied from interface: ModulesRegistry
        Returns the Module instance giving a name and version constraints.
        Specified by:
        makeModuleFor in interface ModulesRegistry
        Parameters:
        name - the module name
        version - the module version. Caller should specify a correct version.
        resolve - should the module be resolved or not
        Returns:
        the module instance or null if none can be found
        Throws:
        ResolveError - if the module dependencies cannot be resolved
      • makeModuleFor

        public Module makeModuleFor​(String packageName)
                             throws ResolveError
        Find and return a loaded Module that has the package name in its list of exported interfaces.
        Specified by:
        makeModuleFor in interface ModulesRegistry
        Parameters:
        packageName - the requested implementation package name.
        Returns:
        the Module instance implementing the package name or null if not found.
        Throws:
        ResolveError - if the module dependencies cannot be resolved
      • loadFromRepository

        protected Module loadFromRepository​(String name,
                                            String version)
      • newModule

        protected abstract Module newModule​(ModuleDefinition moduleDef)
        Factory method for creating new instances of Module.
        Parameters:
        moduleDef - module definition of the new module to be created
        Returns:
        a new Module instance
      • add

        protected void add​(Module newModule)
        Add a new module to this registry. Once added, the module will be available through one of the getServiceImplementor methods.
        Parameters:
        newModule - the new module
      • remove

        public void remove​(Module module)
        Removes a module from the registry. The module will not be accessible from this registry after this method returns.
      • getModules

        public Collection<Module> getModules​(String moduleName)
        Description copied from interface: ModulesRegistry
        Returns the list of shared Modules registered in this instance whose name matches the given name

        The returned list will not include the modules defined in the ancestor ModulesRegistrys.

        Specified by:
        getModules in interface ModulesRegistry
        Returns:
        an umodifiable list of loaded modules having names that match the given name
      • changed

        public void changed​(Module service)
        Modules can notify their registry that they have changed (classes, resources,etc...). Registries are requested to take appropriate action to make the new module available.
        Specified by:
        changed in interface ModuleChangeListener
      • add

        public Module add​(ModuleDefinition info,
                          boolean resolve)
                   throws ResolveError
        Description copied from interface: ModulesRegistry
        Registers a new DefaultModuleDefinition in this registry. Using this module definition, the registry will be capable of created shared and private Module instances.
        Specified by:
        add in interface ModulesRegistry
        Parameters:
        info - ModuleDefinition representing the new module content
        resolve - should the new module be resolved or not
        Throws:
        ResolveError
      • print

        public void print​(Logger logger)
        Print a Registry dump to the logger
        Specified by:
        print in interface ModulesRegistry
        Parameters:
        logger - the logger to dump on
      • getModulesProvider

        public Iterable<Module> getModulesProvider​(Class serviceClass)
        Returns a collection of Module containing at least one implementation of the passed service interface class.
        Specified by:
        getModulesProvider in interface ModulesRegistry
        Parameters:
        serviceClass - the service interface class
        Returns:
        a collection of module
      • registerRunningService

        public <T> void registerRunningService​(Class<T> serviceClass,
                                               T provider)
        Registers a running service, this is useful when other components need to have access to a provider of a service without having to create a new instance and initialize it.
        Specified by:
        registerRunningService in interface ModulesRegistry
        Parameters:
        serviceClass - the service interface
        provider - the provider of that service.
      • unregisterRunningService

        public <T> boolean unregisterRunningService​(Class<T> serviceClass,
                                                    T provider)
        Removes a running service, this is useful when a service instance is no longer available as a provider of a service.
        Specified by:
        unregisterRunningService in interface ModulesRegistry
      • getRunningServices

        public <T> List<T> getRunningServices​(Class<T> serviceClass)
        Returns all running services implementation of the passed service interface
        Specified by:
        getRunningServices in interface ModulesRegistry
        Parameters:
        serviceClass - the service interface
        Returns:
        the list of providers of that service.