Interface ModulesRegistry

All Superinterfaces:
ModuleChangeListener
All Known Implementing Classes:
AbstractModulesRegistryImpl, ClassPathBasedModulesRegistry, ModulesRegistryImpl, SingleModulesRegistry, StaticModulesRegistry

@Contract public interface ModulesRegistry extends ModuleChangeListener
  • Method Details

    • createChild

      ModulesRegistry createChild()
      Creates a new child ModulesRegistry in this ModulesRegistry.
    • newServiceLocator

      ServiceLocator newServiceLocator() throws MultiException
      Creates an uninitialized ServiceLocator
      Throws:
      MultiException
    • createServiceLocator

      ServiceLocator createServiceLocator() throws MultiException
      Creates the default ServiceLocator from all the modules in this registry Calling this method has the same effect of calling
      invalid @link
      {@link #createServiceLocator("default")
      }
      Parameters:
      name - Determines which inhabitants descriptors are loaded. (so that different parallel habitats can be created over the same modules registry.)
      Throws:
      MultiException
    • createServiceLocator

      ServiceLocator createServiceLocator(String name) throws MultiException
      Creates a ServiceLocator from all the modules in this registry Cal;ling this method has the same effect of calling newServiceLocator() followed by
      invalid @link
      {@link #populateServiceLocator(String, org.glassfish.hk2.api.ServiceLocator, java.util.List
      }.
      Parameters:
      name - Determines which inhabitants descriptors are loaded. (so that different parallel habitats can be created over the same modules registry.)
      Throws:
      MultiException
    • createServiceLocator

      ServiceLocator createServiceLocator(ServiceLocator serviceLocator, String name, List<PopulatorPostProcessor> postProcessors)
      Creates a ServiceLocator with the provided parent.
      Parameters:
      serviceLocator -
      name -
      postProcessors -
      Returns:
    • populateServiceLocator

      void populateServiceLocator(String name, ServiceLocator h, List<PopulatorPostProcessor> postProcessors) throws MultiException
      Populates a ServiceLocator from all the modules in this registry.

      Default

      invalid reference
      InhabitantsParser
      is used.
      Parameters:
      name - Determines which inhabitants descriptors are loaded. (so that different parallel habitats can be created over the same modules registry.)
      h - Habitat to initialize, null if it should be created
      postProcessors -
      Throws:
      MultiException
    • addRepository

      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).
      Parameters:
      repository - new repository to attach to this registry
      weight - int value from 1 to 100 to specify the search order
    • addRepository

      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.
      Parameters:
      repository - new repository to attach to this registry
    • removeRepository

      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
      Parameters:
      name - name of the repository to remove
    • getRepository

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

      Module makeModuleFor(String name, String version) throws ResolveError
      Returns the Module instance giving a name and version constraints.
      Parameters:
      name - the module name
      version - the module version. Caller should specify a correct version.
      Returns:
      the module instance or null if none can be found
      Throws:
      ResolveError - if the module dependencies cannot be resolved
    • makeModuleFor

      Module makeModuleFor(String name, String version, boolean resolve) throws ResolveError
      Returns the Module instance giving a name and version constraints.
      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

      Module makeModuleFor(String packageName) throws ResolveError
      Find and return a loaded Module that has the package name in its list of exported interfaces.
      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
    • getModules

      Collection<Module> getModules()
      Returns the list of shared Modules registered in this instance.

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

      Returns:
      an umodifiable list of loaded modules
    • getModules

      Collection<Module> getModules(String moduleName)
      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.

      Returns:
      an umodifiable list of loaded modules having names that match the given name
    • detachAll

      void detachAll()
      Detaches all the modules from this registry. The modules are not deconstructed when calling this method.
    • add

      Registers a new DefaultModuleDefinition in this registry. Using this module definition, the registry will be capable of created shared and private Module instances.
      Throws:
      ResolveError
    • add

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

      void print(Logger logger)
      Print a Registry dump to the logger
      Parameters:
      logger - the logger to dump on
    • register

      void register(ModuleLifecycleListener listener)
      Add a ModuleLifecycleListener to this registry. The listener will be notified for each module startup and shutdown.
      Parameters:
      listener - the listener implementation
    • unregister

      void unregister(ModuleLifecycleListener listener)
      Removes an ModuleLifecycleListener from this registry. Notification of module startup and shutdown will not be emitted to this listener any longer.
      Parameters:
      listener - the listener to unregister
    • shutdown

      void shutdown()
      Shuts down this module's registry, apply housekeeping tasks
    • dumpState

      void dumpState(PrintStream writer)
    • getProvidersClass

      <T> Iterable<Class<? extends T>> getProvidersClass(Class<T> serviceClass)
    • getModulesProvider

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

      <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.
      Parameters:
      serviceClass - the service interface
      provider - the provider of that service.
    • unregisterRunningService

      <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.
    • getRunningServices

      <T> List<T> getRunningServices(Class<T> serviceClass)
      Returns all running services implementation of the passed service interface
      Parameters:
      serviceClass - the service interface
      Returns:
      the list of providers of that service.
    • setParentClassLoader

      void setParentClassLoader(ClassLoader parent)
    • getParentClassLoader

      ClassLoader getParentClassLoader()
    • getModulesClassLoader

      ClassLoader getModulesClassLoader(ClassLoader parent, Collection<ModuleDefinition> defs) throws ResolveError
      Returns a ClassLoader capable of loading classes from a set of modules identified by their module definition
      Parameters:
      parent - the parent class loader for the returned class loader instance
      defs - module definitions for all modules this classloader should be capable of loading classes from
      Returns:
      class loader instance
      Throws:
      ResolveError - if one of the provided module definition cannot be resolved
    • getModulesClassLoader

      ClassLoader getModulesClassLoader(ClassLoader parent, Collection<ModuleDefinition> defs, URL[] urls) throws ResolveError
      Returns a ClassLoader capable of loading classes from a set of modules identified by their module definition and also load new urls.
      Parameters:
      parent - the parent class loader for the returned class loader instance
      defs - module definitions for all modules this classloader should be capable of loading
      urls - urls to be added to the module classloader
      Returns:
      class loader instance
      Throws:
      ResolveError - if one of the provided module definition cannot be resolved
    • find

      Module find(Class clazz)
      Finds the Module that owns the given class.
      Returns:
      null if the class is loaded outside the module system.
    • getProvidingModule

      Module getProvidingModule(String providerClassName)
      Gets the Module that provides the provider of the given name.
    • newServiceLocator

      ServiceLocator newServiceLocator(ServiceLocator parent) throws MultiException
      Throws:
      MultiException
    • populateConfig

      void populateConfig(ServiceLocator serviceLocator) throws MultiException
      Throws:
      MultiException