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 SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceRemembers to set the value back.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier 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.ThreadLocalinitialValue, remove, set
- 
Constructor Details- 
TryThreadLocalpublic TryThreadLocal()
 
- 
- 
Method Details- 
ofCreates a TryThreadLocal with a fixed initial value.- Parameters:
- initialValue- Initial value
 
- 
ofNonNullCreates 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
 
- 
withInitialCreates 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 class- ThreadLocal<@Nullable T>
 
- 
pushAssigns the value asvaluefor the current thread. Returns aTryThreadLocal.Memowhich, when closed, will assign the value back to the previous value.
- 
restoreToSets the value back to a previous value.
- 
letInPerforms 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.
- 
letInCalls 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.
 
-