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.
  • Field Details

    • CONTEXT_PROPAGATOR_LIST_SHOULD_BE_NON_NULL

      static final String CONTEXT_PROPAGATOR_LIST_SHOULD_BE_NON_NULL
      See Also:
  • Method Details

    • retrieve

      Supplier<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

      Consumer<Optional<T>> copy()
      Copies value from the parent thread into new executing thread. This method is passed with the values received from method retrieve() in the parent thread.
      Returns:
      a Consumer to set values in new thread.
    • clear

      Consumer<Optional<T>> clear()
      CleanUp value before thread execution finish. This method is passed with the values received from method retrieve() in the parent thread.
      Returns:
      a Consumer to cleanUp values.
    • decorateSupplier

      static <T> Supplier<T> decorateSupplier(ContextPropagator propagator, 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 of ContextPropagator
      supplier - 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 of ContextPropagator should be non null.
      supplier - the supplier to be decorated
      Returns:
      decorated supplier of type T
    • decorateCallable

      static <T> Callable<T> decorateCallable(ContextPropagator propagator, 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 of ContextPropagator
      callable - 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 of ContextPropagator should 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 of ContextPropagator
      runnable - the runnable to be decorated
      Returns:
      decorated supplier of type T
    • decorateRunnable

      static <T> Runnable decorateRunnable(ContextPropagator propagator, 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 of ContextPropagator
      runnable - 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