Package com.sun.enterprise.module.impl
Class ModuleImpl
- java.lang.Object
-
- com.sun.enterprise.module.impl.ModuleImpl
-
- All Implemented Interfaces:
Module
public final class ModuleImpl extends java.lang.Object implements Module
A module represents a set of resources accessible to third party modules. Each module has a module definition which defines its name, its list of exported resources and its dependencies to other modules. A module instance stores references to the class loader instances giving access to the module's implementation. A module instance belongs to aModuleRegistrywhich can be used to get the list of available modules and/or get particular module implementation. Modules can only satisfy their dependencies within theModuleRegistryinstance they are registered in.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<ModuleImpl>dependenciesprivate java.util.HashMap<java.lang.String,java.lang.Long>lastModifiedsprivate LifecyclePolicylifecyclePolicyprivate java.util.ArrayList<ModuleChangeListener>listenersprivate ModuleDefinitionmoduleDefprivate ModuleClassLoaderprivateCLprivate java.lang.ref.WeakReference<ClassLoaderFacade>publicCLprivate ModulesRegistryImplregistryModulesRegistryImplthat owns this module.private java.util.Map<java.lang.String,java.util.List<java.lang.Class>>serviceClassesLazily loaded providerClasses fromModuleMetadata.private booleansharedprivate ModuleStatestateprivate booleansticky
-
Constructor Summary
Constructors Constructor Description ModuleImpl(ModulesRegistryImpl registry, ModuleDefinition info)Creates a new instance of Module
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddImport(Module module)ModuleaddImport(ModuleDependency dependency)Create and add a new module to this module's list of imports.voidaddListener(ModuleChangeListener listener)Add a new module change listenervoiddetach()Detach this module from its registry.voiddumpState(java.io.PrintStream writer)protected voidfireChangeEvent()fires a ModuleChange event to all listenersClassLoaderFacadegetClassLoader()Return theClassLoaderinstance associated with this module.java.util.List<Module>getImports()Returns the list of imported modulesModuleMetadatagetMetadata()Gets the metadata of this module.ModuleDefinitiongetModuleDefinition()Returns the module definition for this module instancejava.lang.StringgetName()Short-cut forgetModuleDefinition().getName().(package private) ModuleClassLoadergetPrivateClassLoader()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)ModulesRegistryImplgetRegistry()Returns the registry owning this moduleModuleStategetState()Returns the module's statebooleanhasProvider(java.lang.Class serviceClass)Returns true if this module has any provider for the given service class.booleanisShared()Returns true if this module is sharable.booleanisSticky()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.voidrefresh()Trigger manual refresh mechanism, the module will check all its URLs and generate change events if any of them has changed.voidremoveImport(ModuleImpl module)voidremoveListener(ModuleChangeListener listener)Unregister a module change listenervoidresolve()Ensure that this module isresolved.(package private) voidsetShared(boolean sharable)Sets the sharable flag.voidsetSticky(boolean sticky)Sets the sticky flag.voidstart()Forces module startup.booleanstop()Forces module stop.java.lang.StringtoString()Return a String representationvoiduninstall()Removes the module from the registry backing store, the module will need be reinstalled to be loaded.
-
-
-
Field Detail
-
moduleDef
private final ModuleDefinition moduleDef
-
publicCL
private java.lang.ref.WeakReference<ClassLoaderFacade> publicCL
-
privateCL
private volatile ModuleClassLoader privateCL
-
serviceClasses
private final java.util.Map<java.lang.String,java.util.List<java.lang.Class>> serviceClasses
Lazily loaded providerClasses fromModuleMetadata. The key is the service class name. We can't useClassbecause that would cause leaks.
-
registry
private final ModulesRegistryImpl registry
ModulesRegistryImplthat owns this module. Always non-null.
-
state
private ModuleState state
-
dependencies
private final java.util.List<ModuleImpl> dependencies
-
listeners
private final java.util.ArrayList<ModuleChangeListener> listeners
-
lastModifieds
private final java.util.HashMap<java.lang.String,java.lang.Long> lastModifieds
-
shared
private boolean shared
-
sticky
private boolean sticky
-
lifecyclePolicy
private LifecyclePolicy lifecyclePolicy
-
-
Constructor Detail
-
ModuleImpl
ModuleImpl(ModulesRegistryImpl registry, ModuleDefinition info)
Creates a new instance of Module
-
-
Method Detail
-
getClassLoader
public ClassLoaderFacade getClassLoader()
Return theClassLoaderinstance associated with this module. Only designated public interfaces will be loaded and returned by this classloader.- Specified by:
getClassLoaderin interfaceModule- Returns:
- the public
ClassLoader
-
getPrivateClassLoader
ModuleClassLoader getPrivateClassLoader()
Return the private class loader for this module. This class loader will be loading all the classes which are not explicitely exported in the module definition- Returns:
- the private
ClassLoaderinstance
-
getModuleDefinition
public ModuleDefinition getModuleDefinition()
Returns the module definition for this module instance- Specified by:
getModuleDefinitionin interfaceModule- Returns:
- the module definition
-
getRegistry
public ModulesRegistryImpl getRegistry()
Returns the registry owning this module- Specified by:
getRegistryin interfaceModule- Returns:
- the registry owning the module
-
detach
public void detach()
Detach this module from its registry. This does not free any of the loaded resources. Only proper release of all references to the public class loader will ensure module being garbage collected. Detached modules are orphan and will be garbage collected if resources are properly disposed.
-
toString
public java.lang.String toString()
Return a String representation- Overrides:
toStringin classjava.lang.Object- Returns:
- a descriptive String about myself
-
addListener
public void addListener(ModuleChangeListener listener)
Add a new module change listener- Specified by:
addListenerin interfaceModule- Parameters:
listener- the listener
-
removeListener
public void removeListener(ModuleChangeListener listener)
Unregister a module change listener- Specified by:
removeListenerin interfaceModule- Parameters:
listener- the listener to unregister
-
fireChangeEvent
protected void fireChangeEvent()
fires a ModuleChange event to all listeners
-
refresh
public void refresh()
Trigger manual refresh mechanism, the module will check all its URLs and generate change events if any of them has changed. This will allow the owning registry to force a module upgrade at next module request.
-
getMetadata
public ModuleMetadata getMetadata()
Gets the metadata of this module.- Specified by:
getMetadatain interfaceModule
-
parseInhabitants
java.util.List<ActiveDescriptor> parseInhabitants(java.lang.String name, java.util.List<PopulatorPostProcessor> postProcessors) throws java.io.IOException
Parses all the inhabitants descriptors of the given name in this module.- Returns:
- Throws:
java.io.IOException
-
resolve
public void resolve() throws ResolveErrorEnsure that this module isresolved.If the module is already resolved, this method does nothing. Otherwise, iterate over all declared ModuleDependency instances and use the associated
ModuleRegistryto resolve it. After successful completion of this method, the module state isModuleState.RESOLVED.- Specified by:
resolvein interfaceModule- Throws:
ResolveError- if any of the declared dependency of this module cannot be satisfied
-
start
public void start() throws ResolveErrorForces module startup. In most cases, the runtime will take care of starting modules when they are first used. There could be cases where code need to manually start a sub module. Invoking this method will move the module to theModuleState.READY, theLifecycle.startmethod will be invoked.- Specified by:
startin interfaceModule- Throws:
ResolveError
-
stop
public boolean stop()
Forces module stop. In most cases, the runtime will take care of stopping modules when the last module user released its interest. However, in certain cases, it may be interesting to manually stop the module. Stopping the module means that the module is removed from the registry, the class loader references are released (note : the class loaders will only be released if all instances of any class loaded by them are gc'ed). If aLifecyclePolicyfor this module is defined, theLifecycle.stop(Module)method will be called and finally the module state will be returned toModuleState.NEW.
-
getImports
public java.util.List<Module> getImports()
Returns the list of imported modules- Specified by:
getImportsin interfaceModule- Returns:
- the list of imported modules
-
addImport
public Module addImport(ModuleDependency dependency)
Create and add a new module to this module's list of imports.
-
getState
public ModuleState getState()
Returns the module's state
-
removeImport
public void removeImport(ModuleImpl module)
-
getName
public java.lang.String getName()
Short-cut forgetModuleDefinition().getName().
-
isShared
public boolean isShared()
Returns true if this module is sharable. A sharable module means that onlu one instance of the module classloader will be used by all users.
-
setShared
void setShared(boolean sharable)
Sets the sharable flag. Setting the flag to false means that the moodule class loader should not be shared among module owners.- Parameters:
sharable- set to true to share the module
-
isSticky
public boolean isSticky()
Returns true if the module is sticky. A sticky module cannot be stopped or unloaded. Once a sticky module is loaded or started, it will stay in the JVM until it exists.
-
setSticky
public void setSticky(boolean sticky)
Sets the sticky flag.
-
getProvidersClass
public <T> java.lang.Iterable<java.lang.Class<? extends T>> getProvidersClass(java.lang.Class<T> serviceClass)
- Specified by:
getProvidersClassin interfaceModule
-
getProvidersClass
public java.lang.Iterable<java.lang.Class> getProvidersClass(java.lang.String name)
- Specified by:
getProvidersClassin interfaceModule
-
hasProvider
public boolean hasProvider(java.lang.Class serviceClass)
Returns true if this module has any provider for the given service class.- Specified by:
hasProviderin interfaceModule
-
dumpState
public void dumpState(java.io.PrintStream writer)
-
-