|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jbpm.env.Environment
public abstract class Environment
maintains contextual information for a thread in a set of
Context
s.
Objects have different lifecycles and different context's (aka scopes). An environment provides the structure to easily manage objects with different contexts.
Examples of contexts are:
EnvironmentFactory
.
So if the EnvironmentFactory
is maintained in a static member field, the
application context lives for the duration of the application.
The same application context is shared for all the Environments produced by one
EnvironmentFactory.WireContext
, this results
in an efficient and configurable use of transactional resources that need to be
lazily initialized.An environment is typically installed like this
static EnvironmentFactory environmentFactory = new DefaultEnvironmentFactory(); ... Environment environment = environmentFactory.openEnvironment(); try { ... everything available in this block ... } finally { environment.close(); }
The first purpose of the environment is to separate the application from the environment. Standard Java and Enterprise Java are quite different and an environment abstraction like this allows for the development of applications that can run in both Standard and Enterprise environments. Also test environments are easier to tweak this way.
A second purpose of the environment is to enable specific to global searching of resources. E.g. you could search for an 'adminEmailAddress' in the contexts 'processDefinition-execution', 'processDefinition-definition' and 'application' in the given order. That way, a global adminEmailAddress can be specified in the application context and it can be refined in more specific contexts processDefinition-definition or processDefinition-execution.
To find an object in the environment, a searchOrder can be specified. A search order is an sequence that specifies the order in which the contexts should be searched.
The default search order is the inverse sequence of how the contexts are added to the environment. This is because in general, we can assume that the more recent a context was added, the more specific it is.
Three objects are used so frequently in an environment that they get special treatment:
For these special properties, setters are also available. That is to support programmatic injection into the environment. Alternatively, they can be configured in one of the contexts.
EnvironmentFactory
,
Serialized FormConstructor Summary | |
---|---|
Environment()
|
Method Summary | ||
---|---|---|
abstract void |
addContext(Context context)
|
|
abstract void |
close()
closes the Environment by removing all its contexts. |
|
abstract
|
get(java.lang.Class<T> type)
searches an object based on type. |
|
abstract java.lang.Object |
get(java.lang.String name)
searches a named object in all the contexts in the default search order. |
|
abstract java.lang.Object |
get(java.lang.String name,
java.lang.String[] searchOrder)
searches a named object in all the contexts in the given search order. |
|
abstract java.lang.ClassLoader |
getClassLoader()
|
|
abstract Context |
getContext(java.lang.String contextName)
|
|
static Environment |
getCurrent()
|
|
abstract EnvironmentFactory |
getEnvironmentFactory()
|
|
abstract java.lang.Throwable |
getException()
retrieves the first exception that was reported in this environment block. |
|
abstract Transaction |
getTransaction()
convenience method for finding the Transaction . |
|
abstract java.lang.String |
getUserId()
get the authenticated user id |
|
protected static Environment |
pop()
pops the closing context from the stack of current contexts. |
|
abstract void |
removeContext(java.lang.String contextName)
|
|
abstract void |
setClassLoader(java.lang.ClassLoader classLoader)
|
|
abstract void |
setException(java.lang.Throwable exception)
for clients to indicate that an exception has occurred in this environment block. |
|
abstract void |
setUserId(java.lang.String userId)
set the authenticated user id |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Environment()
Method Detail |
---|
public abstract java.lang.Object get(java.lang.String name)
null
if there is no object with the given name in the environment.public abstract java.lang.Object get(java.lang.String name, java.lang.String[] searchOrder)
searchOrder
- list of contexts names. The object will be searched in these contexts, in the given order.
null
if there is no object with the given name in the specified searchOrder contexts.public abstract <T> T get(java.lang.Class<T> type)
WireContext.get(Class)
public abstract Transaction getTransaction()
Transaction
.
public abstract java.lang.String getUserId()
public abstract void setUserId(java.lang.String userId)
public abstract void setException(java.lang.Throwable exception)
public abstract java.lang.Throwable getException()
public abstract void close()
Context.setEnvironment(Environment)
will be called with a
null value for environment.
public abstract Context getContext(java.lang.String contextName)
public abstract void addContext(Context context)
public abstract void removeContext(java.lang.String contextName)
public abstract EnvironmentFactory getEnvironmentFactory()
public abstract java.lang.ClassLoader getClassLoader()
public abstract void setClassLoader(java.lang.ClassLoader classLoader)
public static Environment getCurrent()
protected static Environment pop()
EnvironmentFactory.push(Environment)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |