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 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 aModuleRegistry
which can be used to get the list of available modules and/or get particular module implementation. Modules can only satisfy their dependencies within theModuleRegistry
instance they are registered in.- Author:
- Jerome Dochez
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 listenervoid
detach()
Detach this module from its registry.void
dumpState(PrintStream writer)
protected void
fireChangeEvent()
fires a ModuleChange event to all listenerscom.sun.enterprise.module.impl.ClassLoaderFacade
getClassLoader()
Return theClassLoader
instance associated with this module.List<Module>
getImports()
Returns the list of imported modulesModuleMetadata
getMetadata()
Gets the metadata of this module.ModuleDefinition
getModuleDefinition()
Returns the module definition for this module instanceString
getName()
Short-cut forgetModuleDefinition().getName()
.<T> Iterable<Class<? extends T>>
getProvidersClass(Class<T> serviceClass)
Iterable<Class>
getProvidersClass(String name)
ModulesRegistryImpl
getRegistry()
Returns the registry owning this moduleModuleState
getState()
Returns the module's stateboolean
hasProvider(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.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 listenervoid
resolve()
Ensure that this module isresolved
.void
setSticky(boolean sticky)
Sets the sticky flag.void
start()
Forces module startup.boolean
stop()
Forces module stop.String
toString()
Return a String representationvoid
uninstall()
Removes the module from the registry backing store, the module will need be reinstalled to be loaded.
-
-
-
Method Detail
-
getClassLoader
public com.sun.enterprise.module.impl.ClassLoaderFacade getClassLoader()
Return theClassLoader
instance associated with this module. Only designated public interfaces will be loaded and returned by this classloader.- Specified by:
getClassLoader
in interfaceModule
- Returns:
- the public
ClassLoader
-
getModuleDefinition
public ModuleDefinition getModuleDefinition()
Returns the module definition for this module instance- Specified by:
getModuleDefinition
in interfaceModule
- Returns:
- the module definition
-
getRegistry
public ModulesRegistryImpl getRegistry()
Returns the registry owning this module- Specified by:
getRegistry
in 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 String toString()
Return a String representation
-
addListener
public void addListener(ModuleChangeListener listener)
Add a new module change listener- Specified by:
addListener
in interfaceModule
- Parameters:
listener
- the listener
-
removeListener
public void removeListener(ModuleChangeListener listener)
Unregister a module change listener- Specified by:
removeListener
in 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:
getMetadata
in interfaceModule
-
resolve
public void resolve() throws ResolveError
Ensure 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
ModuleRegistry
to resolve it. After successful completion of this method, the module state isModuleState.RESOLVED
.- Specified by:
resolve
in interfaceModule
- Throws:
ResolveError
- if any of the declared dependency of this module cannot be satisfied
-
start
public void start() throws ResolveError
Forces 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.start
method will be invoked.- Specified by:
start
in 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 aLifecyclePolicy
for this module is defined, theLifecycle.stop(Module)
method will be called and finally the module state will be returned toModuleState.NEW
.
-
getImports
public List<Module> getImports()
Returns the list of imported modules- Specified by:
getImports
in 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 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.
-
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> Iterable<Class<? extends T>> getProvidersClass(Class<T> serviceClass)
- Specified by:
getProvidersClass
in interfaceModule
-
getProvidersClass
public Iterable<Class> getProvidersClass(String name)
- Specified by:
getProvidersClass
in interfaceModule
-
hasProvider
public boolean hasProvider(Class serviceClass)
Returns true if this module has any provider for the given service class.- Specified by:
hasProvider
in interfaceModule
-
dumpState
public void dumpState(PrintStream writer)
-
-