public interface ContextLocal<T>
Provide access to context local bag. E.g JDKThreadLocal
Modifier and Type | Interface and Description |
---|---|
static interface |
ContextLocal.Factory |
static class |
ContextLocal.InitialValueProvider<T> |
Modifier and Type | Field and Description |
---|---|
static String |
CONF_CONTEXT_LOCAL_FACTORY |
Modifier and Type | Method and Description |
---|---|
T |
get()
Returns the value in the current context’s copy of this context-local variable.
|
T |
initialValue()
Returns the current context’s “initial value” for this context-local variable.
|
void |
remove()
Removes the current context’s value for this context-local variable.
|
void |
set(T value)
Sets the current context’s copy of this context-local variable to the specified value.
|
static final String CONF_CONTEXT_LOCAL_FACTORY
T get()
Returns the value in the current context’s copy of this context-local variable. If the variable has no value for the current context, it is first initialized to the value returned by an invocation of the initialValue()
method.
void set(T value)
Sets the current context’s copy of this context-local variable to the specified value. Most subclasses will have no need to override this method, relying solely on the initialValue()
method to set the values of context-locals.
value
- the value to be stored in the current context’s copy of this context-local.void remove()
Removes the current context’s value for this context-local variable. If this context-local variable is subsequently read by the current thread, its value will be reinitialized by invoking its initialValue()
method, unless its value is set by the current context in the interim. This may result in multiple invocations of the initialValue method in the current context.
T initialValue()
Returns the current context’s “initial value” for this context-local variable. This method will be invoked the first time a context accesses the variable with the get()
method, unless the context previously invoked the set(T)
method, in which case the initialValue method will not be invoked for the context. Normally, this method is invoked at most once per context, but it may be invoked again in case of subsequent invocations of remove()
followed by get()
.
Copyright © 2014–2018 OSGL (Open Source General Library). All rights reserved.