Interface ContextReference<C>

Type Parameters:
C - the context type
All Superinterfaces:
Consumer<C>, Function<C,C>, Supplier<C>, UnaryOperator<C>
All Known Implementing Classes:
ThreadContextClassLoaderReference, ThreadContextReference

public interface ContextReference<C> extends Supplier<C>, Consumer<C>, UnaryOperator<C>
Reference to some context.
Author:
Paul Ferraro
  • Method Details

    • fromThreadLocal

      static <C> ContextReference<C> fromThreadLocal(ThreadLocal<C> threadLocal)
      Creates a context reference from the specified ThreadLocal.
      Type Parameters:
      C - the context type
      Parameters:
      threadLocal - a thread local used to store the context
      Returns:
      a context reference using the specified ThreadLocal.
    • of

      static <C> ContextReference<C> of(AtomicReference<C> reference)
      Creates a context reference from the specified AtomicReference.
      Type Parameters:
      C - the context type
      Parameters:
      reference - an atomic reference used to store the context
      Returns:
      a context reference using the specified AtomicReference.
    • apply

      default C apply(C context)
      Specified by:
      apply in interface Function<C,C>
    • provide

      default Supplier<Context<C>> provide(C target)
      Returns a context provider for the specified value.
      Parameters:
      target - the target context
      Returns:
      a context provider