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 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 Summary
Fields Modifier and Type Field Description protected ConcurrentMap<ModuleId,Module>
modules
protected ModulesRegistry
parent
ModulesRegistry
can form a tree structure by using this pointer.protected Map<String,Module>
providers
Service provider class names and which modules they are in.protected Map<Integer,Repository>
repositories
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractModulesRegistryImpl(ModulesRegistry parent)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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 newRepository
to this registry.void
addRepository(Repository repository, int weight)
Add a newRepository
to this registry.void
changed(Module service)
Modules can notify their registry that they have changed (classes, resources,etc...).ServiceLocator
createServiceLocator()
Creates the defaultServiceLocator
from all the modules in this registry Calling this method has the same effect of calling {@link #createServiceLocator("default")}ServiceLocator
createServiceLocator(String name)
Creates aServiceLocator
from 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}.ServiceLocator
createServiceLocator(ServiceLocator parent, String name, List<PopulatorPostProcessor> postProcessors)
Creates aServiceLocator
with the provided parent.void
dumpState(PrintStream writer)
protected Set<ServiceLocator>
getAllServiceLocators()
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 nameIterable<Module>
getModulesProvider(Class serviceClass)
Returns a collection of Module containing at least one implementation of the passed service interface class.<T> Iterable<Class<? extends T>>
getProvidersClass(Class<T> serviceClass)
Module
getProvidingModule(String providerClassName)
Gets theModule
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 interfaceprotected void
initializeServiceLocator(ServiceLocator serviceLocator)
protected Module
loadFromRepository(String name, String version)
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 theModule
instance giving a name and version constraints.Module
makeModuleFor(String name, String version, boolean resolve)
Returns theModule
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 uninitializedServiceLocator
ServiceLocator
newServiceLocator(ServiceLocator parent)
Create a new ServiceLocator optionally providing a parent Servicesprotected abstract List<ActiveDescriptor>
parseInhabitants(Module module, String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors)
void
populateConfig(ServiceLocator serviceLocator)
void
populateServiceLocator(String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors)
Creates aServiceLocator
from all the modules in this registryvoid
print(Logger logger)
Print a Registry dump to the logger<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
remove(Module module)
Removes a module from the registry.void
removeRepository(String name)
Remove a repository from the list of attached repositories to this instances.<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.-
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
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.
-
modules
protected final ConcurrentMap<ModuleId,Module> modules
-
repositories
protected final Map<Integer,Repository> repositories
-
-
Constructor Detail
-
AbstractModulesRegistryImpl
protected AbstractModulesRegistryImpl(ModulesRegistry parent)
-
-
Method Detail
-
newServiceLocator
public ServiceLocator newServiceLocator() throws MultiException
Creates an uninitializedServiceLocator
- Specified by:
newServiceLocator
in interfaceModulesRegistry
- Throws:
MultiException
-
newServiceLocator
public ServiceLocator newServiceLocator(ServiceLocator parent) throws MultiException
Create a new ServiceLocator optionally providing a parent Services- Specified by:
newServiceLocator
in interfaceModulesRegistry
- Throws:
MultiException
-
initializeServiceLocator
protected void initializeServiceLocator(ServiceLocator serviceLocator) throws MultiException
- Throws:
MultiException
-
populateServiceLocator
public void populateServiceLocator(String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors) throws MultiException
Creates aServiceLocator
from all the modules in this registry- Specified by:
populateServiceLocator
in 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:
populateConfig
in interfaceModulesRegistry
-
createServiceLocator
public ServiceLocator createServiceLocator(ServiceLocator parent, String name, List<PopulatorPostProcessor> postProcessors) throws MultiException
Description copied from interface:ModulesRegistry
Creates aServiceLocator
with the provided parent.- Specified by:
createServiceLocator
in interfaceModulesRegistry
- Returns:
- Throws:
MultiException
-
createServiceLocator
public ServiceLocator createServiceLocator(String name) throws MultiException
Description copied from interface:ModulesRegistry
Creates aServiceLocator
from 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:
createServiceLocator
in 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:ModulesRegistry
Creates the defaultServiceLocator
from all the modules in this registry Calling this method has the same effect of calling {@link #createServiceLocator("default")}- Specified by:
createServiceLocator
in interfaceModulesRegistry
- Throws:
MultiException
-
parseInhabitants
protected abstract List<ActiveDescriptor> parseInhabitants(Module module, String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors) throws IOException, BootException
- Throws:
IOException
BootException
-
addRepository
public void addRepository(Repository repository, int weight)
Add a newRepository
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 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 newRepository
to this registry. From now on the repository will be used to procure requested nodule not registered in this instance.- Specified by:
addRepository
in interfaceModulesRegistry
- 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, theRepository
name will not be used to procure missing modules any longer- Specified by:
removeRepository
in interfaceModulesRegistry
- 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 interfaceModulesRegistry
- 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 theModule
instance giving a name and version constraints.- Specified by:
makeModuleFor
in 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(String name, String version, boolean resolve) throws ResolveError
Description copied from interface:ModulesRegistry
Returns theModule
instance giving a name and version constraints.- Specified by:
makeModuleFor
in 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(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 interfaceModulesRegistry
- 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
-
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.
-
getAllServiceLocators
protected Set<ServiceLocator> getAllServiceLocators()
-
getModules
public 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
AbstractModulesRegistryImpl
s.- Specified by:
getModules
in interfaceModulesRegistry
- Returns:
- an umodifiable list of loaded modules
-
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 nameThe returned list will not include the modules defined in the ancestor
ModulesRegistry
s.- Specified by:
getModules
in 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:
changed
in 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 privateModule
instances.- Specified by:
add
in interfaceModulesRegistry
- Throws:
ResolveError
-
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 privateModule
instances.- Specified by:
add
in interfaceModulesRegistry
- Parameters:
info
- ModuleDefinition representing the new module contentresolve
- 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 interfaceModulesRegistry
- Parameters:
logger
- the logger to dump on
-
getProvidersClass
public <T> Iterable<Class<? extends T>> getProvidersClass(Class<T> serviceClass)
- Specified by:
getProvidersClass
in interfaceModulesRegistry
-
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 interfaceModulesRegistry
- 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 interfaceModulesRegistry
- Parameters:
serviceClass
- the service interfaceprovider
- 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 interfaceModulesRegistry
-
getRunningServices
public <T> List<T> getRunningServices(Class<T> serviceClass)
Returns all running services implementation of the passed service interface- Specified by:
getRunningServices
in interfaceModulesRegistry
- Parameters:
serviceClass
- the service interface- Returns:
- the list of providers of that service.
-
getProvidingModule
public Module getProvidingModule(String providerClassName)
Description copied from interface:ModulesRegistry
Gets theModule
that provides the provider of the given name.- Specified by:
getProvidingModule
in interfaceModulesRegistry
-
dumpState
public void dumpState(PrintStream writer)
- Specified by:
dumpState
in interfaceModulesRegistry
-
-