Class AbstractModulesRegistryImpl
- java.lang.Object
-
- com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl
-
- All Implemented Interfaces:
ModuleChangeListener,ModulesRegistry
- Direct Known Subclasses:
ModulesRegistryImpl
public abstract class AbstractModulesRegistryImpl extends java.lang.Object implements ModulesRegistry
The Modules Registry maintains the registry of all available module. TODO: concurrency bug in the acess of the repositories field.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<ServiceLocator,java.lang.String>habitats(package private) java.util.Map<Module,java.util.Map<ServiceLocator,java.util.List<ActiveDescriptor>>>moduleDescriptorsprotected java.util.concurrent.ConcurrentMap<ModuleId,Module>modulesprotected ModulesRegistryparentModulesRegistrycan form a tree structure by using this pointer.protected java.util.Map<java.lang.String,Module>providersService provider class names and which modules they are in.protected java.util.Map<java.lang.Integer,Repository>repositoriesprivate java.util.concurrent.ConcurrentMap<java.lang.Class<?>,java.util.concurrent.CopyOnWriteArrayList<?>>runningServices
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractModulesRegistryImpl(ModulesRegistry parent)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidadd(Module newModule)Add a new module to this registry.Moduleadd(ModuleDefinition info)Registers a new DefaultModuleDefinition in this registry.Moduleadd(ModuleDefinition info, boolean resolve)Registers a new DefaultModuleDefinition in this registry.voidaddRepository(Repository repository)Add a newRepositoryto this registry.voidaddRepository(Repository repository, int weight)Add a newRepositoryto this registry.voidchanged(Module service)Modules can notify their registry that they have changed (classes, resources,etc...).ServiceLocatorcreateServiceLocator()Creates the defaultServiceLocatorfrom all the modules in this registry Calling this method has the same effect of calling {@link #createServiceLocator("default")}ServiceLocatorcreateServiceLocator(java.lang.String name)Creates aServiceLocatorfrom all the modules in this registry Cal;ling this method has the same effect of callingModulesRegistry.newServiceLocator()followed by {@link #populateServiceLocator(String, org.glassfish.hk2.api.ServiceLocator, java.util.List}.ServiceLocatorcreateServiceLocator(ServiceLocator parent, java.lang.String name, java.util.List<PopulatorPostProcessor> postProcessors)Creates aServiceLocatorwith the provided parent.voiddumpState(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 namejava.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)ModulegetProvidingModule(java.lang.String providerClassName)Gets theModulethat provides the provider of the given name.RepositorygetRepository(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 interfaceprotected voidinitializeServiceLocator(ServiceLocator serviceLocator)protected ModuleloadFromRepository(java.lang.String name, java.lang.String version)ModulemakeModuleFor(java.lang.String packageName)Find and return a loaded Module that has the package name in its list of exported interfaces.ModulemakeModuleFor(java.lang.String name, java.lang.String version)Returns theModuleinstance giving a name and version constraints.ModulemakeModuleFor(java.lang.String name, java.lang.String version, boolean resolve)Returns theModuleinstance giving a name and version constraints.protected abstract ModulenewModule(ModuleDefinition moduleDef)Factory method for creating new instances of Module.ServiceLocatornewServiceLocator()Creates an uninitializedServiceLocatorServiceLocatornewServiceLocator(ServiceLocator parent)Create a new ServiceLocator optionally providing a parent Servicesprotected abstract java.util.List<ActiveDescriptor>parseInhabitants(Module module, java.lang.String name, ServiceLocator serviceLocator, java.util.List<PopulatorPostProcessor> postProcessors)voidpopulateConfig(ServiceLocator serviceLocator)voidpopulateServiceLocator(java.lang.String name, ServiceLocator serviceLocator, java.util.List<PopulatorPostProcessor> postProcessors)Creates aServiceLocatorfrom all the modules in this registryvoidprint(java.util.logging.Logger logger)Print a Registry dump to the logger<T> voidregisterRunningService(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.voidremove(Module module)Removes a module from the registry.voidremoveRepository(java.lang.String name)Remove a repository from the list of attached repositories to this instances.private voidremoveShutdownLocators()<T> booleanunregisterRunningService(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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.sun.enterprise.module.ModulesRegistry
createChild, detachAll, find, getModulesClassLoader, getModulesClassLoader, getParentClassLoader, register, setParentClassLoader, shutdown, unregister
-
-
-
-
Field Detail
-
parent
protected final ModulesRegistry parent
ModulesRegistrycan 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.
-
repositories
protected final java.util.Map<java.lang.Integer,Repository> repositories
-
runningServices
private final java.util.concurrent.ConcurrentMap<java.lang.Class<?>,java.util.concurrent.CopyOnWriteArrayList<?>> runningServices
-
providers
protected final java.util.Map<java.lang.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.
-
habitats
private java.util.Map<ServiceLocator,java.lang.String> habitats
-
moduleDescriptors
java.util.Map<Module,java.util.Map<ServiceLocator,java.util.List<ActiveDescriptor>>> moduleDescriptors
-
-
Constructor Detail
-
AbstractModulesRegistryImpl
protected AbstractModulesRegistryImpl(ModulesRegistry parent)
-
-
Method Detail
-
newServiceLocator
public ServiceLocator newServiceLocator() throws MultiException
Creates an uninitializedServiceLocator- Specified by:
newServiceLocatorin interfaceModulesRegistry- Throws:
MultiException
-
newServiceLocator
public ServiceLocator newServiceLocator(ServiceLocator parent) throws MultiException
Create a new ServiceLocator optionally providing a parent Services- Specified by:
newServiceLocatorin interfaceModulesRegistry- Throws:
MultiException
-
initializeServiceLocator
protected void initializeServiceLocator(ServiceLocator serviceLocator) throws MultiException
- Throws:
MultiException
-
populateServiceLocator
public void populateServiceLocator(java.lang.String name, ServiceLocator serviceLocator, java.util.List<PopulatorPostProcessor> postProcessors) throws MultiExceptionCreates aServiceLocatorfrom all the modules in this registry- Specified by:
populateServiceLocatorin interfaceModulesRegistry- Parameters:
name- Determines which descriptors are loaded.postProcessors-serviceLocator- Habitat to initialize, null if it should be created- Throws:
MultiException
-
populateConfig
public void populateConfig(ServiceLocator serviceLocator)
- Specified by:
populateConfigin interfaceModulesRegistry
-
createServiceLocator
public ServiceLocator createServiceLocator(ServiceLocator parent, java.lang.String name, java.util.List<PopulatorPostProcessor> postProcessors) throws MultiException
Description copied from interface:ModulesRegistryCreates aServiceLocatorwith the provided parent.- Specified by:
createServiceLocatorin interfaceModulesRegistry- Returns:
- Throws:
MultiException
-
createServiceLocator
public ServiceLocator createServiceLocator(java.lang.String name) throws MultiException
Description copied from interface:ModulesRegistryCreates aServiceLocatorfrom all the modules in this registry Cal;ling this method has the same effect of callingModulesRegistry.newServiceLocator()followed by {@link #populateServiceLocator(String, org.glassfish.hk2.api.ServiceLocator, java.util.List}.- Specified by:
createServiceLocatorin interfaceModulesRegistry- Parameters:
name- Determines which inhabitants descriptors are loaded. (so that different parallel habitats can be created over the same modules registry.)- Throws:
MultiException
-
createServiceLocator
public ServiceLocator createServiceLocator() throws MultiException
Description copied from interface:ModulesRegistryCreates the defaultServiceLocatorfrom all the modules in this registry Calling this method has the same effect of calling {@link #createServiceLocator("default")}- Specified by:
createServiceLocatorin interfaceModulesRegistry- Throws:
MultiException
-
parseInhabitants
protected abstract java.util.List<ActiveDescriptor> parseInhabitants(Module module, java.lang.String name, ServiceLocator serviceLocator, java.util.List<PopulatorPostProcessor> postProcessors) throws java.io.IOException, BootException
- Throws:
java.io.IOExceptionBootException
-
addRepository
public void addRepository(Repository repository, int weight)
Add a newRepositoryto 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:
addRepositoryin interfaceModulesRegistry- Parameters:
repository- new repository to attach to this registryweight- int value from 1 to 100 to specify the search order
-
addRepository
public void addRepository(Repository repository)
Add a newRepositoryto this registry. From now on the repository will be used to procure requested nodule not registered in this instance.- Specified by:
addRepositoryin interfaceModulesRegistry- Parameters:
repository- new repository to attach to this registry
-
removeRepository
public void removeRepository(java.lang.String name)
Remove a repository from the list of attached repositories to this instances. After this call, theRepositoryname will not be used to procure missing modules any longer- Specified by:
removeRepositoryin interfaceModulesRegistry- Parameters:
name- name of the repository to remove
-
getRepository
public Repository getRepository(java.lang.String name)
Get a repository from the list of attached repositories- Specified by:
getRepositoryin interfaceModulesRegistry- Parameters:
name- name of the repository to return- Returns:
- the repository or null if not found
-
makeModuleFor
public Module makeModuleFor(java.lang.String name, java.lang.String version) throws ResolveError
Returns theModuleinstance giving a name and version constraints.- Specified by:
makeModuleForin interfaceModulesRegistry- Parameters:
name- the module nameversion- 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(java.lang.String name, java.lang.String version, boolean resolve) throws ResolveError
Description copied from interface:ModulesRegistryReturns theModuleinstance giving a name and version constraints.- Specified by:
makeModuleForin interfaceModulesRegistry- Parameters:
name- the module nameversion- 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(java.lang.String packageName) throws ResolveError
Find and return a loaded Module that has the package name in its list of exported interfaces.- Specified by:
makeModuleForin interfaceModulesRegistry- Parameters:
packageName- the requested implementation package name.- Returns:
- the
Moduleinstance implementing the package name or null if not found. - Throws:
ResolveError- if the module dependencies cannot be resolved
-
loadFromRepository
protected Module loadFromRepository(java.lang.String name, java.lang.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
-
removeShutdownLocators
private void removeShutdownLocators()
-
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.
-
getAllServiceLocators
protected java.util.Set<ServiceLocator> getAllServiceLocators()
-
getModules
public java.util.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
AbstractModulesRegistryImpls.- Specified by:
getModulesin interfaceModulesRegistry- Returns:
- an umodifiable list of loaded modules
-
getModules
public java.util.Collection<Module> getModules(java.lang.String moduleName)
Description copied from interface:ModulesRegistryReturns the list of shared Modules registered in this instance whose name matches the given nameThe returned list will not include the modules defined in the ancestor
ModulesRegistrys.- Specified by:
getModulesin interfaceModulesRegistry- 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:
changedin interfaceModuleChangeListener
-
add
public Module add(ModuleDefinition info) throws ResolveError
Registers a new DefaultModuleDefinition in this registry. Using this module definition, the registry will be capable of created shared and privateModuleinstances.- Specified by:
addin interfaceModulesRegistry- Throws:
ResolveError
-
add
public Module add(ModuleDefinition info, boolean resolve) throws ResolveError
Description copied from interface:ModulesRegistryRegisters a new DefaultModuleDefinition in this registry. Using this module definition, the registry will be capable of created shared and privateModuleinstances.- Specified by:
addin interfaceModulesRegistry- Parameters:
info- ModuleDefinition representing the new module contentresolve- should the new module be resolved or not- Throws:
ResolveError
-
print
public void print(java.util.logging.Logger logger)
Print a Registry dump to the logger- Specified by:
printin interfaceModulesRegistry- Parameters:
logger- the logger to dump on
-
getProvidersClass
public <T> java.lang.Iterable<java.lang.Class<? extends T>> getProvidersClass(java.lang.Class<T> serviceClass)
- Specified by:
getProvidersClassin interfaceModulesRegistry
-
getModulesProvider
public 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.- Specified by:
getModulesProviderin interfaceModulesRegistry- Parameters:
serviceClass- the service interface class- Returns:
- a collection of module
-
registerRunningService
public <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.- Specified by:
registerRunningServicein interfaceModulesRegistry- Parameters:
serviceClass- the service interfaceprovider- the provider of that service.
-
unregisterRunningService
public <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.- Specified by:
unregisterRunningServicein interfaceModulesRegistry
-
getRunningServices
public <T> java.util.List<T> getRunningServices(java.lang.Class<T> serviceClass)
Returns all running services implementation of the passed service interface- Specified by:
getRunningServicesin interfaceModulesRegistry- Parameters:
serviceClass- the service interface- Returns:
- the list of providers of that service.
-
getProvidingModule
public Module getProvidingModule(java.lang.String providerClassName)
Description copied from interface:ModulesRegistryGets theModulethat provides the provider of the given name.- Specified by:
getProvidingModulein interfaceModulesRegistry
-
dumpState
public void dumpState(java.io.PrintStream writer)
- Specified by:
dumpStatein interfaceModulesRegistry
-
-