|
J avolution v3.7 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavolution.realtime.Context
public abstract class Context
This class represents a real-time context; they are typically thread-local but they can also be associated to particular objects.
This package provides few predefined contexts:
LocalContext - To define locally
scoped setting held by LocalReferencePoolContext - To transparently reuse objects created using
an ObjectFactory instead of a constructor.ConcurrentContext - To take advantage of concurrent
algorithms on multi-processors systems.LogContext - For thread-based or object-based logging
capability.
Note: java.util.logging provides class-based
logging (based upon class hierarchy). The scope of a Context should be surrounded by a try,
finally block statement to ensure correct behavior in case
of exceptions being raised. For example:
LocalContext.enter();
try
Length.showAs(Unit.FOOT); // Thread-Local setting (no impact on other threads)
...
} finally {
LocalContext.exit();
}
public class Calculator {
private PoolContext _pool = new PoolContext();
public void execute(Runnable logic) {
PoolContext.enter(_pool);
try {
logic.run(); // Executes the logic using this calculator pool.
} finally {
PoolContext.exit(_pool); // Recycles used objects all at once.
}
}
}
Finally, context instances can be serialized/deserialized in
xml format. For example,
applications may want to load pool contexts at start-up to limit
the number of object creation at run-time (and therefore reducing
the worst-case execution time).
| Constructor Summary | |
|---|---|
protected |
Context()
Default constructor. |
| Method Summary | |
|---|---|
void |
clear()
Clears this context and releases any associated resource. |
static Context |
current()
Returns the current context for the current thread. |
protected static Context |
enter(java.lang.Class contextClass)
Enters a context of specified class. |
static void |
enter(Context context)
Enters the specified context. |
protected abstract void |
enterAction()
The action to be performed after this context becomes the current context. |
protected static Context |
exit(java.lang.Class contextClass)
Exits the current context which must be of specified type. |
static void |
exit(Context context)
Exits the specified context. |
protected abstract void |
exitAction()
The action to be performed before this context is no more the current context. |
Context |
getOuter()
Holds the outer context of this context or null
if none (root context). |
java.lang.Thread |
getOwner()
Returns the current owner of this 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 |
|---|
public static Context current()
HeapContext for normal threads and a PoolContext
for concurrent threads.
null).public final java.lang.Thread getOwner()
public final Context getOuter()
null
if none (root context).
null if none (root context).public void clear()
protected abstract void enterAction()
protected abstract void exitAction()
public static void enter(Context context)
context - the context being entered.
java.lang.IllegalStateException - if this context is currently in use.public static void exit(Context context)
outer context
becomes the current context.
context - the context being entered.
java.lang.IllegalStateException - if this context is not the current context.protected static Context enter(java.lang.Class contextClass)
contextClass - the type of context to be entered.
protected static Context exit(java.lang.Class contextClass)
contextClass - the type of context to be exited.
java.lang.IllegalStateException - if the current context
is not an instance of the specified class.
|
J avolution v3.7 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||