Package com.atlassian.bitbucket.request
Interface RequestLocal<T>
- Type Parameters:
T- the value type
public interface RequestLocal<T>
Value that is resolved in the current
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).
- Since:
- 7.9
-
Method Summary
Modifier and TypeMethodDescriptionAttempts to compute the value given the current value.computeIfAbsent(Supplier<? extends T> missingValueSupplier) Returns the value, if present.get()voidIf a value is present, invoke the specified consumer with the value, otherwise do nothing.booleanisActive()booleanremove()Removes the value from the currentRequestContext, if present.Removes the value from the currentRequestContext, if a non-null value is present and thepredicatematches the value.booleanSets the value.
-
Method Details
-
compute
Attempts to compute the value given the current value. The value returned by themappingFunctionis stored as the value for currentRequestContext.If there is no current
RequestContext, themappingFunctionis still invoked but the computed value is not stored.- Parameters:
mappingFunction- function that computes the value given the current value which may benullif no value is present.- Returns:
- the computed value
-
computeIfAbsent
Returns the value, if present. If anRequestContextis active, but no value is set, the value supplied by themissingValueSupplieris stored and returned.If no
RequestContextis active,missingValueSupplieris still invoked, but the computed value is not stored.- Parameters:
missingValueSupplier- supplier of the value when- Returns:
- the value, possibly supplied by
missingValueSupplier
-
get
- Returns:
- the value, or
nullif not set or noRequestContextis active
-
ifPresent
If a value is present, invoke the specified consumer with the value, otherwise do nothing.- Parameters:
consumer- block to be executed if a value is present
-
isActive
boolean isActive()- Returns:
trueis aRequestContextis currently active, otherwisefalse
-
isPresent
boolean isPresent()- Returns:
truewhen a value other thannullis defined in the currentRequestContext.
-
remove
Removes the value from the currentRequestContext, if present.- Returns:
- the removed value, if the value was removed; otherwise
null
-
removeIf
Removes the value from the currentRequestContext, if a non-null value is present and thepredicatematches the value. If no value is present, the predicate will not be called. The Predicate will never be called with anullvalue.- Parameters:
predicate- the predicate- Returns:
- the removed value, if the value was removed; otherwise
null
-
set
Sets the value. Setting anullvalue is equivalent to callingremove().- Parameters:
value- the value- Returns:
trueif the value was set, orfalseif noRequestContextis active
-