Top Description Inners Fields Constructors Methods
io.micrometer.context

pack-priv final Class DefaultContextSnapshotFactory

extends Object
implements ContextSnapshotFactory
Class Inheritance
All Implemented Interfaces
io.micrometer.context.ContextSnapshotFactory
Imports
java.util.List, .Map, .Objects, java.util.function.Predicate

Default implementation of ContextSnapshotFactory.
Author
Dariusz Jędrzejczyk
Since
1.0.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final Predicate<Object>
private final boolean
private final ContextRegistry
private static final DefaultContextSnapshot

Constructor Summary

AccessConstructor and Description
public
DefaultContextSnapshotFactory(ContextRegistry contextRegistry, boolean clearMissing, Predicate<Object> captureKeyPredicate)

Method Summary

Modifier and TypeMethod and Description
public ContextSnapshot
captureAll(Object...
context objects to extract values from
contexts
)

Implements io.micrometer.context.ContextSnapshotFactory.captureAll.

Capture values from ThreadLocal and from other context objects using all accessors from a ContextRegistry instance.
pack-priv static ContextSnapshot
captureAll(ContextRegistry contextRegistry, Predicate<Object> keyPredicate, boolean clearMissing, Object... contexts)

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

Implements io.micrometer.context.ContextSnapshotFactory.captureFrom.

Create a ContextSnapshot by reading values from the given context objects.
pack-priv static DefaultContextSnapshot
captureFromContext(Predicate<Object> keyPredicate, boolean clearMissing, ContextRegistry contextRegistry, DefaultContextSnapshot snapshot, Object... contexts)

private static DefaultContextSnapshot
captureFromThreadLocals(Predicate<Object> keyPredicate, boolean clearMissing, ContextRegistry contextRegistry)

private static DefaultContextSnapshot
pack-priv static <C> ContextSnapshot.Scope
setAllThreadLocalsFrom(Object sourceContext, ContextRegistry contextRegistry, boolean clearMissing)

public <C> ContextSnapshot.Scope
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
)

Implements io.micrometer.context.ContextSnapshotFactory.setThreadLocalsFrom.

Read the values specified by keys from the given source context, and if found, use them to set ThreadLocal values.
pack-priv static <C> ContextSnapshot.Scope
setThreadLocalsFrom(Object sourceContext, ContextRegistry contextRegistry, boolean clearMissing, String... keys)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

captureKeyPredicateback to summary
private final Predicate<Object> captureKeyPredicate
clearMissingback to summary
private final boolean clearMissing
contextRegistryback to summary
private final ContextRegistry contextRegistry
emptyContextSnapshotback to summary
private static final DefaultContextSnapshot emptyContextSnapshot

Constructor Detail

DefaultContextSnapshotFactoryback to summary
public DefaultContextSnapshotFactory(ContextRegistry contextRegistry, boolean clearMissing, Predicate<Object> captureKeyPredicate)

Method Detail

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

Implements io.micrometer.context.ContextSnapshotFactory.captureAll.

Doc from io.micrometer.context.ContextSnapshotFactory.captureAll.

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

Annotations
@Override
captureAllback to summary
pack-priv static ContextSnapshot captureAll(ContextRegistry contextRegistry, Predicate<Object> keyPredicate, boolean clearMissing, Object... contexts)
captureFromback to summary
public ContextSnapshot captureFrom(Object... contexts)

Implements io.micrometer.context.ContextSnapshotFactory.captureFrom.

Doc from io.micrometer.context.ContextSnapshotFactory.captureFrom.

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

Annotations
@Override
captureFromContextback to summary
pack-priv static DefaultContextSnapshot captureFromContext(Predicate<Object> keyPredicate, boolean clearMissing, ContextRegistry contextRegistry, DefaultContextSnapshot snapshot, Object... contexts)
Annotations
@SuppressWarnings:unchecked
captureFromThreadLocalsback to summary
private static DefaultContextSnapshot captureFromThreadLocals(Predicate<Object> keyPredicate, boolean clearMissing, ContextRegistry contextRegistry)
Annotations
@Nullable
clearingEmptySnapshotback to summary
private static DefaultContextSnapshot clearingEmptySnapshot(ContextRegistry contextRegistry)
setAllThreadLocalsFromback to summary
pack-priv static <C> ContextSnapshot.Scope setAllThreadLocalsFrom(Object sourceContext, ContextRegistry contextRegistry, boolean clearMissing)
Annotations
@SuppressWarnings:unchecked
setThreadLocalsFromback to summary
public <C> ContextSnapshot.Scope setThreadLocalsFrom(Object sourceContext, String... keys)

Implements io.micrometer.context.ContextSnapshotFactory.setThreadLocalsFrom.

Doc from io.micrometer.context.ContextSnapshotFactory.setThreadLocalsFrom.

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.

Annotations
@Override
setThreadLocalsFromback to summary
pack-priv static <C> ContextSnapshot.Scope setThreadLocalsFrom(Object sourceContext, ContextRegistry contextRegistry, boolean clearMissing, String... keys)
Annotations
@SuppressWarnings:unchecked
io.micrometer.context back to summary

pack-priv final Class DefaultContextSnapshotFactory.Builder

extends Object
implements Builder
Class Inheritance
All Implemented Interfaces
io.micrometer.context.ContextSnapshotFactory.Builder

Field Summary

Modifier and TypeField and Description
private Predicate<Object>
private boolean
private ContextRegistry

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ContextSnapshotFactory
public ContextSnapshotFactory.Builder
captureKeyPredicate(Predicate<Object>
predicate used to select matching keys
captureKeyPredicate
)

Implements io.micrometer.context.ContextSnapshotFactory.Builder.captureKeyPredicate.

Instructs the factory to use the given predicate to select matching keys when capturing ThreadLocal values
public ContextSnapshotFactory.Builder
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
)

Implements io.micrometer.context.ContextSnapshotFactory.Builder.clearMissing.

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
contextRegistry(ContextRegistry
the registry to use
contextRegistry
)

Implements io.micrometer.context.ContextSnapshotFactory.Builder.contextRegistry.

Configures the ContextRegistry to use by the created factory.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

captureKeyPredicateback to summary
private Predicate<Object> captureKeyPredicate
clearMissingback to summary
private boolean clearMissing
contextRegistryback to summary
private ContextRegistry contextRegistry

Constructor Detail

Builderback to summary
public Builder()

Method Detail

buildback to summary
public ContextSnapshotFactory build()

Implements io.micrometer.context.ContextSnapshotFactory.Builder.build.

Doc from io.micrometer.context.ContextSnapshotFactory.Builder.build.

Creates a new instance of ContextSnapshotFactory.

Returns:ContextSnapshotFactory

an instance configured by the values set on the builder

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

Implements io.micrometer.context.ContextSnapshotFactory.Builder.captureKeyPredicate.

Doc from io.micrometer.context.ContextSnapshotFactory.Builder.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

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

Implements io.micrometer.context.ContextSnapshotFactory.Builder.clearMissing.

Doc from io.micrometer.context.ContextSnapshotFactory.Builder.clearMissing.

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

Annotations
@Override
contextRegistryback to summary
public ContextSnapshotFactory.Builder contextRegistry(ContextRegistry contextRegistry)

Implements io.micrometer.context.ContextSnapshotFactory.Builder.contextRegistry.

Doc from io.micrometer.context.ContextSnapshotFactory.Builder.contextRegistry.

Configures the ContextRegistry to use by the created factory.

Parameters
contextRegistry:ContextRegistry

the registry to use

Returns:ContextSnapshotFactory.Builder

this builder instance

Annotations
@Override