Top Description Methods
reactor.util.context

public Interface ContextView

Known Direct Subinterfaces
reactor.util.context.Context
Imports
java.util.Map, .NoSuchElementException, .Optional, java.util.function.BiConsumer, java.util.stream.Stream, reactor.util.annotation.Nullable

A read-only view of a collection of key/value pairs that is propagated between components such as operators via the context protocol. Contexts are ideal to transport orthogonal information such as tracing or security tokens.

Context is an immutable variant of the same key/value pairs structure which exposes a write API that returns new instances on each write.

Author
Simon Baslé
Since
3.4.0

Method Summary

Modifier and TypeMethod and Description
public default void
forEach(BiConsumer<Object, Object>
The action to be performed for each entry
action
)

Perform the given action for each entry in this ContextView.

public <
an unchecked casted generic for fluent typing convenience
T
>
T

Returns:

the value resolved for this key (throws if key not found)
get
(Object
a lookup key to resolve the value within the context
key
)

Resolve a value given a key that exists within the Context, or throw a NoSuchElementException if the key is not present.

public default <
an unchecked casted generic for fluent typing convenience
T
>
T

Returns:

the value resolved for this type key (throws if key not found)
get
(Class<T>
a type key to resolve the value within the context
key
)

Resolve a value given a type key within the Context.

public default <T> T

Returns:

the value resolved for this key, or the given default if not present
getOrDefault
(Object
a lookup key to resolve the value within the context
key
,
T
a fallback value if key doesn't resolve
defaultValue
)

Resolve a value given a key within the Context.

public default <T> Optional<T>

Returns:

an Optional of the value for that key.
getOrEmpty
(Object
a lookup key to resolve the value within the context
key
)

Resolve a value given a key within the Context.

public boolean

Returns:

true if this context contains the given key
hasKey
(Object
a lookup key to test for
key
)

Return true if a particular key resolves to a value within the Context.

public default boolean

Returns:

true if the Context is empty.
isEmpty
()

Return true if the Context is empty.

public int

Returns:

the size of the Context
size
()

Return the size of this Context, the number of immutable key/value pairs stored inside it.

public Stream<Map.Entry<Object, Object>>

Returns:

a Stream of key/value pairs held by this context
stream
()

Stream key/value pairs from this Context

Method Detail

forEachback to summary
public default void forEach(BiConsumer<Object, Object> action)

Perform the given action for each entry in this ContextView. If the action throws an exception, it is immediately propagated to the caller and the remaining items will not be processed.

Parameters
action:BiConsumer<Object, Object>

The action to be performed for each entry

Exceptions
NullPointerException:
if the specified action is null
getback to summary
public <T> T get(Object key)

Resolve a value given a key that exists within the Context, or throw a NoSuchElementException if the key is not present.

Parameters
<T>
an unchecked casted generic for fluent typing convenience
key:Object

a lookup key to resolve the value within the context

Returns:T

the value resolved for this key (throws if key not found)

Exceptions
NoSuchElementException:
when the given key is not present
See Also
getOrDefault(Object, Object), getOrEmpty(Object), hasKey(Object)
getback to summary
public default <T> T get(Class<T> key)

Resolve a value given a type key within the Context.

Parameters
<T>
an unchecked casted generic for fluent typing convenience
key:Class<T>

a type key to resolve the value within the context

Returns:T

the value resolved for this type key (throws if key not found)

Exceptions
NoSuchElementException:
when the given type key is not present
See Also
getOrDefault(Object, Object), getOrEmpty(Object)
getOrDefaultback to summary
public default <T> T getOrDefault(Object key, T defaultValue)

Resolve a value given a key within the Context. If unresolved return the passed default value.

Parameters
key:Object

a lookup key to resolve the value within the context

defaultValue:T

a fallback value if key doesn't resolve

Returns:T

the value resolved for this key, or the given default if not present

Annotations
@Nullable
getOrEmptyback to summary
public default <T> Optional<T> getOrEmpty(Object key)

Resolve a value given a key within the Context.

Parameters
key:Object

a lookup key to resolve the value within the context

Returns:Optional<T>

an Optional of the value for that key.

hasKeyback to summary
public boolean hasKey(Object key)

Return true if a particular key resolves to a value within the Context.

Parameters
key:Object

a lookup key to test for

Returns:boolean

true if this context contains the given key

isEmptyback to summary
public default boolean isEmpty()

Return true if the Context is empty.

Returns:boolean

true if the Context is empty.

sizeback to summary
public int size()

Return the size of this Context, the number of immutable key/value pairs stored inside it.

Returns:int

the size of the Context

streamback to summary
public Stream<Map.Entry<Object, Object>> stream()

Stream key/value pairs from this Context

Returns:Stream<Map.Entry<Object, Object>>

a Stream of key/value pairs held by this context