Top Description Fields Constructors Methods
com.sun.enterprise.module.impl

public final Class ModuleImpl

extends Object
implements HK2Module
Class Inheritance
All Implemented Interfaces
com.sun.enterprise.module.HK2Module
Imports
com.sun.enterprise.module.ImportPolicy, .LifecyclePolicy, .ModuleChangeListener, .ModuleDefinition, .ModuleDependency, .ModuleLifecycleListener, .ModuleMetadata, .ModuleState, .ResolveError, .HK2Module, com.sun.enterprise.module.common_impl.LogHelper, java.io.File, .IOException, .PrintStream, java.lang.ref.WeakReference, java.net.MalformedURLException, .URI, .URL, java.security.AccessController, .PrivilegedAction, java.util.ArrayList, .Collections, .HashMap, .HashSet, .LinkedList, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.locks.ReentrantLock, java.util.logging.Level, .Logger, org.glassfish.hk2.api.ActiveDescriptor, .PopulatorPostProcessor

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.
Author
Jerome Dochez

Field Summary

Modifier and TypeField and Description
private final List<ModuleImpl>
private final HashMap<String, Long>
private LifecyclePolicy
private final ArrayList<ModuleChangeListener>
private final ReentrantLock
private final ModuleDefinition
private volatile ModuleClassLoader
private WeakReference<ClassLoaderFacade>
private final ModulesRegistryImpl
registry

ModulesRegistryImpl that owns this module.

private final Map<String, List<Class<T>>>
private boolean
private ModuleState
private boolean

Constructor Summary

AccessConstructor and Description
pack-priv
ModuleImpl(ModulesRegistryImpl registry, ModuleDefinition info)

Creates a new instance of HK2Module

Method Summary

Modifier and TypeMethod and Description
public HK2Module
addImport(ModuleDependency
new module's definition
dependency
)

Implements com.sun.enterprise.module.HK2Module.addImport.

Create and add a new module to this module's list of imports.

public void
public void
addListener(ModuleChangeListener
the listener
listener
)

Implements com.sun.enterprise.module.HK2Module.addListener.

Add a new module change listener

public void
detach()

Implements com.sun.enterprise.module.HK2Module.detach.

Detach this module from its registry.

public void
protected void
fireChangeEvent()

fires a ModuleChange event to all listeners

public ClassLoaderFacade

Returns:

the public ClassLoader
getClassLoader
()

Implements com.sun.enterprise.module.HK2Module.getClassLoader.

Return the ClassLoader instance associated with this module.

public List<HK2Module>

Returns:

the list of imported modules
getImports
()

Implements com.sun.enterprise.module.HK2Module.getImports.

Returns the list of imported modules

public ModuleMetadata
getMetadata()

Implements com.sun.enterprise.module.HK2Module.getMetadata.

Gets the metadata of this module.

public ModuleDefinition

Returns:

the module definition
getModuleDefinition
()

Implements com.sun.enterprise.module.HK2Module.getModuleDefinition.

Returns the module definition for this module instance

public String
getName()

Implements com.sun.enterprise.module.HK2Module.getName.

Short-cut for getModuleDefinition().getName().

pack-priv ModuleClassLoader

Returns:

the private ClassLoader instance
getPrivateClassLoader
()

Return the private class loader for this module.

public <T> Iterable<Class<? extends T>>
public Iterable<Class<T>>
public ModulesRegistryImpl

Returns:

the registry owning the module
getRegistry
()

Implements com.sun.enterprise.module.HK2Module.getRegistry.

Returns the registry owning this module

public ModuleState

Returns:

the module's state
getState
()

Implements com.sun.enterprise.module.HK2Module.getState.

Returns the module's state

public boolean
hasProvider(Class<T> serviceClass)

Implements com.sun.enterprise.module.HK2Module.hasProvider.

Returns true if this module has any provider for the given service class.

public boolean

Returns:

true if this module is sharable.
isShared
()

Implements com.sun.enterprise.module.HK2Module.isShared.

Returns true if this module is sharable.

public boolean

Returns:

true is the module is sticky
isSticky
()

Implements com.sun.enterprise.module.HK2Module.isSticky.

Returns true if the module is sticky.

pack-priv List<ActiveDescriptor<T>>
parseInhabitants(String name, List<PopulatorPostProcessor> postProcessors)

Parses all the inhabitants descriptors of the given name in this module.

public void
refresh()

Implements com.sun.enterprise.module.HK2Module.refresh.

Trigger manual refresh mechanism, the module will check all its URLs and generate change events if any of them has changed.

public void
public void
removeListener(ModuleChangeListener
the listener to unregister
listener
)

Implements com.sun.enterprise.module.HK2Module.removeListener.

Unregister a module change listener

public void
resolve()

Implements com.sun.enterprise.module.HK2Module.resolve.

Ensure that this module is resolved.

pack-priv void
setShared(boolean
set to true to share the module
sharable
)

Sets the sharable flag.

public void
setSticky(boolean
true if the module should stick around
sticky
)

Implements com.sun.enterprise.module.HK2Module.setSticky.

Sets the sticky flag.

public void
start()

Implements com.sun.enterprise.module.HK2Module.start.

Forces module startup.

public boolean

Returns:

true if unloading was successful
stop
()

Implements com.sun.enterprise.module.HK2Module.stop.

Forces module stop.

public String

Returns:

a descriptive String about myself
toString
()

Overrides java.lang.Object.toString.

Return a String representation

public void
uninstall()

Implements com.sun.enterprise.module.HK2Module.uninstall.

Removes the module from the registry backing store, the module will need be reinstalled to be loaded.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

dependenciesback to summary
private final List<ModuleImpl> dependencies
lastModifiedsback to summary
private final HashMap<String, Long> lastModifieds
lifecyclePolicyback to summary
private LifecyclePolicy lifecyclePolicy
listenersback to summary
private final ArrayList<ModuleChangeListener> listeners
lockback to summary
private final ReentrantLock lock
moduleDefback to summary
private final ModuleDefinition moduleDef
privateCLback to summary
private volatile ModuleClassLoader privateCL
publicCLback to summary
private WeakReference<ClassLoaderFacade> publicCL
registryback to summary
private final ModulesRegistryImpl registry

ModulesRegistryImpl that owns this module. Always non-null.

serviceClassesback to summary
private final Map<String, List<Class<T>>> serviceClasses

Lazily loaded provider Classes from com.sun.enterprise.module.ModuleMetadata. The key is the service class name. We can't use Class because that would cause leaks.

sharedback to summary
private boolean shared
stateback to summary
private ModuleState state
stickyback to summary
private boolean sticky

Constructor Detail

ModuleImplback to summary
pack-priv ModuleImpl(ModulesRegistryImpl registry, ModuleDefinition info)

Creates a new instance of HK2Module

Method Detail

addImportback to summary
public HK2Module addImport(ModuleDependency dependency)

Implements com.sun.enterprise.module.HK2Module.addImport.

Create and add a new module to this module's list of imports.

Parameters
dependency:ModuleDependency

new module's definition

addImportback to summary
public void addImport(HK2Module module)

Implements com.sun.enterprise.module.HK2Module.addImport.

addListenerback to summary
public void addListener(ModuleChangeListener listener)

Implements com.sun.enterprise.module.HK2Module.addListener.

Add a new module change listener

Parameters
listener:ModuleChangeListener

the listener

detachback to summary
public void detach()

Implements com.sun.enterprise.module.HK2Module.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.

dumpStateback to summary
public void dumpState(PrintStream writer)

Implements com.sun.enterprise.module.HK2Module.dumpState.

fireChangeEventback to summary
protected void fireChangeEvent()

fires a ModuleChange event to all listeners

getClassLoaderback to summary
public ClassLoaderFacade getClassLoader()

Implements com.sun.enterprise.module.HK2Module.getClassLoader.

Return the ClassLoader instance associated with this module. Only designated public interfaces will be loaded and returned by this classloader.

Returns:ClassLoaderFacade

the public ClassLoader

getImportsback to summary
public List<HK2Module> getImports()

Implements com.sun.enterprise.module.HK2Module.getImports.

Returns the list of imported modules

Returns:List<HK2Module>

the list of imported modules

getMetadataback to summary
public ModuleMetadata getMetadata()

Implements com.sun.enterprise.module.HK2Module.getMetadata.

Gets the metadata of this module.

getModuleDefinitionback to summary
public ModuleDefinition getModuleDefinition()

Implements com.sun.enterprise.module.HK2Module.getModuleDefinition.

Returns the module definition for this module instance

Returns:ModuleDefinition

the module definition

getNameback to summary
public String getName()

Implements com.sun.enterprise.module.HK2Module.getName.

Short-cut for getModuleDefinition().getName().

getPrivateClassLoaderback to summary
pack-priv 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:ModuleClassLoader

the private ClassLoader instance

getProvidersClassback to summary
public <T> Iterable<Class<? extends T>> getProvidersClass(Class<T> serviceClass)

Implements com.sun.enterprise.module.HK2Module.getProvidersClass.

Annotations
@SuppressWarnings:unchecked
getProvidersClassback to summary
public Iterable<Class<T>> getProvidersClass(String name)

Implements com.sun.enterprise.module.HK2Module.getProvidersClass.

getRegistryback to summary
public ModulesRegistryImpl getRegistry()

Implements com.sun.enterprise.module.HK2Module.getRegistry.

Returns the registry owning this module

Returns:ModulesRegistryImpl

the registry owning the module

getStateback to summary
public ModuleState getState()

Implements com.sun.enterprise.module.HK2Module.getState.

Returns the module's state

Returns:ModuleState

the module's state

hasProviderback to summary
public boolean hasProvider(Class<T> serviceClass)

Implements com.sun.enterprise.module.HK2Module.hasProvider.

Returns true if this module has any provider for the given service class.

isSharedback to summary
public boolean isShared()

Implements com.sun.enterprise.module.HK2Module.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.

Returns:boolean

true if this module is sharable.

isStickyback to summary
public boolean isSticky()

Implements com.sun.enterprise.module.HK2Module.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.

Returns:boolean

true is the module is sticky

parseInhabitantsback to summary
pack-priv List<ActiveDescriptor<T>> parseInhabitants(String name, List<PopulatorPostProcessor> postProcessors) throws IOException

Parses all the inhabitants descriptors of the given name in this module.

refreshback to summary
public void refresh()

Implements com.sun.enterprise.module.HK2Module.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.

removeImportback to summary
public void removeImport(ModuleImpl module)
removeListenerback to summary
public void removeListener(ModuleChangeListener listener)

Implements com.sun.enterprise.module.HK2Module.removeListener.

Unregister a module change listener

Parameters
listener:ModuleChangeListener

the listener to unregister

resolveback to summary
public void resolve() throws ResolveError

Implements com.sun.enterprise.module.HK2Module.resolve.

Ensure that this module is 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.

Exceptions
ResolveError:
if any of the declared dependency of this module cannot be satisfied
setSharedback to summary
pack-priv 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:boolean

set to true to share the module

setStickyback to summary
public void setSticky(boolean sticky)

Implements com.sun.enterprise.module.HK2Module.setSticky.

Sets the sticky flag.

Parameters
sticky:boolean

true if the module should stick around

startback to summary
public void start() throws ResolveError

Implements com.sun.enterprise.module.HK2Module.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 the ModuleState.READY, the Lifecycle.start method will be invoked.

stopback to summary
public boolean stop()

Implements com.sun.enterprise.module.HK2Module.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 a LifecyclePolicy for this module is defined, the Lifecycle.stop(HK2Module) method will be called and finally the module state will be returned to ModuleState.NEW.

Returns:boolean

true if unloading was successful

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return a String representation

Returns:String

a descriptive String about myself

uninstallback to summary
public void uninstall()

Implements com.sun.enterprise.module.HK2Module.uninstall.

Doc from com.sun.enterprise.module.HK2Module.uninstall.

Removes the module from the registry backing store, the module will need be reinstalled to be loaded.