T
- the value typepublic interface RequestLocal<T>
RequestContext
, if one is active. Conceptually similar to a
ThreadLocal
, but tied to the current RequestContext
instead of the current thread.
Note that the request context can be propagated to background threads such as event listener threads and repository
hook handler threads. As a result, the object stored in a RequestLocal
could be accessed from different
threads and care should be taken to ensure the stored object is thread safe when interacting with it from multiple
threads (e.g. the request thread, an asynchronous event listener and/or a repository hook).
Modifier and Type | Method and Description |
---|---|
T |
compute(Function<? super T,? extends T> mappingFunction)
Attempts to compute the value given the current value.
|
T |
computeIfAbsent(Supplier<? extends T> missingValueSupplier)
Returns the value, if present.
|
T |
get() |
void |
ifPresent(Consumer<? super T> consumer)
If a value is present, invoke the specified consumer with the value, otherwise do nothing.
|
boolean |
isActive() |
boolean |
isPresent() |
T |
remove()
Removes the value from the current
RequestContext , if present. |
T |
removeIf(Predicate<? super T> predicate)
Removes the value from the current
RequestContext , if a non-null value is present and the
predicate matches the value. |
boolean |
set(T value)
Sets the value.
|
T compute(@Nonnull Function<? super T,? extends T> mappingFunction)
mappingFunction
is
stored as the value for current RequestContext
.
If there is no current RequestContext
, the mappingFunction
is still invoked but the computed
value is not stored.
mappingFunction
- function that computes the value given the current value which may be null
if
no value is present.T computeIfAbsent(@Nonnull Supplier<? extends T> missingValueSupplier)
RequestContext
is active, but no value is set, the value supplied
by the missingValueSupplier
is stored and returned.
If no RequestContext
is active, missingValueSupplier
is still invoked, but the computed value
is not stored.
missingValueSupplier
- supplier of the value whenmissingValueSupplier
@Nullable T get()
null
if not set or no RequestContext
is activevoid ifPresent(@Nonnull Consumer<? super T> consumer)
consumer
- block to be executed if a value is presentboolean isActive()
true
is a RequestContext
is currently active, otherwise false
boolean isPresent()
true
when a value other than null
is defined in the current RequestContext
.@Nullable T remove()
RequestContext
, if present.null
@Nullable T removeIf(@Nonnull Predicate<? super T> predicate)
RequestContext
, if a non-null value is present and the
predicate
matches the value. If no value is present, the predicate will not be called. The Predicate
will never be called with a null
value.predicate
- the predicatenull
boolean set(@Nullable T value)
null
value is equivalent to calling remove()
.value
- the valuetrue
if the value was set, or false
if no RequestContext
is activeCopyright © 2022 Atlassian. All rights reserved.