|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.objectledge.context.Context
public class Context
Context gives the application an ability to reference arbitrary objects using String names.
The bindings are local to the calling thread. This is a convenient way of passing data associated with a stream of processing without putting them into method attributes. This is especialy convenient with data that are not needed at a specific stage of processing, but may be needed by the nested stages - for example security credentials.
Note!It is important to clear the context before the thread departs from within application boundaries - otherwise the references may prevent the objects (and as a result large graphs of objects including classes and classloaders) from being garbage collected, while being otherwise being eligible to collection.
| Field Summary | |
|---|---|
private static ThreadLocal |
threadAttributes
storage of the context attributes, specific to a thread. |
| Constructor Summary | |
|---|---|
Context()
|
|
| Method Summary | ||
|---|---|---|
void |
clearAttributes()
Removes all context attributes. |
|
|
getAttribute(Class<T> key)
Return the value of a context attribute. |
|
Object |
getAttribute(String name)
Return the value of a context attribute. |
|
private Map |
getAttributes()
|
|
Object |
removeAttribute(Class key)
Removes a context attribute. |
|
Object |
removeAttribute(String name)
Removes a context attribute. |
|
Object |
setAttribute(Class key,
Object value)
Sets a new value of a context attribute. |
|
Object |
setAttribute(String name,
Object value)
Sets a new value of a context attribute. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static ThreadLocal threadAttributes
| Constructor Detail |
|---|
public Context()
| Method Detail |
|---|
public Object getAttribute(String name)
name - the attribute name.
public <T> T getAttribute(Class<T> key)
Class object and the class name String are considered to be equivalent keys.
T - the type reflected by key Class object, to avoid casting on the caller's side.key - a Class key of the attribute.
public Object setAttribute(String name,
Object value)
name - the name of the attribute.value - the new value of the attribute.
public Object setAttribute(Class key,
Object value)
Class object and the class name String are considered to be equivalent keys.
key - Class key of the attribute.value - the new value of the attribute.
public Object removeAttribute(String name)
name - the name of the attribute.
public Object removeAttribute(Class key)
Class object and the class name String are considered to be equivalent keys.
key - Class key of the attribute.
public void clearAttributes()
private Map getAttributes()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||