Top Description Inners Methods
io.micrometer.context

public Interface ContextSnapshotFactory

Known Direct Implementers
io.micrometer.context.DefaultContextSnapshotFactory
Imports
java.util.function.Predicate

Factory for creating ContextSnapshot objects and restoring ThreadLocal values using a context object for which a ContextAccessor exists in the ContextRegistry.
Author
Dariusz Jędrzejczyk
Since
1.0.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Method Summary

Modifier and TypeMethod and Description
public static ContextSnapshotFactory.Builder

Returns:

an instance that provides defaults, that can be configured to provide to the created ContextSnapshotFactory.
builder
()

Creates a builder for configuring the factory.

public ContextSnapshot

Returns:

a snapshot with saved context values
captureAll
(Object...
context objects to extract values from
contexts
)

Capture values from ThreadLocal and from other context objects using all accessors from a ContextRegistry instance.

public ContextSnapshot

Returns:

the created ContextSnapshot
captureFrom
(Object...
the contexts to read values from
contexts
)

Create a ContextSnapshot by reading values from the given context objects.

public <
the type of the target context
C
>
ContextSnapshot.Scope

Returns:

an object that can be used to reset ThreadLocal values at the end of the context scope, either removing them or restoring their previous values, if any.
setThreadLocalsFrom
(Object
the source context to read values from
sourceContext
,
String...
the keys of the values to read. If none provided, all keys are considered.
keys
)

Read the values specified by keys from the given source context, and if found, use them to set ThreadLocal values.

Method Detail

builderback to summary
public static ContextSnapshotFactory.Builder builder()

Creates a builder for configuring the factory.

Returns:ContextSnapshotFactory.Builder

an instance that provides defaults, that can be configured to provide to the created ContextSnapshotFactory.

captureAllback to summary
public ContextSnapshot captureAll(Object... contexts)

Capture values from ThreadLocal and from other context objects using all accessors from a ContextRegistry instance.

Values captured multiple times are overridden in the snapshot by the order of contexts given as arguments.

Parameters
contexts:Object[]

context objects to extract values from

Returns:ContextSnapshot

a snapshot with saved context values

captureFromback to summary
public ContextSnapshot captureFrom(Object... contexts)

Create a ContextSnapshot by reading values from the given context objects.

Values captured multiple times are overridden in the snapshot by the order of contexts given as arguments.

Parameters
contexts:Object[]

the contexts to read values from

Returns:ContextSnapshot

the created ContextSnapshot

setThreadLocalsFromback to summary
public <C> ContextSnapshot.Scope setThreadLocalsFrom(Object sourceContext, String... keys)

Read the values specified by keys from the given source context, and if found, use them to set ThreadLocal values. If no keys are provided, all keys are used. Essentially, a shortcut that bypasses the need to create of ContextSnapshot first via captureFrom(Object...), followed by ContextSnapshot#setThreadLocals().

Parameters
<C>
the type of the target context
sourceContext:Object

the source context to read values from

keys:String[]

the keys of the values to read. If none provided, all keys are considered.

Returns:ContextSnapshot.Scope

an object that can be used to reset ThreadLocal values at the end of the context scope, either removing them or restoring their previous values, if any.

io.micrometer.context back to summary

public Interface ContextSnapshotFactory.Builder

Known Direct Implementers
io.micrometer.context.DefaultContextSnapshotFactory.Builder

Builder for ContextSnapshotFactory instances.

Method Summary

Modifier and TypeMethod and Description
public ContextSnapshotFactory

Returns:

an instance configured by the values set on the builder
build
()

Creates a new instance of ContextSnapshotFactory.

public ContextSnapshotFactory.Builder

Returns:

this builder instance
captureKeyPredicate
(Predicate<Object>
predicate used to select matching keys
captureKeyPredicate
)

Instructs the factory to use the given predicate to select matching keys when capturing ThreadLocal values

public ContextSnapshotFactory.Builder

Returns:

this builder instance
clearMissing
(boolean
if true, values not present in the context object or snapshot will be cleared at the start of a scope and later restored
shouldClear
)

Determines whether to clear existing ThreadLocal values at the start of a scope, if there are no corresponding values in the source ContextSnapshot or context object.

public ContextSnapshotFactory.Builder

Returns:

this builder instance
contextRegistry
(ContextRegistry
the registry to use
contextRegistry
)

Configures the ContextRegistry to use by the created factory.

Method Detail

buildback to summary
public ContextSnapshotFactory build()

Creates a new instance of ContextSnapshotFactory.

Returns:ContextSnapshotFactory

an instance configured by the values set on the builder

captureKeyPredicateback to summary
public ContextSnapshotFactory.Builder captureKeyPredicate(Predicate<Object> captureKeyPredicate)

Instructs the factory to use the given predicate to select matching keys when capturing ThreadLocal values

Parameters
captureKeyPredicate:Predicate<Object>

predicate used to select matching keys

Returns:ContextSnapshotFactory.Builder

this builder instance

clearMissingback to summary
public ContextSnapshotFactory.Builder clearMissing(boolean shouldClear)

Determines whether to clear existing ThreadLocal values at the start of a scope, if there are no corresponding values in the source ContextSnapshot or context object.

Parameters
shouldClear:boolean

if true, values not present in the context object or snapshot will be cleared at the start of a scope and later restored

Returns:ContextSnapshotFactory.Builder

this builder instance

contextRegistryback to summary
public ContextSnapshotFactory.Builder contextRegistry(ContextRegistry contextRegistry)

Configures the ContextRegistry to use by the created factory.

Parameters
contextRegistry:ContextRegistry

the registry to use

Returns:ContextSnapshotFactory.Builder

this builder instance