Package pl.morgwai.base.guice.scopes
Class TrackableContext<CtxT extends TrackableContext<CtxT>>
- java.lang.Object
-
- pl.morgwai.base.guice.scopes.InjectionContext
-
- pl.morgwai.base.guice.scopes.TrackableContext<CtxT>
-
public abstract class TrackableContext<CtxT extends TrackableContext<CtxT>> extends InjectionContext
AnInjectionContext
that canexecute tasks within itself
, so that it can be tracked across threads using the associatedContextTracker
.Overriding classes must use themselves as
CtxT
type argument.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
TrackableContext(ContextTracker<CtxT> tracker)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
executeWithinAll(List<TrackableContext<?>> contexts, Runnable task)
Executestask
on the current thread within allcontexts
.static <T> T
executeWithinAll(List<TrackableContext<?>> contexts, Callable<T> task)
Executestask
on the current thread within allcontexts
.void
executeWithinSelf(Runnable task)
Sets itself as the current context for the current thread and executestask
synchronously.<T> T
executeWithinSelf(Callable<T> task)
Sets itself as the current context for the current thread and executestask
synchronously.-
Methods inherited from class pl.morgwai.base.guice.scopes.InjectionContext
provideIfAbsent, removeScopedObject
-
-
-
-
Constructor Detail
-
TrackableContext
protected TrackableContext(ContextTracker<CtxT> tracker)
-
-
Method Detail
-
executeWithinSelf
public void executeWithinSelf(Runnable task)
Sets itself as the current context for the current thread and executestask
synchronously. Afterwards clears the current context.- See Also:
executeWithinAll(List, Runnable)
-
executeWithinSelf
public <T> T executeWithinSelf(Callable<T> task) throws Exception
Sets itself as the current context for the current thread and executestask
synchronously. Afterwards clears the current context.- Throws:
Exception
- See Also:
executeWithinAll(List, Callable)
-
executeWithinAll
public static void executeWithinAll(List<TrackableContext<?>> contexts, Runnable task)
Executestask
on the current thread within allcontexts
. Used to transfer active contexts after a switch to another thread.- See Also:
ContextTracker.getActiveContexts(List)
-
executeWithinAll
public static <T> T executeWithinAll(List<TrackableContext<?>> contexts, Callable<T> task) throws Exception
Executestask
on the current thread within allcontexts
. Used to transfer active contexts after a switch to another thread.- Throws:
Exception
- See Also:
ContextTracker.getActiveContexts(List)
-
-