Class ModuleImpl
java.lang.Object
com.sun.enterprise.module.impl.ModuleImpl
- All Implemented Interfaces:
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 a
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.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<ModuleImpl> private LifecyclePolicyprivate final ArrayList<ModuleChangeListener> private final ModuleDefinitionprivate ModuleClassLoaderprivate WeakReference<ClassLoaderFacade> private final ModulesRegistryImplModulesRegistryImplthat owns this module.Lazily loaded providerClasses fromModuleMetadata.private booleanprivate ModuleStateprivate boolean -
Constructor Summary
ConstructorsConstructorDescriptionModuleImpl(ModulesRegistryImpl registry, ModuleDefinition info) Creates a new instance of Module -
Method Summary
Modifier and TypeMethodDescriptionvoidaddImport(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(PrintStream writer) protected voidfires a ModuleChange event to all listenersReturn theClassLoaderinstance associated with this module.Returns the list of imported modulesGets the metadata of this module.Returns the module definition for this module instancegetName()Short-cut forgetModuleDefinition().getName().(package private) ModuleClassLoaderReturn the private class loader for this module.getProvidersClass(Class<T> serviceClass) getProvidersClass(String name) Returns the registry owning this modulegetState()Returns the module's statebooleanhasProvider(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) List<ActiveDescriptor> parseInhabitants(String name, 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.toString()Return a String representationvoidRemoves the module from the registry backing store, the module will need be reinstalled to be loaded.
-
Field Details
-
moduleDef
-
publicCL
-
privateCL
-
serviceClasses
-
registry
ModulesRegistryImplthat owns this module. Always non-null. -
state
-
dependencies
-
listeners
-
lastModifieds
-
sticky
private boolean sticky -
lifecyclePolicy
-
-
Constructor Details
-
ModuleImpl
ModuleImpl(ModulesRegistryImpl registry, ModuleDefinition info) Creates a new instance of Module
-
-
Method Details
-
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
Returns the module definition for this module instance- Specified by:
getModuleDefinitionin interfaceModule- Returns:
- the module definition
-
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
-
addListener
Add a new module change listener- Specified by:
addListenerin interfaceModule- Parameters:
listener- the listener
-
removeListener
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
-
getMetadata
Gets the metadata of this module.- Specified by:
getMetadatain interfaceModule
-
parseInhabitants
List<ActiveDescriptor> parseInhabitants(String name, List<PopulatorPostProcessor> postProcessors) throws IOException Parses all the inhabitants descriptors of the given name in this module.- Returns:
- Throws:
IOException
-
resolve
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
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
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.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
Returns the list of imported modules- Specified by:
getImportsin interfaceModule- Returns:
- the list of imported modules
-
addImport
Create and add a new module to this module's list of imports. -
getState
Returns the module's state -
addImport
-
removeImport
-
getName
-
isSticky
-
setSticky
-
getProvidersClass
- Specified by:
getProvidersClassin interfaceModule
-
getProvidersClass
- Specified by:
getProvidersClassin interfaceModule
-
hasProvider
Returns true if this module has any provider for the given service class.- Specified by:
hasProviderin interfaceModule
-
dumpState
-
uninstall
-