Package org.apache.calcite.util
Class TryThreadLocal<T>
java.lang.Object
java.lang.ThreadLocal<@Nullable T>
org.apache.calcite.util.TryThreadLocal<T>
- Type Parameters:
T
- Value type
Thread-local variable that returns a handle that can be closed.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Remembers to set the value back. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionget()
void
Performs an action with this ThreadLocal set to a particular value in this thread, and restores the previous value afterward.<R> R
Calls a Supplier with this ThreadLocal set to a particular value, in this thread, and restores the previous value afterward.static <S> TryThreadLocal<S>
of
(S initialValue) Creates a TryThreadLocal with a fixed initial value.static <S> TryThreadLocal<@NonNull S>
ofNonNull
(S initialValue) Creates a TryThreadLocal with a fixed initial value whose values are never null.Assigns the value asvalue
for the current thread.protected abstract void
Sets the value back to a previous value.static <S> TryThreadLocal<@NonNull S>
withInitial
(Supplier<? extends @NonNull S> supplier) Creates a TryThreadLocal with a supplier for the initial value.Methods inherited from class java.lang.ThreadLocal
initialValue, remove, set
-
Constructor Details
-
TryThreadLocal
public TryThreadLocal()
-
-
Method Details
-
of
Creates a TryThreadLocal with a fixed initial value.- Parameters:
initialValue
- Initial value
-
ofNonNull
Creates a TryThreadLocal with a fixed initial value whose values are never null.The value returned from
get()
is never null; the initial value must not be null; you must not callThreadLocal.set(Object)
with a null value.- Parameters:
initialValue
- Initial value
-
withInitial
Creates a TryThreadLocal with a supplier for the initial value.The value returned from
get()
is never null; the supplier must never return null; you must not callThreadLocal.set(Object)
with a null value.- Parameters:
supplier
- Supplier
-
get
- Overrides:
get
in classThreadLocal<@Nullable T>
-
push
Assigns the value asvalue
for the current thread. Returns aTryThreadLocal.Memo
which, when closed, will assign the value back to the previous value. -
restoreTo
Sets the value back to a previous value. -
letIn
Performs an action with this ThreadLocal set to a particular value in this thread, and restores the previous value afterward.This method is named after the Standard ML
let
construct, for examplelet val x = 1 in x + 2 end
. -
letIn
Calls a Supplier with this ThreadLocal set to a particular value, in this thread, and restores the previous value afterward.This method is named after the Standard ML
let
construct, for examplelet val x = 1 in x + 2 end
.
-