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 TypeMethodDescriptiondefault T
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 byexists()
), 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 byexists()
), this value is used to compute a new one with the given mapping function.boolean
exists()
Is a value stored (even null)?get()
Reads the current per-thread value, or returns null if no value has been stored.Gets the current per-thread value if it exists (even if null), or the defaultValue if no value has been stored.default void
If a value is set, performs the given action with it, otherwise it does nothing.Sets the current per-thread value, then returns that value.
-
Method Details
-
exists
boolean exists()Is a value stored (even null)? -
get
Reads the current per-thread value, or returns null if no value has been stored. -
get
Gets the current per-thread value if it exists (even if null), or the defaultValue if no value has been stored. -
set
Sets the current per-thread value, then returns that value. -
computeIfAbsent
If no value is currently stored (checked byexists()
), 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
If a value is currently stored (checked byexists()
), 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
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
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
-