public abstract class AbstractModulesRegistryImpl extends java.lang.Object implements ModulesRegistry
| Modifier and Type | Field and Description |
|---|---|
protected java.util.concurrent.ConcurrentMap<ModuleId,Module> |
modules |
protected ModulesRegistry |
parent
ModulesRegistry can form a tree structure by using this pointer. |
protected java.util.Map<java.lang.String,Module> |
providers
Service provider class names and which modules they are in.
|
protected java.util.Map<java.lang.Integer,Repository> |
repositories |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractModulesRegistryImpl(ModulesRegistry parent) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
add(Module newModule)
Add a new module to this registry.
|
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. |
void |
changed(Module service)
Modules can notify their registry that they have changed (classes,
resources,etc...).
|
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 parent,
java.lang.String name,
java.util.List<PopulatorPostProcessor> postProcessors)
Creates a
ServiceLocator with the provided parent. |
ServiceLocator |
createServiceLocator(java.lang.String name)
Creates a
ServiceLocator from all the modules in this registry
Cal;ling this method has the same effect of calling ModulesRegistry.newServiceLocator() followed by
#populateServiceLocator(String, org.glassfish.hk2.api.ServiceLocator, java.util.List. |
void |
dumpState(java.io.PrintStream writer) |
protected java.util.Set<ServiceLocator> |
getAllServiceLocators() |
java.util.Collection<Module> |
getModules()
Returns the list of shared Modules registered in this instance.
|
java.util.Collection<Module> |
getModules(java.lang.String moduleName)
Returns the list of shared Modules registered in this instance whose name
matches the given name
|
java.lang.Iterable<Module> |
getModulesProvider(java.lang.Class serviceClass)
Returns a collection of Module containing at least one implementation
of the passed service interface class.
|
<T> java.lang.Iterable<java.lang.Class<? extends T>> |
getProvidersClass(java.lang.Class<T> serviceClass) |
Module |
getProvidingModule(java.lang.String providerClassName)
Gets the
Module that provides the provider of the given name. |
Repository |
getRepository(java.lang.String name)
Get a repository from the list of attached repositories
|
<T> java.util.List<T> |
getRunningServices(java.lang.Class<T> serviceClass)
Returns all running services implementation of the passed service
interface
|
protected void |
initializeServiceLocator(ServiceLocator serviceLocator) |
protected Module |
loadFromRepository(java.lang.String name,
java.lang.String version) |
Module |
makeModuleFor(java.lang.String packageName)
Find and return a loaded Module that has the package name in its list
of exported interfaces.
|
Module |
makeModuleFor(java.lang.String name,
java.lang.String version)
Returns the
Module instance giving a name and version
constraints. |
Module |
makeModuleFor(java.lang.String name,
java.lang.String version,
boolean resolve)
Returns the
Module instance giving a name and version
constraints. |
protected abstract Module |
newModule(ModuleDefinition moduleDef)
Factory method for creating new instances of Module.
|
ServiceLocator |
newServiceLocator()
Creates an uninitialized
ServiceLocator |
ServiceLocator |
newServiceLocator(ServiceLocator parent)
Create a new ServiceLocator optionally providing a parent Services
|
protected abstract java.util.List<ActiveDescriptor> |
parseInhabitants(Module module,
java.lang.String name,
ServiceLocator serviceLocator,
java.util.List<PopulatorPostProcessor> postProcessors) |
void |
populateConfig(ServiceLocator serviceLocator) |
void |
populateServiceLocator(java.lang.String name,
ServiceLocator serviceLocator,
java.util.List<PopulatorPostProcessor> postProcessors)
Creates a
ServiceLocator from all the modules in this registry |
void |
print(java.util.logging.Logger logger)
Print a Registry dump to the logger
|
<T> void |
registerRunningService(java.lang.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 |
remove(Module module)
Removes a module from the registry.
|
void |
removeRepository(java.lang.String name)
Remove a repository from the list of attached repositories to
this instances.
|
<T> boolean |
unregisterRunningService(java.lang.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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreateChild, detachAll, find, getModulesClassLoader, getModulesClassLoader, getParentClassLoader, register, setParentClassLoader, shutdown, unregisterprotected 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.protected final java.util.Map<java.lang.Integer,Repository> repositories
protected final java.util.Map<java.lang.String,Module> providers
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.
protected AbstractModulesRegistryImpl(ModulesRegistry parent)
public ServiceLocator newServiceLocator() throws MultiException
ServiceLocatornewServiceLocator in interface ModulesRegistryMultiExceptionpublic ServiceLocator newServiceLocator(ServiceLocator parent) throws MultiException
newServiceLocator in interface ModulesRegistryMultiExceptionprotected void initializeServiceLocator(ServiceLocator serviceLocator) throws MultiException
MultiExceptionpublic void populateServiceLocator(java.lang.String name,
ServiceLocator serviceLocator,
java.util.List<PopulatorPostProcessor> postProcessors)
throws MultiException
ServiceLocator from all the modules in this registrypopulateServiceLocator in interface ModulesRegistryname - Determines which descriptors are loaded.postProcessors - serviceLocator - Habitat to initialize, null if it should be createdMultiExceptionpublic void populateConfig(ServiceLocator serviceLocator)
populateConfig in interface ModulesRegistrypublic ServiceLocator createServiceLocator(ServiceLocator parent, java.lang.String name, java.util.List<PopulatorPostProcessor> postProcessors) throws MultiException
ModulesRegistryServiceLocator with the provided parent.createServiceLocator in interface ModulesRegistryMultiExceptionpublic ServiceLocator createServiceLocator(java.lang.String name) throws MultiException
ModulesRegistryServiceLocator from all the modules in this registry
Cal;ling this method has the same effect of calling ModulesRegistry.newServiceLocator() followed by
#populateServiceLocator(String, org.glassfish.hk2.api.ServiceLocator, java.util.List.createServiceLocator in interface ModulesRegistryname - Determines which inhabitants descriptors are loaded.
(so that different parallel habitats can be
created over the same modules registry.)MultiExceptionpublic ServiceLocator createServiceLocator() throws MultiException
ModulesRegistryServiceLocator from all the modules in this registry
Calling this method has the same effect of calling #createServiceLocator("default")createServiceLocator in interface ModulesRegistryMultiExceptionprotected abstract java.util.List<ActiveDescriptor> parseInhabitants(Module module, java.lang.String name, ServiceLocator serviceLocator, java.util.List<PopulatorPostProcessor> postProcessors) throws java.io.IOException, BootException
java.io.IOExceptionBootExceptionpublic 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).addRepository in interface ModulesRegistryrepository - new repository to attach to this registryweight - int value from 1 to 100 to specify the search orderpublic void addRepository(Repository repository)
Repository to this registry. From now on
the repository will be used to procure requested nodule not
registered in this instance.addRepository in interface ModulesRegistryrepository - new repository to attach to this registrypublic void removeRepository(java.lang.String name)
Repository
name will not be used to procure missing modules any
longerremoveRepository in interface ModulesRegistryname - name of the repository to removepublic Repository getRepository(java.lang.String name)
getRepository in interface ModulesRegistryname - name of the repository to returnpublic Module makeModuleFor(java.lang.String name, java.lang.String version) throws ResolveError
Module instance giving a name and version
constraints.makeModuleFor in interface ModulesRegistryname - the module nameversion - the module version.ResolveError - if the module dependencies cannot be resolvedpublic Module makeModuleFor(java.lang.String name, java.lang.String version, boolean resolve) throws ResolveError
ModulesRegistryModule instance giving a name and version
constraints.makeModuleFor in interface ModulesRegistryname - 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 resolvedpublic Module makeModuleFor(java.lang.String packageName) throws ResolveError
makeModuleFor in interface ModulesRegistrypackageName - the requested implementation package name.Module instance implementing the package
name or null if not found.ResolveError - if the module dependencies cannot be resolvedprotected Module loadFromRepository(java.lang.String name, java.lang.String version)
protected abstract Module newModule(ModuleDefinition moduleDef)
moduleDef - module definition of the new module to be createdprotected void add(Module newModule)
newModule - the new modulepublic void remove(Module module)
protected java.util.Set<ServiceLocator> getAllServiceLocators()
public java.util.Collection<Module> getModules()
The returned list will not include the modules defined in the ancestor
AbstractModulesRegistryImpls.
getModules in interface ModulesRegistrypublic java.util.Collection<Module> getModules(java.lang.String moduleName)
ModulesRegistry
The returned list will not include the modules defined in the ancestor
ModulesRegistrys.
getModules in interface ModulesRegistrypublic void changed(Module service)
changed in interface ModuleChangeListenerpublic Module add(ModuleDefinition info) throws ResolveError
Module instances.add in interface ModulesRegistryResolveErrorpublic Module add(ModuleDefinition info, boolean resolve) throws ResolveError
ModulesRegistryModule instances.add in interface ModulesRegistryinfo - ModuleDefinition representing the new module contentresolve - should the new module be resolved or notResolveErrorpublic void print(java.util.logging.Logger logger)
print in interface ModulesRegistrylogger - the logger to dump onpublic <T> java.lang.Iterable<java.lang.Class<? extends T>> getProvidersClass(java.lang.Class<T> serviceClass)
getProvidersClass in interface ModulesRegistrypublic java.lang.Iterable<Module> getModulesProvider(java.lang.Class serviceClass)
getModulesProvider in interface ModulesRegistryserviceClass - the service interface classpublic <T> void registerRunningService(java.lang.Class<T> serviceClass,
T provider)
registerRunningService in interface ModulesRegistryserviceClass - the service interfaceprovider - the provider of that service.public <T> boolean unregisterRunningService(java.lang.Class<T> serviceClass,
T provider)
unregisterRunningService in interface ModulesRegistrypublic <T> java.util.List<T> getRunningServices(java.lang.Class<T> serviceClass)
getRunningServices in interface ModulesRegistryserviceClass - the service interfacepublic Module getProvidingModule(java.lang.String providerClassName)
ModulesRegistryModule that provides the provider of the given name.getProvidingModule in interface ModulesRegistrypublic void dumpState(java.io.PrintStream writer)
dumpState in interface ModulesRegistryCopyright © 2013 Oracle Corporation. All Rights Reserved.