Top Description Methods
io.micrometer.context

public Interface ContextAccessor<READ, WRITE>

Type Parameters
<READ>
type of context for reading
<WRITE>
type of context for writing
Imports
java.util.Map, java.util.function.Predicate

Contract to assist with access to an external, map-like context, such as the Project Reactor Context, including the ability to read values from it a Map and to write values to it from a Map.
Authors
Marcin Grzejszczak, Rossen Stoyanchev
Since
1.0.0

Method Summary

Modifier and TypeMethod and Description
public Class<? extends READ>
readableType()

Class representing the type of context this accessor is capable of reading values from.

public <T> T

Returns:

the value, if present
readValue
(READ
the context to read from; the context type should be assignable from the type returned by readableType().
sourceContext
,
Object
the key to use to look up the context value
key
)

Read a single value from the source context.

public void
readValues(READ
the context to read from; the context type should be assignable from the type returned by readableType().

When an ContextAccessor is used to populate a ContextSnapshot, the snapshot implementations are required to filter out null mappings, so it is not required to implement special handling in the accessor.

sourceContext
,
Predicate<Object>
a predicate to decide which keys to read
keyPredicate
,
Map<Object, Object>
a map where to put read values
readValues
)

Read values from a source context into a Map.

public Class<? extends WRITE>
writeableType()

Class representing the type of context this accessor can restore values to.

public WRITE

Returns:

a context with the written values
writeValues
(Map<Object, Object>
the values to write to the target context.
valuesToWrite
,
WRITE
the context to write to; the context type should be assignable from the type returned by writeableType().
targetContext
)

Write values from a Map to a target context.

Method Detail

readableTypeback to summary
public Class<? extends READ> readableType()

Class representing the type of context this accessor is capable of reading values from.

readValueback to summary
public <T> T readValue(READ sourceContext, Object key)

Read a single value from the source context.

Parameters
sourceContext:READ

the context to read from; the context type should be assignable from the type returned by readableType().

key:Object

the key to use to look up the context value

Returns:T

the value, if present

Annotations
@Nullable
readValuesback to summary
public void readValues(READ sourceContext, Predicate<Object> keyPredicate, Map<Object, Object> readValues)

Read values from a source context into a Map.

Parameters
sourceContext:READ

the context to read from; the context type should be assignable from the type returned by readableType().

When an ContextAccessor is used to populate a ContextSnapshot, the snapshot implementations are required to filter out null mappings, so it is not required to implement special handling in the accessor.

keyPredicate:Predicate<Object>

a predicate to decide which keys to read

readValues:Map<Object, Object>

a map where to put read values

writeableTypeback to summary
public Class<? extends WRITE> writeableType()

Class representing the type of context this accessor can restore values to.

writeValuesback to summary
public WRITE writeValues(Map<Object, Object> valuesToWrite, WRITE targetContext)

Write values from a Map to a target context.

Parameters
valuesToWrite:Map<Object, Object>

the values to write to the target context.

targetContext:WRITE

the context to write to; the context type should be assignable from the type returned by writeableType().

Returns:WRITE

a context with the written values