Class ContextHolder<T extends Context>

java.lang.Object
com.suncode.pwfl.core.context.ContextHolder<T>

@Api public class ContextHolder<T extends Context> extends Object
Context holder. Stores same type contexts per thread on stack (this allows us to use nested contexts). Any new threads created from within thread with active context, will inherit this context.

Usually used by context implementations that allows static access to context holder.

Author:
Cezary Kozar 14 cze 2016
  • Constructor Details

    • ContextHolder

      public ContextHolder(String contextName)
    • ContextHolder

      public ContextHolder(String contextName, boolean single)
  • Method Details

    • isActive

      public boolean isActive()
      Returns true if there is at least 1 context on stack.
    • current

      public T current() throws ContextNotActiveException
      Returns current context from top of stack.
      Returns:
      current context
      Throws:
      ContextNotActiveException
    • activate

      public void activate(T newContext)
      Activates given context and puts it on top of stack.
      Parameters:
      newContext - new context
    • activate

      public void activate(T newContext, InContext<T> action)
      Activates given context and puts it on top of stack and automatically removes it after invoking provided action.
      Parameters:
      newContext - new context
      action - action
    • activateReturning

      public <R> R activateReturning(T newContext, InContextReturning<T,? extends R> action)
      Activates given context and puts it on top of stack and automatically removes it after invoking provided action.
      Parameters:
      newContext - new context
      action - action
    • remove

      public T remove() throws ContextNotActiveException
      Removes and returns current context.
      Returns:
      current context
      Throws:
      ContextNotActiveException