A module's execution context within the Runtime. The context is used to grant access to other methods so that this module can interact with the Runtime.
{@code ModuleContext} methods allow a module to:
- Subscribe to events published by the Runtime.
- Register service objects with the Runtime service registry.
- Retrieve {@code ServiceReferences} from the Runtime service registry.
- Get and release service objects for a referenced service.
- Create {@code File} objects for files in a persistent storage area provided for the module by the Runtime.
A {@code ModuleContext} object will be created for a module when the moduleis started. The {@code Module} object associated with a {@code ModuleContext}object is called the context module.
The {@code ModuleContext} object will be passed to the{@link ModuleActivator#start(ModuleContext)} method during activation of thecontext module. The same {@code ModuleContext} object will be passed to the{@link ModuleActivator#stop(ModuleContext)} method when the context module isstopped. A {@code ModuleContext} object is generally for the private use ofits associated module and is not meant to be shared with other modules in the environment.
The {@code ModuleContext} object is only valid during the execution of itscontext module; that is, during the period from when the context module is in the {@code STARTING}, {@code STOPPING}, and {@code ACTIVE} module states. Ifthe {@code ModuleContext} object is used subsequently, an{@code IllegalStateException} must be thrown. The {@code ModuleContext}object must never be reused after its context module is stopped.
Two {@code ModuleContext} objects are equal if they both refer to the sameexecution context of a module. The Runtime is the only entity that can create {@code ModuleContext} objects and they are only valid within theRuntime that created them.
A {@link Module} can be {@link Module#adapt(Class) adapted} to its{@code ModuleContext}.
@author thomas.diesler@jboss.com
@since 27-Sep-2013
@ThreadSafe