Class ThreadLocalContext.Snapshot

java.lang.Object
io.fluxzero.sdk.common.ThreadLocalContext.Snapshot
Enclosing class:
ThreadLocalContext

public static final class ThreadLocalContext.Snapshot extends Object
A reusable snapshot of the context that was active when ThreadLocalContext.capture() was called.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns whether this snapshot contains no participating values.
    void
    run(Runnable task)
    Runs a task with this snapshot active and restores the previous context afterwards.
    <T> T
    supply(Supplier<T> task)
    Supplies a value with this snapshot active and restores the previous context afterwards.
    wrap(Runnable task)
    Wraps a task so that this snapshot is active whenever the task runs.
    <T,U> BiConsumer<T,U>
    wrap(BiConsumer<T,U> task)
    Wraps a two-argument consumer, such as a completion callback, with this snapshot.
    <T,R> Function<T,R>
    wrap(Function<T,R> task)
    Wraps a function so that this snapshot is active whenever the function runs.
    <T> Supplier<T>
    wrap(Supplier<T> task)
    Wraps a supplier so that this snapshot is active whenever the supplier runs.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Returns whether this snapshot contains no participating values.
    • run

      public void run(Runnable task)
      Runs a task with this snapshot active and restores the previous context afterwards.
    • supply

      public <T> T supply(Supplier<T> task)
      Supplies a value with this snapshot active and restores the previous context afterwards.
    • wrap

      public Runnable wrap(Runnable task)
      Wraps a task so that this snapshot is active whenever the task runs.
    • wrap

      public <T> Supplier<T> wrap(Supplier<T> task)
      Wraps a supplier so that this snapshot is active whenever the supplier runs.
    • wrap

      public <T,U> BiConsumer<T,U> wrap(BiConsumer<T,U> task)
      Wraps a two-argument consumer, such as a completion callback, with this snapshot.
    • wrap

      public <T,R> Function<T,R> wrap(Function<T,R> task)
      Wraps a function so that this snapshot is active whenever the function runs.