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
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRemembers to set the value back. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionget()voidPerforms an action with this ThreadLocal set to a particular value in this thread, and restores the previous value afterward.<R> RCalls 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 asvaluefor the current thread.protected abstract voidSets 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:
getin classThreadLocal<@Nullable T>
-
push
Assigns the value asvaluefor the current thread. Returns aTryThreadLocal.Memowhich, 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
letconstruct, 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
letconstruct, for examplelet val x = 1 in x + 2 end.
-