Package com.suncode.pwfl.core.context
Class ContextHolder<T extends Context>
java.lang.Object
com.suncode.pwfl.core.context.ContextHolder<T>
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 Summary
ConstructorsConstructorDescriptionContextHolder
(String contextName) ContextHolder
(String contextName, boolean single) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Activates given context and puts it on top of stack.void
Activates given context and puts it on top of stack and automatically removes it after invoking provided action.<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.current()
Returns current context from top of stack.boolean
isActive()
Returns true if there is at least 1 context on stack.remove()
Removes and returns current context.
-
Constructor Details
-
ContextHolder
-
ContextHolder
-
-
Method Details
-
isActive
public boolean isActive()Returns true if there is at least 1 context on stack. -
current
Returns current context from top of stack.- Returns:
- current context
- Throws:
ContextNotActiveException
-
activate
Activates given context and puts it on top of stack.- Parameters:
newContext
- new context
-
activate
Activates given context and puts it on top of stack and automatically removes it after invoking provided action.- Parameters:
newContext
- new contextaction
- action
-
activateReturning
Activates given context and puts it on top of stack and automatically removes it after invoking provided action.- Parameters:
newContext
- new contextaction
- action
-
remove
Removes and returns current context.- Returns:
- current context
- Throws:
ContextNotActiveException
-