ix.util.context
Class ThreadLocalHoldingStrategy

java.lang.Object
  extended by ix.util.context.ContextHoldingStrategy
      extended by ix.util.context.ThreadLocalHoldingStrategy
Direct Known Subclasses:
InheritableThreadLocalHoldingStrategy

public class ThreadLocalHoldingStrategy
extends ContextHoldingStrategy

A context-holding strategy that associates context-holders with threads. The holder for a thread is created by the initialHolder() method. (In some cases, it may be better to override that method to have it return null, so that the holder must be explicitly set.) More than one thread may be given the same context-holder, however this must be done with care, because some objects that use contexts frequently change their current context, and two threads doing that with the same holder could confuse each other.


Field Summary
protected  java.lang.ThreadLocal<ContextHolder> threadContextHolder
           
 
Constructor Summary
ThreadLocalHoldingStrategy()
           
 
Method Summary
 void clearContexts()
          Clears contexts in the current thread's holder by telling it to set its current context to the root context.
 ContextHolder getContextHolder()
          Returns the ContextHolder for the current thread.
protected  ContextHolder initialHolder()
          Called to create a holder for a thread that doesn't already have one.
 void setContextHolder(ContextHolder h)
          Sets the ContextHolder for the current thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

threadContextHolder

protected java.lang.ThreadLocal<ContextHolder> threadContextHolder
Constructor Detail

ThreadLocalHoldingStrategy

public ThreadLocalHoldingStrategy()
Method Detail

initialHolder

protected ContextHolder initialHolder()
Called to create a holder for a thread that doesn't already have one. Unless overridden in a subclass, this method returns an instance of BasicContextHolder.


getContextHolder

public ContextHolder getContextHolder()
Returns the ContextHolder for the current thread.

Specified by:
getContextHolder in class ContextHoldingStrategy

setContextHolder

public void setContextHolder(ContextHolder h)
Sets the ContextHolder for the current thread.

Overrides:
setContextHolder in class ContextHoldingStrategy

clearContexts

public void clearContexts()
Clears contexts in the current thread's holder by telling it to set its current context to the root context.

Specified by:
clearContexts in class ContextHoldingStrategy