public abstract class AbstractModulesRegistryImpl extends Object implements ModulesRegistry
Modifier and Type | Field and 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 |
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,
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 ModulesRegistry.newServiceLocator() followed by
#populateServiceLocator(String, org.glassfish.hk2.api.ServiceLocator, java.util.List . |
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 name
|
Iterable<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 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
|
protected 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 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. |
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 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 a
ServiceLocator from all the modules in this registry |
void |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createChild, detachAll, find, getModulesClassLoader, getModulesClassLoader, getParentClassLoader, register, setParentClassLoader, shutdown, unregister
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.protected final ConcurrentMap<ModuleId,Module> modules
protected final Map<Integer,Repository> repositories
protected AbstractModulesRegistryImpl(ModulesRegistry parent)
public ServiceLocator newServiceLocator() throws MultiException
ServiceLocator
newServiceLocator
in interface ModulesRegistry
MultiException
public ServiceLocator newServiceLocator(ServiceLocator parent) throws MultiException
newServiceLocator
in interface ModulesRegistry
MultiException
protected void initializeServiceLocator(ServiceLocator serviceLocator) throws MultiException
MultiException
public void populateServiceLocator(String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors) throws MultiException
ServiceLocator
from all the modules in this registrypopulateServiceLocator
in interface ModulesRegistry
name
- Determines which descriptors are loaded.postProcessors
- serviceLocator
- Habitat to initialize, null if it should be createdMultiException
public void populateConfig(ServiceLocator serviceLocator)
populateConfig
in interface ModulesRegistry
public ServiceLocator createServiceLocator(ServiceLocator parent, String name, List<PopulatorPostProcessor> postProcessors) throws MultiException
ModulesRegistry
ServiceLocator
with the provided parent.createServiceLocator
in interface ModulesRegistry
MultiException
public ServiceLocator createServiceLocator(String name) throws MultiException
ModulesRegistry
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
.createServiceLocator
in interface ModulesRegistry
name
- Determines which inhabitants descriptors are loaded.
(so that different parallel habitats can be
created over the same modules registry.)MultiException
public ServiceLocator createServiceLocator() throws MultiException
ModulesRegistry
ServiceLocator
from all the modules in this registry
Calling this method has the same effect of calling #createServiceLocator("default")
createServiceLocator
in interface ModulesRegistry
MultiException
protected abstract List<ActiveDescriptor> parseInhabitants(Module module, String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors) throws IOException, BootException
IOException
BootException
public 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 ModulesRegistry
repository
- 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 ModulesRegistry
repository
- new repository to attach to this registrypublic void removeRepository(String name)
Repository
name will not be used to procure missing modules any
longerremoveRepository
in interface ModulesRegistry
name
- name of the repository to removepublic Repository getRepository(String name)
getRepository
in interface ModulesRegistry
name
- name of the repository to returnpublic Module makeModuleFor(String name, String version) throws ResolveError
Module
instance giving a name and version
constraints.makeModuleFor
in interface ModulesRegistry
name
- the module nameversion
- the module version.ResolveError
- if the module dependencies cannot be resolvedpublic Module makeModuleFor(String name, String version, boolean resolve) throws ResolveError
ModulesRegistry
Module
instance giving a name and version
constraints.makeModuleFor
in interface ModulesRegistry
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 resolvedpublic Module makeModuleFor(String packageName) throws ResolveError
makeModuleFor
in interface ModulesRegistry
packageName
- the requested implementation package name.Module
instance implementing the package
name or null if not found.ResolveError
- if the module dependencies cannot be resolvedprotected 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 Set<ServiceLocator> getAllServiceLocators()
public Collection<Module> getModules()
The returned list will not include the modules defined in the ancestor
AbstractModulesRegistryImpl
s.
getModules
in interface ModulesRegistry
public Collection<Module> getModules(String moduleName)
ModulesRegistry
The returned list will not include the modules defined in the ancestor
ModulesRegistry
s.
getModules
in interface ModulesRegistry
public void changed(Module service)
changed
in interface ModuleChangeListener
public Module add(ModuleDefinition info) throws ResolveError
Module
instances.add
in interface ModulesRegistry
ResolveError
public Module add(ModuleDefinition info, boolean resolve) throws ResolveError
ModulesRegistry
Module
instances.add
in interface ModulesRegistry
info
- ModuleDefinition representing the new module contentresolve
- should the new module be resolved or notResolveError
public void print(Logger logger)
print
in interface ModulesRegistry
logger
- the logger to dump onpublic <T> Iterable<Class<? extends T>> getProvidersClass(Class<T> serviceClass)
getProvidersClass
in interface ModulesRegistry
public Iterable<Module> getModulesProvider(Class serviceClass)
getModulesProvider
in interface ModulesRegistry
serviceClass
- the service interface classpublic <T> void registerRunningService(Class<T> serviceClass, T provider)
registerRunningService
in interface ModulesRegistry
serviceClass
- the service interfaceprovider
- the provider of that service.public <T> boolean unregisterRunningService(Class<T> serviceClass, T provider)
unregisterRunningService
in interface ModulesRegistry
public <T> List<T> getRunningServices(Class<T> serviceClass)
getRunningServices
in interface ModulesRegistry
serviceClass
- the service interfacepublic Module getProvidingModule(String providerClassName)
ModulesRegistry
Module
that provides the provider of the given name.getProvidingModule
in interface ModulesRegistry
public void dumpState(PrintStream writer)
dumpState
in interface ModulesRegistry
Copyright © 2009–2023 Oracle Corporation. All rights reserved.