Package io.micrometer.context
Interface ContextSnapshotFactory
public interface ContextSnapshotFactory
Factory for creating
ContextSnapshot objects and restoring ThreadLocal
values using a context object for which a ContextAccessor exists in the
ContextRegistry.- Since:
- 1.0.3
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceBuilder forContextSnapshotFactoryinstances. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a builder for configuring the factory.captureAll(Object... contexts) Capture values fromThreadLocaland from other context objects using all accessors from aContextRegistryinstance.captureFrom(Object... contexts) Create aContextSnapshotby reading values from the given context objects.setThreadLocalsFrom(Object sourceContext, String... keys) Read the values specified by keys from the given source context, and if found, use them to setThreadLocalvalues.
-
Method Details
-
captureAll
Capture values fromThreadLocaland from other context objects using all accessors from aContextRegistryinstance.Values captured multiple times are overridden in the snapshot by the order of contexts given as arguments.
- Parameters:
contexts- context objects to extract values from- Returns:
- a snapshot with saved context values
-
captureFrom
Create aContextSnapshotby 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- the contexts to read values from- Returns:
- the created
ContextSnapshot
-
setThreadLocalsFrom
Read the values specified by keys from the given source context, and if found, use them to setThreadLocalvalues. If no keys are provided, all keys are used. Essentially, a shortcut that bypasses the need to create ofContextSnapshotfirst viacaptureFrom(Object...), followed byContextSnapshot.setThreadLocals().- Type Parameters:
C- the type of the target context- Parameters:
sourceContext- the source context to read values fromkeys- the keys of the values to read. If none provided, all keys are considered.- Returns:
- an object that can be used to reset
ThreadLocalvalues at the end of the context scope, either removing them or restoring their previous values, if any.
-
builder
Creates a builder for configuring the factory.- Returns:
- an instance that provides defaults, that can be configured to provide to
the created
ContextSnapshotFactory.
-