Interface PerThreadValue<T>


public interface PerThreadValue<T>
Provides access to per-thread (and, by extension, per-request) data, managed by the PerthreadManager. A PerThreadValue stores a particular type of information.
Since:
5.2.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default T
    compute(Function<? super T,? extends T> fn)
    Computes a new value with the help of the current one, which is returned.
    default T
    computeIfAbsent(Supplier<? extends T> fn)
    If no value is currently stored (checked by exists()), the value provided by the supplier function is set and return.
    default T
    computeIfPresent(Function<? super T,? extends T> fn)
    If a value is currently stored (checked by exists()), this value is used to compute a new one with the given mapping function.
    boolean
    Is a value stored (even null)?
    get()
    Reads the current per-thread value, or returns null if no value has been stored.
    get(T defaultValue)
    Gets the current per-thread value if it exists (even if null), or the defaultValue if no value has been stored.
    default void
    ifSet(Consumer<? super T> action)
    If a value is set, performs the given action with it, otherwise it does nothing.
    set(T newValue)
    Sets the current per-thread value, then returns that value.
  • Method Details

    • exists

      boolean exists()
      Is a value stored (even null)?
    • get

      T get()
      Reads the current per-thread value, or returns null if no value has been stored.
    • get

      T get(T defaultValue)
      Gets the current per-thread value if it exists (even if null), or the defaultValue if no value has been stored.
    • set

      T set(T newValue)
      Sets the current per-thread value, then returns that value.
    • computeIfAbsent

      default T computeIfAbsent(Supplier<? extends T> fn)
      If no value is currently stored (checked by exists()), the value provided by the supplier function is set and return. Otherwise, the current value is returned.
      Parameters:
      fn - the value supplier function
      Returns:
      The current (existing or computed) value
      Throws:
      NullPointerException - if the supplier function is null
      Since:
      5.8.3
    • computeIfPresent

      default T computeIfPresent(Function<? super T,? extends T> fn)
      If a value is currently stored (checked by exists()), this value is used to compute a new one with the given mapping function. Otherwise, null is returned.
      Parameters:
      fn - the mapping function to compute the new value
      Returns:
      The new computed value, or null if none was present
      Throws:
      NullPointerException - if the mapping function is null
      Since:
      5.8.3
    • compute

      default T compute(Function<? super T,? extends T> fn)
      Computes a new value with the help of the current one, which is returned.
      Parameters:
      fn - the mapping function to compute the new value
      Returns:
      The new computed value
      Throws:
      NullPointerException - if the mapping function is null
      Since:
      5.8.3
    • ifSet

      default void ifSet(Consumer<? super T> action)
      If a value is set, performs the given action with it, otherwise it does nothing.
      Parameters:
      action - performed action if a value is set
      Throws:
      NullPointerException - if the action is null
      Since:
      5.8.3