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 interface
Builder forContextSnapshotFactory
instances. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Creates a builder for configuring the factory.captureAll
(Object... contexts) Capture values fromThreadLocal
and from other context objects using all accessors from aContextRegistry
instance.captureFrom
(Object... contexts) Create aContextSnapshot
by 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 setThreadLocal
values.
-
Method Details
-
captureAll
Capture values fromThreadLocal
and from other context objects using all accessors from aContextRegistry
instance.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 aContextSnapshot
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
- 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 setThreadLocal
values. If no keys are provided, all keys are used. Essentially, a shortcut that bypasses the need to create ofContextSnapshot
first 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
ThreadLocal
values 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
.
-