Top Description Fields Constructors Methods
com.sun.enterprise.module.common_impl

public abstract Class AbstractModulesRegistryImpl

extends Object
implements ModulesRegistry
Class Inheritance
All Implemented Interfaces
com.sun.enterprise.module.ModulesRegistry, com.sun.enterprise.module.ModuleChangeListener
Known Direct Subclasses
com.sun.enterprise.module.impl.ModulesRegistryImpl
Imports
com.sun.enterprise.module.HK2Module, .ModuleDefinition, .ModuleMetadata, .ModulesRegistry, .Repository, .ResolveError, com.sun.enterprise.module.bootstrap.BootException, java.io.IOException, .PrintStream, java.util.ArrayList, .Collection, .Collections, .HashMap, .HashSet, .Hashtable, .Iterator, .LinkedList, .List, .Map, .Map.Entry, .Set, .TreeMap, .TreeSet, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, .CopyOnWriteArrayList, java.util.concurrent.locks.ReentrantLock, java.util.logging.Logger, org.glassfish.hk2.api.ActiveDescriptor, .Descriptor, .DynamicConfiguration, .DynamicConfigurationService, .MultiException, .PopulatorPostProcessor, .ServiceLocator, .ServiceLocatorFactory, .ServiceLocatorState, org.glassfish.hk2.bootstrap.HK2Populator, org.glassfish.hk2.utilities.BuilderHelper, .DuplicatePostProcessor, .ServiceLocatorUtilities

The Modules Registry maintains the registry of all available module.

Todo

concurrency bug in the acess of the repositories field.

Authors
Jerome Dochez, [email protected]

Field Summary

Modifier and TypeField and Description
private Map<ServiceLocator, String>
private final ReentrantLock
pack-priv Map<HK2Module, Map<ServiceLocator, List<ActiveDescriptor<T>>>>
protected final ConcurrentMap<ModuleId, HK2Module>
protected final ModulesRegistry
parent

ModulesRegistry can form a tree structure by using this pointer.

protected final Map<String, HK2Module>
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.

protected final Map<Integer, Repository>
private final ConcurrentMap<Class<?>, CopyOnWriteArrayList<?>>

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected void
add(HK2Module
the new module
newModule
)

Add a new module to this registry.

public HK2Module
add(ModuleDefinition info)

Implements com.sun.enterprise.module.ModulesRegistry.add.

Registers a new DefaultModuleDefinition in this registry.

public HK2Module
add(ModuleDefinition info, boolean resolve)

Implements com.sun.enterprise.module.ModulesRegistry.add.

Registers a new DefaultModuleDefinition in this registry.

public void
addRepository(Repository
new repository to attach to this registry
repository
,
int
int value from 1 to 100 to specify the search order
weight
)

Implements com.sun.enterprise.module.ModulesRegistry.addRepository.

Add a new Repository to this registry.

public void
addRepository(Repository
new repository to attach to this registry
repository
)

Implements com.sun.enterprise.module.ModulesRegistry.addRepository.

Add a new Repository to this registry.

public void
changed(HK2Module service)

Implements com.sun.enterprise.module.ModuleChangeListener.changed.

Modules can notify their registry that they have changed (classes, resources,etc...).

public ServiceLocator
public ServiceLocator
createServiceLocator(String name)

Implements com.sun.enterprise.module.ModulesRegistry.createServiceLocator.

Creates a ServiceLocator from all the modules in this registry Cal;ling this method has the same effect of calling newServiceLocator() followed by org.glassfish.hk2.api.ServiceLocator, java.util.List.

public ServiceLocator
createServiceLocator()

Implements com.sun.enterprise.module.ModulesRegistry.createServiceLocator.

Creates the default ServiceLocator from all the modules in this registry Calling this method has the same effect of calling createServiceLocator("default")

public void
protected Set<ServiceLocator>
public Collection<HK2Module>

Returns:

an umodifiable list of loaded modules
getModules
()

Implements com.sun.enterprise.module.ModulesRegistry.getModules.

Returns the list of shared Modules registered in this instance.

public Collection<HK2Module>
getModules(String moduleName)

Implements com.sun.enterprise.module.ModulesRegistry.getModules.

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.

public Iterable<HK2Module>

Returns:

a collection of module
getModulesProvider
(final Class<T>
the service interface class
serviceClass
)

Implements com.sun.enterprise.module.ModulesRegistry.getModulesProvider.

Returns a collection of HK2Module containing at least one implementation of the passed service interface class.

public <T> Iterable<Class<? extends T>>
public HK2Module
getProvidingModule(String providerClassName)

Implements com.sun.enterprise.module.ModulesRegistry.getProvidingModule.

Gets the HK2Module that provides the provider of the given name.

public Repository

Returns:

the repository or null if not found
getRepository
(String
name of the repository to return
name
)

Implements com.sun.enterprise.module.ModulesRegistry.getRepository.

Get a repository from the list of attached repositories

public <T> List<T>

Returns:

the list of providers of that service.
getRunningServices
(Class<T>
the service interface
serviceClass
)

Implements com.sun.enterprise.module.ModulesRegistry.getRunningServices.

Returns all running services implementation of the passed service interface

private <T> T
getServiceOrFail(ServiceLocator serviceLocator, Class<T> contractOrImpl)

protected void
protected HK2Module
public HK2Module

Returns:

the module instance or null if none can be found
makeModuleFor
(String
the module name
name
,
String
the module version.
version
)

Implements com.sun.enterprise.module.ModulesRegistry.makeModuleFor.

Returns the HK2Module instance giving a name and version constraints.

public HK2Module
makeModuleFor(String name, String version, boolean resolve)

Implements com.sun.enterprise.module.ModulesRegistry.makeModuleFor.

Returns the HK2Module instance giving a name and version constraints.

public HK2Module

Returns:

the HK2Module instance implementing the package name or null if not found.
makeModuleFor
(String
the requested implementation package name.
packageName
)

Implements com.sun.enterprise.module.ModulesRegistry.makeModuleFor.

Find and return a loaded HK2Module that has the package name in its list of exported interfaces.

protected abstract HK2Module

Returns:

a new HK2Module instance
newModule
(ModuleDefinition
module definition of the new module to be created
moduleDef
)

Factory method for creating new instances of HK2Module.

public ServiceLocator
public ServiceLocator
newServiceLocator(ServiceLocator parent)

Implements com.sun.enterprise.module.ModulesRegistry.newServiceLocator.

Create a new ServiceLocator optionally providing a parent Services

protected abstract List<ActiveDescriptor<T>>
parseInhabitants(HK2Module module, String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors)

public void
public void
populateServiceLocator(String
Determines which descriptors are loaded.
name
,
ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors)

Implements com.sun.enterprise.module.ModulesRegistry.populateServiceLocator.

Creates a ServiceLocator from all the modules in this registry

public <T> void
registerRunningService(Class<T>
the service interface
serviceClass
,
T
the provider of that service.
provider
)

Implements com.sun.enterprise.module.ModulesRegistry.registerRunningService.

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.

public void
remove(HK2Module module)

Removes a module from the registry.

public void
removeRepository(String
name of the repository to remove
name
)

Implements com.sun.enterprise.module.ModulesRegistry.removeRepository.

Remove a repository from the list of attached repositories to this instances.

private void
public <T> boolean
unregisterRunningService(Class<T> serviceClass, T provider)

Implements com.sun.enterprise.module.ModulesRegistry.unregisterRunningService.

Removes a running service, this is useful when a service instance is no longer available as a provider of a service.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

habitatsback to summary
private Map<ServiceLocator, String> habitats
lockback to summary
private final ReentrantLock lock
moduleDescriptorsback to summary
pack-priv Map<HK2Module, Map<ServiceLocator, List<ActiveDescriptor<T>>>> moduleDescriptors
modulesback to summary
protected final ConcurrentMap<ModuleId, HK2Module> modules
parentback to summary
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.

providersback to summary
protected final Map<String, HK2Module> 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.

repositoriesback to summary
protected final Map<Integer, Repository> repositories
runningServicesback to summary
private final ConcurrentMap<Class<?>, CopyOnWriteArrayList<?>> runningServices

Constructor Detail

AbstractModulesRegistryImplback to summary
protected AbstractModulesRegistryImpl(ModulesRegistry parent)

Method Detail

addback to summary
protected void add(HK2Module newModule)

Add a new module to this registry. Once added, the module will be available through one of the getServiceImplementor methods.

Parameters
newModule:HK2Module

the new module

addback to summary
public HK2Module add(ModuleDefinition info) throws ResolveError

Implements com.sun.enterprise.module.ModulesRegistry.add.

Registers a new DefaultModuleDefinition in this registry. Using this module definition, the registry will be capable of created shared and private HK2Module instances.

addback to summary
public HK2Module add(ModuleDefinition info, boolean resolve) throws ResolveError

Implements com.sun.enterprise.module.ModulesRegistry.add.

Doc from com.sun.enterprise.module.ModulesRegistry.add.

Registers a new DefaultModuleDefinition in this registry. Using this module definition, the registry will be capable of created shared and private HK2Module instances.

addRepositoryback to summary
public void addRepository(Repository repository, int weight)

Implements com.sun.enterprise.module.ModulesRegistry.addRepository.

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:Repository

new repository to attach to this registry

weight:int

int value from 1 to 100 to specify the search order

addRepositoryback to summary
public void addRepository(Repository repository)

Implements com.sun.enterprise.module.ModulesRegistry.addRepository.

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:Repository

new repository to attach to this registry

changedback to summary
public void changed(HK2Module service)

Implements com.sun.enterprise.module.ModuleChangeListener.changed.

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.

createServiceLocatorback to summary
public ServiceLocator createServiceLocator(ServiceLocator parent, String name, List<PopulatorPostProcessor> postProcessors) throws MultiException

Implements com.sun.enterprise.module.ModulesRegistry.createServiceLocator.

Doc from com.sun.enterprise.module.ModulesRegistry.createServiceLocator.

Creates a ServiceLocator with the provided parent.

createServiceLocatorback to summary
public ServiceLocator createServiceLocator(String name) throws MultiException

Implements com.sun.enterprise.module.ModulesRegistry.createServiceLocator.

Doc from com.sun.enterprise.module.ModulesRegistry.createServiceLocator.

Creates a ServiceLocator from all the modules in this registry Cal;ling this method has the same effect of calling newServiceLocator() followed by org.glassfish.hk2.api.ServiceLocator, java.util.List.

createServiceLocatorback to summary
public ServiceLocator createServiceLocator() throws MultiException

Implements com.sun.enterprise.module.ModulesRegistry.createServiceLocator.

Doc from com.sun.enterprise.module.ModulesRegistry.createServiceLocator.

Creates the default ServiceLocator from all the modules in this registry Calling this method has the same effect of calling createServiceLocator("default")

dumpStateback to summary
public void dumpState(PrintStream writer)

Implements com.sun.enterprise.module.ModulesRegistry.dumpState.

getAllServiceLocatorsback to summary
protected Set<ServiceLocator> getAllServiceLocators()
getModulesback to summary
public Collection<HK2Module> getModules()

Implements com.sun.enterprise.module.ModulesRegistry.getModules.

Returns the list of shared Modules registered in this instance.

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

Returns:Collection<HK2Module>

an umodifiable list of loaded modules

getModulesback to summary
public Collection<HK2Module> getModules(String moduleName)

Implements com.sun.enterprise.module.ModulesRegistry.getModules.

Doc from com.sun.enterprise.module.ModulesRegistry.getModules.

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.

getModulesProviderback to summary
public Iterable<HK2Module> getModulesProvider(final Class<T> serviceClass)

Implements com.sun.enterprise.module.ModulesRegistry.getModulesProvider.

Returns a collection of HK2Module containing at least one implementation of the passed service interface class.

Parameters
serviceClass:Class<T>

the service interface class

Returns:Iterable<HK2Module>

a collection of module

getProvidersClassback to summary
public <T> Iterable<Class<? extends T>> getProvidersClass(final Class<T> serviceClass)

Implements com.sun.enterprise.module.ModulesRegistry.getProvidersClass.

getProvidingModuleback to summary
public HK2Module getProvidingModule(String providerClassName)

Implements com.sun.enterprise.module.ModulesRegistry.getProvidingModule.

Doc from com.sun.enterprise.module.ModulesRegistry.getProvidingModule.

Gets the HK2Module that provides the provider of the given name.

Annotations
@Override
getRepositoryback to summary
public Repository getRepository(String name)

Implements com.sun.enterprise.module.ModulesRegistry.getRepository.

Get a repository from the list of attached repositories

Parameters
name:String

name of the repository to return

Returns:Repository

the repository or null if not found

getRunningServicesback to summary
public <T> List<T> getRunningServices(Class<T> serviceClass)

Implements com.sun.enterprise.module.ModulesRegistry.getRunningServices.

Returns all running services implementation of the passed service interface

Parameters
serviceClass:Class<T>

the service interface

Returns:List<T>

the list of providers of that service.

getServiceOrFailback to summary
private <T> T getServiceOrFail(ServiceLocator serviceLocator, Class<T> contractOrImpl)
initializeServiceLocatorback to summary
protected void initializeServiceLocator(ServiceLocator serviceLocator) throws MultiException
loadFromRepositoryback to summary
protected HK2Module loadFromRepository(String name, String version)
makeModuleForback to summary
public HK2Module makeModuleFor(String name, String version) throws ResolveError

Implements com.sun.enterprise.module.ModulesRegistry.makeModuleFor.

Returns the HK2Module instance giving a name and version constraints.

Parameters
name:String

the module name

version:String

the module version.

Returns:HK2Module

the module instance or null if none can be found

Exceptions
ResolveError:
if the module dependencies cannot be resolved
makeModuleForback to summary
public HK2Module makeModuleFor(String name, String version, boolean resolve) throws ResolveError

Implements com.sun.enterprise.module.ModulesRegistry.makeModuleFor.

Doc from com.sun.enterprise.module.ModulesRegistry.makeModuleFor.

Returns the HK2Module instance giving a name and version constraints.

Exceptions
ResolveError:
if the module dependencies cannot be resolved
makeModuleForback to summary
public HK2Module makeModuleFor(String packageName) throws ResolveError

Implements com.sun.enterprise.module.ModulesRegistry.makeModuleFor.

Find and return a loaded HK2Module that has the package name in its list of exported interfaces.

Parameters
packageName:String

the requested implementation package name.

Returns:HK2Module

the HK2Module instance implementing the package name or null if not found.

Exceptions
ResolveError:
if the module dependencies cannot be resolved
newModuleback to summary
protected abstract HK2Module newModule(ModuleDefinition moduleDef)

Factory method for creating new instances of HK2Module.

Parameters
moduleDef:ModuleDefinition

module definition of the new module to be created

Returns:HK2Module

a new HK2Module instance

newServiceLocatorback to summary
public ServiceLocator newServiceLocator() throws MultiException

Implements com.sun.enterprise.module.ModulesRegistry.newServiceLocator.

Creates an uninitialized ServiceLocator

Annotations
@Override
newServiceLocatorback to summary
public ServiceLocator newServiceLocator(ServiceLocator parent) throws MultiException

Implements com.sun.enterprise.module.ModulesRegistry.newServiceLocator.

Create a new ServiceLocator optionally providing a parent Services

Annotations
@Override
parseInhabitantsback to summary
protected abstract List<ActiveDescriptor<T>> parseInhabitants(HK2Module module, String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors) throws IOException, BootException
populateConfigback to summary
public void populateConfig(ServiceLocator serviceLocator)

Implements com.sun.enterprise.module.ModulesRegistry.populateConfig.

Annotations
@Override
populateServiceLocatorback to summary
public void populateServiceLocator(String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors) throws MultiException

Implements com.sun.enterprise.module.ModulesRegistry.populateServiceLocator.

Creates a ServiceLocator from all the modules in this registry

Parameters
name:String

Determines which descriptors are loaded.

registerRunningServiceback to summary
public <T> void registerRunningService(Class<T> serviceClass, T provider)

Implements com.sun.enterprise.module.ModulesRegistry.registerRunningService.

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:Class<T>

the service interface

provider:T

the provider of that service.

removeback to summary
public void remove(HK2Module module)

Removes a module from the registry. The module will not be accessible from this registry after this method returns.

removeRepositoryback to summary
public void removeRepository(String name)

Implements com.sun.enterprise.module.ModulesRegistry.removeRepository.

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:String

name of the repository to remove

removeShutdownLocatorsback to summary
private void removeShutdownLocators()
unregisterRunningServiceback to summary
public <T> boolean unregisterRunningService(Class<T> serviceClass, T provider)

Implements com.sun.enterprise.module.ModulesRegistry.unregisterRunningService.

Removes a running service, this is useful when a service instance is no longer available as a provider of a service.