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 propagatingThreadLocalacross different thread boundaries.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classContextPropagator.EmptyContextPropagator<T>A convenient implementation of emptyContextPropagator
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.function.Consumer<java.util.Optional<T>>clear()CleanUp value before thread execution finish.java.util.function.Consumer<java.util.Optional<T>>copy()Copies value from the parent thread into new executing thread.static <T> java.util.concurrent.Callable<T>decorateCallable(ContextPropagator propagator, java.util.concurrent.Callable<T> callable)Method decorates callable to copy variables across thread boundary.static <T> java.util.concurrent.Callable<T>decorateCallable(java.util.List<? extends ContextPropagator> propagators, java.util.concurrent.Callable<T> callable)Method decorates callable to copy variables across thread boundary.static <T> java.lang.RunnabledecorateRunnable(ContextPropagator propagator, java.lang.Runnable runnable)Method decorates runnable to copy variables across thread boundary.static <T> java.lang.RunnabledecorateRunnable(java.util.List<? extends ContextPropagator> propagators, java.lang.Runnable runnable)Method decorates runnable to copy variables across thread boundary.static <T> java.util.function.Supplier<T>decorateSupplier(ContextPropagator propagator, java.util.function.Supplier<T> supplier)Method decorates supplier to copy variables across thread boundary.static <T> java.util.function.Supplier<T>decorateSupplier(java.util.List<? extends ContextPropagator> propagators, java.util.function.Supplier<T> supplier)Method decorates supplier to copy variables across thread boundary.static <T> ContextPropagator<T>empty()An empty context propagator.java.util.function.Supplier<java.util.Optional<T>>retrieve()Retrieves value from the currently executing thread.
-
-
-
Method Detail
-
retrieve
java.util.function.Supplier<java.util.Optional<T>> 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
java.util.function.Consumer<java.util.Optional<T>> 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
java.util.function.Consumer<java.util.Optional<T>> 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
static <T> java.util.function.Supplier<T> decorateSupplier(ContextPropagator propagator, java.util.function.Supplier<T> supplier)
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> java.util.function.Supplier<T> decorateSupplier(java.util.List<? extends ContextPropagator> propagators, java.util.function.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
static <T> java.util.concurrent.Callable<T> decorateCallable(ContextPropagator propagator, java.util.concurrent.Callable<T> callable)
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> java.util.concurrent.Callable<T> decorateCallable(java.util.List<? extends ContextPropagator> propagators, java.util.concurrent.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> java.lang.Runnable decorateRunnable(java.util.List<? extends ContextPropagator> propagators, java.lang.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
static <T> java.lang.Runnable decorateRunnable(ContextPropagator propagator, java.lang.Runnable runnable)
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
static <T> ContextPropagator<T> empty()
An empty context propagator.- Type Parameters:
T- type.- Returns:
- an empty
ContextPropagator
-
-