@Contract public interface ModulesRegistry extends ModuleChangeListener
Modifier and Type | Method and Description |
---|---|
Module |
add(ModuleDefinition info)
Registers a new DefaultModuleDefinition in this registry.
|
Module |
add(ModuleDefinition info,
boolean resolve)
Registers a new DefaultModuleDefinition in this registry.
|
void |
addRepository(Repository repository)
Add a new
Repository to this registry. |
void |
addRepository(Repository repository,
int weight)
Add a new
Repository to this registry. |
ModulesRegistry |
createChild()
Creates a new child
ModulesRegistry in this ModulesRegistry . |
ServiceLocator |
createServiceLocator()
Creates the default
ServiceLocator from all the modules in this registry
Calling this method has the same effect of calling #createServiceLocator("default") |
ServiceLocator |
createServiceLocator(ServiceLocator serviceLocator,
String name,
List<PopulatorPostProcessor> postProcessors)
Creates a
ServiceLocator with the provided parent. |
ServiceLocator |
createServiceLocator(String name)
Creates a
ServiceLocator from all the modules in this registry
Cal;ling this method has the same effect of calling newServiceLocator() followed by
#populateServiceLocator(String, org.glassfish.hk2.api.ServiceLocator, java.util.List . |
void |
detachAll()
Detaches all the modules from this registry.
|
void |
dumpState(PrintStream writer) |
Module |
find(Class clazz)
Finds the
Module that owns the given class. |
Collection<Module> |
getModules()
Returns the list of shared Modules registered in this instance.
|
Collection<Module> |
getModules(String moduleName)
Returns the list of shared Modules registered in this instance whose name
matches the given name
|
ClassLoader |
getModulesClassLoader(ClassLoader parent,
Collection<ModuleDefinition> defs)
Returns a ClassLoader capable of loading classes from a set of modules identified
by their module definition
|
ClassLoader |
getModulesClassLoader(ClassLoader parent,
Collection<ModuleDefinition> defs,
URL[] urls)
Returns a ClassLoader capable of loading classes from a set of modules identified
by their module definition and also load new urls.
|
Iterable<Module> |
getModulesProvider(Class serviceClass)
Returns a collection of Module containing at least one implementation
of the passed service interface class.
|
ClassLoader |
getParentClassLoader() |
<T> Iterable<Class<? extends T>> |
getProvidersClass(Class<T> serviceClass) |
Module |
getProvidingModule(String providerClassName)
Gets the
Module that provides the provider of the given name. |
Repository |
getRepository(String name)
Get a repository from the list of attached repositories
|
<T> List<T> |
getRunningServices(Class<T> serviceClass)
Returns all running services implementation of the passed service
interface
|
Module |
makeModuleFor(String packageName)
Find and return a loaded Module that has the package name in its list
of exported interfaces.
|
Module |
makeModuleFor(String name,
String version)
Returns the
Module instance giving a name and version
constraints. |
Module |
makeModuleFor(String name,
String version,
boolean resolve)
Returns the
Module instance giving a name and version
constraints. |
ServiceLocator |
newServiceLocator()
Creates an uninitialized
ServiceLocator |
ServiceLocator |
newServiceLocator(ServiceLocator parent) |
void |
populateConfig(ServiceLocator serviceLocator) |
void |
populateServiceLocator(String name,
ServiceLocator h,
List<PopulatorPostProcessor> postProcessors)
Populates a
ServiceLocator from all the modules in this registry. |
void |
print(Logger logger)
Print a Registry dump to the logger
|
void |
register(ModuleLifecycleListener listener)
Add a
ModuleLifecycleListener to this registry. |
<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.
|
void |
removeRepository(String name)
Remove a repository from the list of attached repositories to
this instances.
|
void |
setParentClassLoader(ClassLoader parent) |
void |
shutdown()
Shuts down this module's registry, apply housekeeping tasks
|
void |
unregister(ModuleLifecycleListener listener)
Removes an
ModuleLifecycleListener from this registry. |
<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.
|
changed
ModulesRegistry createChild()
ModulesRegistry
in this ModulesRegistry
.ServiceLocator newServiceLocator() throws MultiException
ServiceLocator
MultiException
ServiceLocator createServiceLocator() throws MultiException
ServiceLocator
from all the modules in this registry
Calling this method has the same effect of calling #createServiceLocator("default")
name
- Determines which inhabitants descriptors are loaded.
(so that different parallel habitats can be
created over the same modules registry.)MultiException
ServiceLocator createServiceLocator(String name) throws MultiException
ServiceLocator
from all the modules in this registry
Cal;ling this method has the same effect of calling newServiceLocator()
followed by
#populateServiceLocator(String, org.glassfish.hk2.api.ServiceLocator, java.util.List
.name
- Determines which inhabitants descriptors are loaded.
(so that different parallel habitats can be
created over the same modules registry.)MultiException
ServiceLocator createServiceLocator(ServiceLocator serviceLocator, String name, List<PopulatorPostProcessor> postProcessors)
ServiceLocator
with the provided parent.serviceLocator
- name
- postProcessors
- void populateServiceLocator(String name, ServiceLocator h, List<PopulatorPostProcessor> postProcessors) throws MultiException
ServiceLocator
from all the modules in this registry.
Default InhabitantsParser
is used.
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 createdpostProcessors
- MultiException
void addRepository(Repository repository, int weight)
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).repository
- new repository to attach to this registryweight
- int value from 1 to 100 to specify the search ordervoid addRepository(Repository repository)
Repository
to this registry. From now on
the repository will be used to procure requested nodule not
registered in this instance.repository
- new repository to attach to this registryvoid removeRepository(String name)
Repository
name will not be used to procure missing modules any
longername
- name of the repository to removeRepository getRepository(String name)
name
- name of the repository to returnModule makeModuleFor(String name, String version) throws ResolveError
Module
instance giving a name and version
constraints.name
- the module nameversion
- the module version. Caller should specify a correct version.ResolveError
- if the module dependencies cannot be resolvedModule makeModuleFor(String name, String version, boolean resolve) throws ResolveError
Module
instance giving a name and version
constraints.name
- the module nameversion
- the module version. Caller should specify a correct version.resolve
- should the module be resolved or notResolveError
- if the module dependencies cannot be resolvedModule makeModuleFor(String packageName) throws ResolveError
packageName
- the requested implementation package name.Module
instance implementing the package
name or null if not found.ResolveError
- if the module dependencies cannot be resolvedCollection<Module> getModules()
The returned list will not include the modules defined in the ancestor
ModulesRegistry
s.
Collection<Module> getModules(String moduleName)
The returned list will not include the modules defined in the ancestor
ModulesRegistry
s.
void detachAll()
Module add(ModuleDefinition info) throws ResolveError
Module
instances.ResolveError
Module add(ModuleDefinition info, boolean resolve) throws ResolveError
Module
instances.info
- ModuleDefinition representing the new module contentresolve
- should the new module be resolved or notResolveError
void print(Logger logger)
logger
- the logger to dump onvoid register(ModuleLifecycleListener listener)
ModuleLifecycleListener
to this registry. The listener
will be notified for each module startup and shutdown.listener
- the listener implementationvoid unregister(ModuleLifecycleListener listener)
ModuleLifecycleListener
from this registry.
Notification of module startup and shutdown will not be emitted to this
listener any longer.listener
- the listener to unregistervoid shutdown()
void dumpState(PrintStream writer)
Iterable<Module> getModulesProvider(Class serviceClass)
serviceClass
- the service interface class<T> void registerRunningService(Class<T> serviceClass, T provider)
serviceClass
- the service interfaceprovider
- the provider of that service.<T> boolean unregisterRunningService(Class<T> serviceClass, T provider)
<T> List<T> getRunningServices(Class<T> serviceClass)
serviceClass
- the service interfacevoid setParentClassLoader(ClassLoader parent)
ClassLoader getParentClassLoader()
ClassLoader getModulesClassLoader(ClassLoader parent, Collection<ModuleDefinition> defs) throws ResolveError
parent
- the parent class loader for the returned class loader instancedefs
- module definitions for all modules this classloader should be
capable of loading classes fromResolveError
- if one of the provided module
definition cannot be resolvedClassLoader getModulesClassLoader(ClassLoader parent, Collection<ModuleDefinition> defs, URL[] urls) throws ResolveError
parent
- the parent class loader for the returned class loader instancedefs
- module definitions for all modules this classloader should be
capable of loadingurls
- urls to be added to the module classloaderResolveError
- if one of the provided module
definition cannot be resolvedModule find(Class clazz)
Module
that owns the given class.Module getProvidingModule(String providerClassName)
Module
that provides the provider of the given name.ServiceLocator newServiceLocator(ServiceLocator parent) throws MultiException
MultiException
void populateConfig(ServiceLocator serviceLocator) throws MultiException
MultiException
Copyright © 2009–2023 Oracle Corporation. All rights reserved.