Module org.elasticsearch.server
Class ThreadContextTransient<T>
java.lang.Object
org.elasticsearch.common.util.concurrent.ThreadContextTransient<T>
A utility class for resolving/setting values in the
ThreadContext in a typesafe way- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanexists(ThreadContext threadContext) get(ThreadContext threadContext) getKey()require(ThreadContext threadContext) voidset(ThreadContext threadContext, T value) Set the value for the thiskey.booleansetIfEmpty(ThreadContext threadContext, T value) Set the value for the thiskey, if and only if there is no current valuestatic <T> ThreadContextTransient<T> transientValue(String key, Class<T> type)
-
Method Details
-
getKey
- Returns:
- The key/name of the transient header
-
exists
- Returns:
trueif the thread context contains a non-null value for thiskey
-
get
- Returns:
- The current value for this
key. May benull.
-
require
- Returns:
- The current value for this
key. May not benull - Throws:
IllegalStateException- if the thread context does not contain a value (or containsnull).
-
set
Set the value for the thiskey. Because transient headers cannot be overwritten, this method will throw an exception if a value already exists- See Also:
-
setIfEmpty
Set the value for the thiskey, if and only if there is no current value- Returns:
trueif the value was set,falseotherwise
-
transientValue
-