public final class ModuleImpl extends java.lang.Object implements Module
ModuleRegistry which can be used
to get the list of available modules and/or get particular module
implementation.
Modules can only satisfy their dependencies within the ModuleRegistry
instance they are registered in.| Modifier and Type | Field and Description |
|---|---|
private java.util.List<ModuleImpl> |
dependencies |
private java.util.HashMap<java.lang.String,java.lang.Long> |
lastModifieds |
private LifecyclePolicy |
lifecyclePolicy |
private java.util.ArrayList<ModuleChangeListener> |
listeners |
private ModuleDefinition |
moduleDef |
private ModuleClassLoader |
privateCL |
private java.lang.ref.WeakReference<ClassLoaderFacade> |
publicCL |
private ModulesRegistryImpl |
registry
ModulesRegistryImpl that owns this module. |
private java.util.Map<java.lang.String,java.util.List<java.lang.Class>> |
serviceClasses
Lazily loaded provider
Classes from ModuleMetadata. |
private boolean |
shared |
private ModuleState |
state |
private boolean |
sticky |
| Constructor and Description |
|---|
ModuleImpl(ModulesRegistryImpl registry,
ModuleDefinition info)
Creates a new instance of Module
|
| Modifier and Type | Method and Description |
|---|---|
void |
addImport(Module module) |
Module |
addImport(ModuleDependency dependency)
Create and add a new module to this module's list of
imports.
|
void |
addListener(ModuleChangeListener listener)
Add a new module change listener
|
void |
detach()
Detach this module from its registry.
|
void |
dumpState(java.io.PrintStream writer) |
protected void |
fireChangeEvent()
fires a ModuleChange event to all listeners
|
ClassLoaderFacade |
getClassLoader()
Return the
ClassLoader instance associated with this module. |
java.util.List<Module> |
getImports()
Returns the list of imported modules
|
ModuleMetadata |
getMetadata()
Gets the metadata of this module.
|
ModuleDefinition |
getModuleDefinition()
Returns the module definition for this module instance
|
java.lang.String |
getName()
Short-cut for
getModuleDefinition().getName(). |
(package private) ModuleClassLoader |
getPrivateClassLoader()
Return the private class loader for this module.
|
<T> java.lang.Iterable<java.lang.Class<? extends T>> |
getProvidersClass(java.lang.Class<T> serviceClass) |
java.lang.Iterable<java.lang.Class> |
getProvidersClass(java.lang.String name) |
ModulesRegistryImpl |
getRegistry()
Returns the registry owning this module
|
ModuleState |
getState()
Returns the module's state
|
boolean |
hasProvider(java.lang.Class serviceClass)
Returns true if this module has any provider for the given service class.
|
boolean |
isShared()
Returns true if this module is sharable.
|
boolean |
isSticky()
Returns true if the module is sticky.
|
(package private) java.util.List<ActiveDescriptor> |
parseInhabitants(java.lang.String name,
java.util.List<PopulatorPostProcessor> postProcessors)
Parses all the inhabitants descriptors of the given name in this module.
|
void |
refresh()
Trigger manual refresh mechanism, the module will check all its
URLs and generate change events if any of them has changed.
|
void |
removeImport(ModuleImpl module) |
void |
removeListener(ModuleChangeListener listener)
Unregister a module change listener
|
void |
resolve()
Ensure that this module is
resolved. |
(package private) void |
setShared(boolean sharable)
Sets the sharable flag.
|
void |
setSticky(boolean sticky)
Sets the sticky flag.
|
void |
start()
Forces module startup.
|
boolean |
stop()
Forces module stop.
|
java.lang.String |
toString()
Return a String representation
|
void |
uninstall()
Removes the module from the registry backing store, the module will need
be reinstalled to be loaded.
|
private final ModuleDefinition moduleDef
private java.lang.ref.WeakReference<ClassLoaderFacade> publicCL
private volatile ModuleClassLoader privateCL
private final java.util.Map<java.lang.String,java.util.List<java.lang.Class>> serviceClasses
Classes from ModuleMetadata.
The key is the service class name. We can't use Class because that would cause leaks.private final ModulesRegistryImpl registry
ModulesRegistryImpl that owns this module.
Always non-null.private ModuleState state
private final java.util.List<ModuleImpl> dependencies
private final java.util.ArrayList<ModuleChangeListener> listeners
private final java.util.HashMap<java.lang.String,java.lang.Long> lastModifieds
private boolean shared
private boolean sticky
private LifecyclePolicy lifecyclePolicy
ModuleImpl(ModulesRegistryImpl registry, ModuleDefinition info)
public ClassLoaderFacade getClassLoader()
ClassLoader instance associated with this module.
Only designated public interfaces will be loaded and returned by
this classloader.getClassLoader in interface ModuleClassLoaderModuleClassLoader getPrivateClassLoader()
ClassLoader instancepublic ModuleDefinition getModuleDefinition()
getModuleDefinition in interface Modulepublic ModulesRegistryImpl getRegistry()
getRegistry in interface Modulepublic void detach()
public java.lang.String toString()
toString in class java.lang.Objectpublic void addListener(ModuleChangeListener listener)
addListener in interface Modulelistener - the listenerpublic void removeListener(ModuleChangeListener listener)
removeListener in interface Modulelistener - the listener to unregisterprotected void fireChangeEvent()
public void refresh()
public ModuleMetadata getMetadata()
getMetadata in interface Modulejava.util.List<ActiveDescriptor> parseInhabitants(java.lang.String name, java.util.List<PopulatorPostProcessor> postProcessors) throws java.io.IOException
java.io.IOExceptionpublic void resolve()
throws ResolveError
resolved.
If the module is already resolved, this method does nothing.
Otherwise, iterate over all declared ModuleDependency instances and use the
associated ModuleRegistry to resolve it. After successful
completion of this method, the module state is
ModuleState.RESOLVED.
resolve in interface ModuleResolveError - if any of the declared dependency of this module
cannot be satisfiedpublic void start()
throws ResolveError
ModuleState.READY, the
Lifecycle.start method will be invoked.start in interface ModuleResolveErrorpublic boolean stop()
LifecyclePolicy for this module is defined, the
Lifecycle.stop(Module)
method will be called and finally the module state will be
returned to ModuleState.NEW.public java.util.List<Module> getImports()
getImports in interface Modulepublic Module addImport(ModuleDependency dependency)
public ModuleState getState()
public void removeImport(ModuleImpl module)
public java.lang.String getName()
getModuleDefinition().getName().public boolean isShared()
void setShared(boolean sharable)
sharable - set to true to share the modulepublic boolean isSticky()
public void setSticky(boolean sticky)
public <T> java.lang.Iterable<java.lang.Class<? extends T>> getProvidersClass(java.lang.Class<T> serviceClass)
getProvidersClass in interface Modulepublic java.lang.Iterable<java.lang.Class> getProvidersClass(java.lang.String name)
getProvidersClass in interface Modulepublic boolean hasProvider(java.lang.Class serviceClass)
hasProvider in interface Modulepublic void dumpState(java.io.PrintStream writer)