|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.dautelle.realtime.Context
This class represents a real-time context (thread-based).
Applications do not have direct access to instances of this class.
Context
methods are always static and typically affect
the first outer context of appropriate type (as defined by the method's
class). In some cases (e.g. LogContext
below), context
static methods may affect more than one context instance.
The scope of a Context
is defined by a try, finally
block statement which starts with a static enter
call and
ends with a static exit
call. For example:
LocalContext.enter(); try { // Current thread executes in a local context. ... } finally { LocalContext.exit(); }The class of the enter/exit methods identifies the context type.
Context can be nested, they inherit the setting/behaviors of their outer contexts (unless these setting/behaviors are mutually exclusive).
Context-aware applications may extend this base class to address system-wide concerns, such as logging, security, performance, and so forth. For example:
public class LogContext extends Context { public static enter(Logger logger) { ... } public static void log(String msg) { ... } public static void exit() { ... } ... } ... LogContext.enter(logger_A); try { foo(); // Logs foo with logger_A LogContext.enter(logger_B); try { foo(); // Logs foo with logger_A and logger_B } finally { LogContext.exit(); } } finally ( LogContext.exit(); } ... void foo() { LogContext.log("blah, blah, blah"); }
Note: JADE context programming is somewhat complementary to aspect-oriented programming. Whereas context programming is dynamic by nature (thread based); AOP is typically code based (ref. AspectJ tool/compiler). Both can be used in conjunction to insert custom context code automatically.
Constructor Summary | |
protected |
Context()
Default constructor. |
Method Summary | |
protected static Context |
current()
Returns the current context for the current thread. |
protected Context |
getInner()
Returns the last inner context used by the owner of this context. |
protected Context |
getOuter()
Holds the outer context of this Context or null
if none (root context). |
protected java.lang.Thread |
getOwner()
Returns the thread owner of this Context . |
protected static Context |
pop()
Pops the current context from the context stack. |
protected static Context |
push(java.lang.Class contextClass)
Pushes a context of specified type as the current context. |
protected static void |
push(Context ctx)
Pushes the specified context as the current context. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected Context()
Method Detail |
protected static Context current()
HeapContext
for normal threads and a PoolContext
for concurrent threads
.
null
).protected final java.lang.Thread getOwner()
Context
. The owner of a
context is the thread which entered the context.
The owner of the current
context is always the
current thread but the owner of the current outer context might
be another thread due to concurrency.
protected final Context getOuter()
Context
or null
if none (root context).
null
if none (root context).protected final Context getInner()
null
if none (deepest context).protected static Context push(java.lang.Class contextClass)
contextClass
- the class of the context to be pushed.
null
if none found.protected static void push(Context ctx)
getOuter()
of the specified context.
ctx
- the new current context.protected static Context pop()
getOuter()
of the current context becomes the current context.
current()
context.
java.util.EmptyStackException
- if the current thread is not the owner
of the current context.getOwner()
|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |