public interface Module
A module must have a unique ResourceIdentity in the Runtime.
Gravia stays out of the business of resolving module's at runtime. Every module
has an associated ClassLoader when it is installed in the runtime already.
Modularity must be dealt with in the layer using the Gravia runtime.
For example, a servlet container like Tomcat may choose to create one Module per web application. Multiple modules may share the same class loader or may even all have the same class loader association. This allows GRavia to run on a flat class path (e.g. a plain JUnit test)
When installed it is also assigned a long identity, chosen by the Runtime.
This identity does not change during the lifecycle of a module.
Uninstalling and then reinstalling the module creates a new unique long identity.
A module can be in one of six states:
Module.State.INSTALLED
State#RESOLVED
Module.State.STARTING
Module.State.ACTIVE
Module.State.STOPPING
Module.State.UNINSTALLED
A module should only have active threads of execution when its state is one
of STARTING,ACTIVE, or STOPPING.
An UNINSTALLED module can not be set to another state;
it can only be reached because references are kept somewhere.
The Runtime is the only entity that is allowed to create Module
objects, and these objects are only valid within the Runtime that created
them.
Modules have a natural ordering such that if two Modules have the
same module id they are equal. A Module is
less than another Module if it has a lower module id and is greater if it has a higher module id.
| Modifier and Type | Interface and Description |
|---|---|
static class |
Module.State
A module can be in one of five states:
|
| Modifier and Type | Method and Description |
|---|---|
<A> A |
adapt(Class<A> type)
Addapt this module to another type.
|
List<URL> |
findEntries(String path,
String filePattern,
boolean recurse)
Returns entries in this module.
|
File |
getDataFile(String filename)
Creates a
File object for a file in the persistent storage area
provided for this module by the Runtime. |
URL |
getEntry(String path)
Returns a URL to the entry at the specified path in this module.
|
List<String> |
getEntryPaths(String path)
Returns an Enumeration of all the paths (
String objects) to
entries within this module whose longest sub-path matches the specified
path. |
Dictionary<String,String> |
getHeaders()
Returns this module's headers and values that where given on module installation.
|
org.jboss.gravia.resource.ResourceIdentity |
getIdentity()
Get the identity of this module.
|
ModuleContext |
getModuleContext()
Returns this module's
ModuleContext. |
long |
getModuleId()
Returns this module's unique identifier.
|
Module.State |
getState()
Returns this module's current state.
|
Class<?> |
loadClass(String className)
Loads the specified class using this module's class loader.
|
void |
start()
Starts this module.
|
void |
stop()
Stops this module.
|
void |
uninstall()
Uninstalls this module.
|
<A> A adapt(Class<A> type)
RuntimeClassLoaderResourceModuleContextorg.jboss.gravia.resource.ResourceIdentity getIdentity()
long getModuleId()
A module's unique identifier has the following attributes:
long.
This method must continue to return this module's unique identifier while
this module is in the UNINSTALLED state.
Module.State getState()
Module.StateModuleContext getModuleContext()
ModuleContext. The returned
ModuleContext can be used by the caller to act on behalf of this
module.
If this module is not in the Module.State.STARTING, Module.State.ACTIVE, or
Module.State.STOPPING states, then this module has no valid ModuleContext.
ModuleContext for this module or null if this
module has no valid ModuleContext.Dictionary<String,String> getHeaders()
These values may be mapped to manifest headers, but this is not a requirement. The module's header values do not change durint the lifecycle of the module.
Header names are case-insensitive. The methods of the returned
Dictionary object must operate on header names in a
case-insensitive manner.
This method must continue to return header information while
this module is in the UNINSTALLED state.
Dictionary object containing this
module's Manifest headers and values.URL getEntry(String path)
The specified path is always relative to the root of this module and may begin with "/". A path value of "/" indicates the root of this module.
path - The path name of the entry.null if no entry could be found.List<String> getEntryPaths(String path)
String objects) to
entries within this module whose longest sub-path matches the specified
path. This module's class loader is not used to search for entries. Only
the contents of this module are searched.
The specified path is always relative to the root of this module and may begin with a "/". A path value of "/" indicates the root of this module.
Returned paths indicating subdirectory paths end with a "/". The returned paths are all relative to the root of this module and must not begin with "/".
path - The path name for which to return entry paths.String objects).List<URL> findEntries(String path, String filePattern, boolean recurse)
URLs for directory entries must have their path end with "/".
path - The path name in which to look. The path is always relative
to the root of this module and may begin with "/". A
path value of "/" indicates the root of this module.filePattern - The file name pattern for selecting entries in the
specified path. The pattern is only matched against the last
element of the entry path. If the entry is a directory then the
trailing "/" is not used for pattern matching. Substring
matching is supported, as specified in the Filter specification,
using the wildcard character ("*"). If null is
specified, this is equivalent to "*" and matches all
files.recurse - If true, recurse into subdirectories. Otherwise
only return entries from the specified path.void start()
throws ModuleException
If this module's state is UNINSTALLED then an IllegalStateException is thrown.
The following steps are required to start this module:
ModuleException is thrown to indicate this module was unable to
be started.
ACTIVE then this method returns immediately.
STARTING.
ModuleEvent.STARTING is fired.
ModuleActivator.start(ModuleContext) method if one is specified, is called.
If the ModuleActivator is invalid or throws an exception then:
STOPPING.
ModuleEvent.STOPPING is fired.
RESOLVED.
ModuleEvent.STOPPED is fired.
ModuleException is then thrown.
ACTIVE.
ModuleEvent.STARTED is fired.
ModuleException - If the module cannot be startedvoid stop()
throws ModuleException
If this module's state is UNINSTALLED then an IllegalStateException is thrown.
The following steps are required to stop this module:
ModuleException is thrown to indicate this module was unable to
be stopped.
ACTIVE then this method returns immediately.
STOPPING.
ModuleEvent.STOPPING is fired.
ModuleActivator.stop(ModuleContext) method of this module's ModuleActivator,
if one is specified, is called. If that method throws an exception, this method must continue to
stop this module and a ModuleException must be thrown after
completion of the remaining steps.
RESOLVED.
ModuleEvent.STOPPED is fired.
ModuleException - If the module cannot be startedvoid uninstall()
This method causes the Runtime to notify other modules that this module
is being uninstalled, and then puts this module into the
UNINSTALLED state. The Runtime must remove any resources
related to this module that it is able to remove.
If this module's state is UNINSTALLED then an IllegalStateException is thrown.
The following steps are required to uninstall a module:
Module.stop method.
UNINSTALLED.
ModuleEvent.UNINSTALLED is fired.
Class<?> loadClass(String className) throws ClassNotFoundException
If this module's state is UNINSTALLED, then an
IllegalStateException is thrown.
className - The name of the class to load.ClassNotFoundExceptionFile getDataFile(String filename)
File object for a file in the persistent storage area
provided for this module by the Runtime. This method will return
null if the platform does not have file system support.
A File object for the base directory of the persistent storage
area provided for this module by the Runtime can be obtained by calling
this method with an empty string as filename.
If the Java Runtime Environment supports permissions, the Runtime will
ensure that this module has the java.io.FilePermission with
actions read,write,delete for all files
(recursively) in the persistent storage area provided for this module.
filename - A relative name to the file to be accessed.File object that represents the requested file or
null if the platform does not have file system support.IllegalStateException - If this module has been uninstalled.Copyright © 2014 JBoss by Red Hat. All Rights Reserved.