Package it.tidalwave.role.spi
Class ContextSampler
- java.lang.Object
-
- it.tidalwave.role.spi.ContextSampler
-
public class ContextSampler extends java.lang.ObjectA facility that samples the contexts that are current at creation time and make them available later.- Author:
- Fabrizio Giudici
-
-
Constructor Summary
Constructors Constructor Description ContextSampler(java.lang.Object owner)Creates a new instance and samples the currently available contexts.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<java.lang.Object>getContexts()Returns the previously sampled contexts.<V,T extends java.lang.Throwable>
VrunWithContexts(Task<V,T> task)Runs aTaskassociated with the sampled contexts.
-
-
-
Method Detail
-
getContexts
@Nonnull public java.util.List<java.lang.Object> getContexts()
Returns the previously sampled contexts.- Returns:
- the contexts
-
runWithContexts
public <V,T extends java.lang.Throwable> V runWithContexts(@Nonnull Task<V,T> task) throws T extends java.lang.ThrowableRuns aTaskassociated with the sampled contexts.- Type Parameters:
V- the type of the result valueT- the type of the exception- Parameters:
task- the task- Returns:
- the value produced by the task
- Throws:
T- the exception(s) thrown by the taskT extends java.lang.Throwable
-
-