Class ReentrantThreadLocal<T>

java.lang.Object
dev.getelements.elements.sdk.util.ReentrantThreadLocal<T>
Type Parameters:
T -

public class ReentrantThreadLocal<T> extends Object
Backed by a ThreadLocal<T>, this allows for the creation of a thread-local scope which can be entered and exited multiple times, provided that the underlying calls are balanced.
  • Constructor Details

  • Method Details

    • getCurrent

      public T getCurrent()
      Gets the current value throwing an instance of IllegalStateException if there is not a current value.
      Returns:
      the current value.
    • getCurrentOptional

      public Optional<T> getCurrentOptional()
      Returns the current value as an Optional<T>.
      Returns:
      the current value as an Optional<T>.
    • ensureEmpty

      public void ensureEmpty()
      Ensures that the current value is empty, throwing an instance of IllegalStateException if the object is not in scope.
    • enter

      public ReentrantThreadLocal.Scope<T> enter(T t)
      Enters scope with the supplied value of T.
      Parameters:
      t - the value of t
      Returns:
      a ReentrantThreadLocal.Scope which will hold the value until it is closed, reverting it to the previous value.