Package reactor.util.context
Interface ContextView
- All Known Subinterfaces:
Context
public interface ContextView
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.
- Since:
- 3.4.0
- Author:
- Simon Baslé
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidforEach(BiConsumer<Object, Object> action) Perform the given action for each entry in thisContextView.default <T> TResolve a value given a type key within theContext.<T> TResolve a value given a key that exists within theContext, or throw aNoSuchElementExceptionif the key is not present.default <T> @Nullable TgetOrDefault(Object key, @Nullable T defaultValue) Resolve a value given a key within theContext.default <T> Optional<T>getOrEmpty(Object key) Resolve a value given a key within theContext.booleanReturn true if a particular key resolves to a value within theContext.default booleanisEmpty()Return true if theContextis empty.intsize()Return the size of thisContext, the number of immutable key/value pairs stored inside it.stream()Stream key/value pairs from thisContext
-
Method Details
-
get
Resolve a value given a key that exists within theContext, or throw aNoSuchElementExceptionif the key is not present.- Type Parameters:
T- an unchecked casted generic for fluent typing convenience- Parameters:
key- a lookup key to resolve the value within the context- Returns:
- the value resolved for this key (throws if key not found)
- Throws:
NoSuchElementException- when the given key is not present- See Also:
-
get
Resolve a value given a type key within theContext.- Type Parameters:
T- an unchecked casted generic for fluent typing convenience- Parameters:
key- a type key to resolve the value within the context- Returns:
- the value resolved for this type key (throws if key not found)
- Throws:
NoSuchElementException- when the given type key is not present- See Also:
-
getOrDefault
Resolve a value given a key within theContext. If unresolved return the passed default value.- Parameters:
key- a lookup key to resolve the value within the contextdefaultValue- a fallback value if key doesn't resolve- Returns:
- the value resolved for this key, or the given default if not present
-
getOrEmpty
Resolve a value given a key within theContext.- Parameters:
key- a lookup key to resolve the value within the context- Returns:
- an
Optionalof the value for that key.
-
hasKey
Return true if a particular key resolves to a value within theContext.- Parameters:
key- a lookup key to test for- Returns:
- true if this context contains the given key
-
isEmpty
default boolean isEmpty()Return true if theContextis empty.- Returns:
- true if the
Contextis empty.
-
size
int size()Return the size of thisContext, the number of immutable key/value pairs stored inside it.- Returns:
- the size of the
Context
-
stream
Stream key/value pairs from thisContext- Returns:
- a
Streamof key/value pairs held by this context
-
forEach
Perform the given action for each entry in thisContextView. If the action throws an exception, it is immediately propagated to the caller and the remaining items will not be processed.- Parameters:
action- The action to be performed for each entry- Throws:
NullPointerException- if the specified action is null
-