Top Description Methods
io.micrometer.context

public Interface ThreadLocalAccessor<V>

Imports
java.util.function.Consumer, .Supplier

Contract to assist with setting and clearing a ThreadLocal.
Authors
Rossen Stoyanchev, Marcin Grzejszczak, Dariusz Jędrzejczyk
Since
1.0.0
See Also
ContextRegistry#registerThreadLocalAccessor(ThreadLocalAccessor), ContextRegistry#registerThreadLocalAccessor(String, Supplier, Consumer, Runnable)

Method Summary

Modifier and TypeMethod and Description
public V
getValue()

Return the current ThreadLocal value.

public Object
key()

The key to associate with the ThreadLocal value when saved within a ContextSnapshot.

public default void
reset()

Deprecated To be replaced by calls to setValue() (and/or restore()), which needs to be implemented when this implementation is removed.
Remove the ThreadLocal value when setting ThreadLocal values in case of missing mapping for a key() from a ContextSnapshot, or a Context object (operated upon by ContextAccessor).
public default void
restore(V
previous value to set, never null when called from a ContextSnapshot * implementation, which is not allowed to store mappings to null.
previousValue
)

Restore the ThreadLocal at the end of a io.

public default void
restore()

Called instead of restore(Object) when there was no ThreadLocal value existing at the start of the scope.

public void
setValue(V
the value to set, never null when called from a ContextSnapshot implementation, which is not allowed to store mappings to null.
value
)

Set the ThreadLocal at the start of a io.

public default void
setValue()

Called instead of setValue(Object) in order to remove the current ThreadLocal value at the start of a io.

Method Detail

getValueback to summary
public V getValue()

Return the current ThreadLocal value.

This method is called in two scenarios:

Annotations
@Nullable
keyback to summary
public Object key()

The key to associate with the ThreadLocal value when saved within a ContextSnapshot.

resetback to summary
public default void reset()

Deprecated

To be replaced by calls to setValue() (and/or restore()), which needs to be implemented when this implementation is removed.

Remove the ThreadLocal value when setting ThreadLocal values in case of missing mapping for a key() from a ContextSnapshot, or a Context object (operated upon by ContextAccessor).

Annotations
@Deprecated
restoreback to summary
public default void restore(V previousValue)

Restore the ThreadLocal at the end of a io.micrometer.context.ContextSnapshot.Scope to the previous value it had before the start of the scope.

Parameters
previousValue:V

previous value to set, never null when called from a ContextSnapshot * implementation, which is not allowed to store mappings to null.

Since
1.0.1
restoreback to summary
public default void restore()

Called instead of restore(Object) when there was no ThreadLocal value existing at the start of the scope.

Since
1.0.3
See Also
getValue()
setValueback to summary
public void setValue(V value)

Set the ThreadLocal at the start of a io.micrometer.context.ContextSnapshot.Scope to a value obtained from a ContextSnapshot or from a different type of context (through a ContextAccessor).

Parameters
value:V

the value to set, never null when called from a ContextSnapshot implementation, which is not allowed to store mappings to null.

setValueback to summary
public default void setValue()

Called instead of setValue(Object) in order to remove the current ThreadLocal value at the start of a io.micrometer.context.ContextSnapshot.Scope.

Since
1.0.3