Package io.github.resilience4j.core
Interface ContextPropagator<T>
- Type Parameters:
T- value type that is copied across thread boundary.
- All Known Implementing Classes:
ContextPropagator.EmptyContextPropagator
public interface ContextPropagator<T>
Abstraction to retrieve, copy and clean up values across thread boundary. This class is
specifically use for propagating
ThreadLocal across different thread boundaries.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classA convenient implementation of emptyContextPropagator -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionclear()CleanUp value before thread execution finish.copy()Copies value from the parent thread into new executing thread.static <T> Callable<T>decorateCallable(ContextPropagator propagator, Callable<T> callable) Method decorates callable to copy variables across thread boundary.static <T> Callable<T>decorateCallable(List<? extends ContextPropagator> propagators, Callable<T> callable) Method decorates callable to copy variables across thread boundary.static <T> RunnabledecorateRunnable(ContextPropagator propagator, Runnable runnable) Method decorates runnable to copy variables across thread boundary.static <T> RunnabledecorateRunnable(List<? extends ContextPropagator> propagators, Runnable runnable) Method decorates runnable to copy variables across thread boundary.static <T> Supplier<T>decorateSupplier(ContextPropagator propagator, Supplier<T> supplier) Method decorates supplier to copy variables across thread boundary.static <T> Supplier<T>decorateSupplier(List<? extends ContextPropagator> propagators, Supplier<T> supplier) Method decorates supplier to copy variables across thread boundary.static <T> ContextPropagator<T>empty()An empty context propagator.retrieve()Retrieves value from the currently executing thread.
-
Field Details
-
CONTEXT_PROPAGATOR_LIST_SHOULD_BE_NON_NULL
- See Also:
-
-
Method Details
-
retrieve
Retrieves value from the currently executing thread. This method should produce values (as Supplier) that needs to be propagated to new thread.- Returns:
- a Supplier producing the value from current thread
-
copy
Copies value from the parent thread into new executing thread. This method is passed with the values received from methodretrieve()in the parent thread.- Returns:
- a Consumer to set values in new thread.
-
clear
CleanUp value before thread execution finish. This method is passed with the values received from methodretrieve()in the parent thread.- Returns:
- a Consumer to cleanUp values.
-
decorateSupplier
Method decorates supplier to copy variables across thread boundary.- Type Parameters:
T- the type of variable that cross thread boundary- Parameters:
propagator- the instance ofContextPropagatorsupplier- the supplier to be decorated- Returns:
- decorated supplier of type T
-
decorateSupplier
static <T> Supplier<T> decorateSupplier(List<? extends ContextPropagator> propagators, Supplier<T> supplier) Method decorates supplier to copy variables across thread boundary.- Type Parameters:
T- the type of variable that cross thread boundary- Parameters:
propagators- the instance ofContextPropagatorshould be non null.supplier- the supplier to be decorated- Returns:
- decorated supplier of type T
-
decorateCallable
Method decorates callable to copy variables across thread boundary.- Type Parameters:
T- the type of variable that cross thread boundary- Parameters:
propagator- the instance ofContextPropagatorcallable- the callable to be decorated- Returns:
- decorated callable of type T
-
decorateCallable
static <T> Callable<T> decorateCallable(List<? extends ContextPropagator> propagators, Callable<T> callable) Method decorates callable to copy variables across thread boundary.- Type Parameters:
T- the type of variable that cross thread boundary- Parameters:
propagators- the instance ofContextPropagatorshould be non null.callable- the callable to be decorated- Returns:
- decorated callable of type T
-
decorateRunnable
static <T> Runnable decorateRunnable(List<? extends ContextPropagator> propagators, Runnable runnable) Method decorates runnable to copy variables across thread boundary.- Type Parameters:
T- the type of variable that cross thread boundary- Parameters:
propagators- the instance ofContextPropagatorrunnable- the runnable to be decorated- Returns:
- decorated supplier of type T
-
decorateRunnable
Method decorates runnable to copy variables across thread boundary.- Type Parameters:
T- the type of variable that cross thread boundary- Parameters:
propagator- the instance ofContextPropagatorrunnable- the runnable to be decorated- Returns:
- decorated supplier of type T
-
empty
An empty context propagator.- Type Parameters:
T- type.- Returns:
- an empty
ContextPropagator
-