Package pl.morgwai.base.guice.scopes
Class ContextTracker<ContextT extends TrackableContext<? super ContextT>>
- java.lang.Object
-
- pl.morgwai.base.guice.scopes.ContextTracker<ContextT>
-
public class ContextTracker<ContextT extends TrackableContext<? super ContextT>> extends Object
Allows to track whichThread
is running within whichContext
. AContextTracker
instance is associated with one particular type of contexts represented as a subclass ofTrackableContext
, here denoted asContextT
. For example: aTracker
of whichThread
runs within aContext
of whichHttpServletRequest
.Instances should usually be created at app startup to be in turn used by instances of
ContextScope
s.
-
-
Constructor Summary
Constructors Constructor Description ContextTracker()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static List<TrackableContext<?>>
getActiveContexts(List<ContextTracker<?>> trackers)
Retrieves fromtrackers
allTrackableContext
s active (current within their class) for the callingThread
.ContextT
getCurrentContext()
Returns the currentContext
of typeContextT
.
-
-
-
Method Detail
-
getCurrentContext
public ContextT getCurrentContext()
Returns the currentContext
of typeContextT
. IfContextT
is not currently active for the callingThread
, thennull
.- See Also:
getActiveContexts(List)
-
getActiveContexts
public static List<TrackableContext<?>> getActiveContexts(List<ContextTracker<?>> trackers)
Retrieves fromtrackers
allTrackableContext
s active (current within their class) for the callingThread
. The returnedList
can be then used as an argument toTrackableContext.executeWithinAll(List, Runnable)
to transfer theContexts
when switching to anotherThread
. AllContexts induced
by any of the returnedTrackableContext
s will also "follow" automatically their inducers to the newThread
.Deriving libs should bind
List<ContextTracker<?>>
to an instance containing all possibleContextTracker
s for use as an argument for this method.
-
-