java.lang.Object
io.smallrye.mutiny.Context
A context allows sharing key / value entries along with a subscriber in a Mutiny pipeline, so all operators can
share implicit data for a given subscription.
A context is provided by a UniSubscriber or Flow.Subscriber
that implements ContextSupport.
Context keys are represented as String while values can be from heterogeneous types.
Context instances are thread-safe.
Internal storage is not allocated until the first entry is being added.
Contexts shall be primarily used to share transient data used for networked I/O processing such as correlation identifiers, tokens, etc. They should not be used as general-purpose data structures that are frequently updated and that hold large amounts of data.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks whether the context has an entry for a given key.Delete an entry for a given key, if present.static Contextempty()Creates a new empty context.booleanstatic ContextCreates a context by copying the entries from aMap.<T> TGet a value for a key.<T> TGet a value for a key, or provide an alternative value when not present.inthashCode()booleanisEmpty()Test whether the context is empty.keys()Gives the set of keys present in the context at the time the method is being called.static ContextCreates a context from key / value pairs.Stores a value for a given key.toString()
-
Method Details
-
empty
Creates a new empty context.- Returns:
- the context
-
of
Creates a context from key / value pairs.- Parameters:
entries- a sequence of key / value pairs, as inkey1, value1, key2, value2- Returns:
- the new context
- Throws:
IllegalArgumentException- whenentriesis not balancedNullPointerException- whenentriesisnull
-
from
Creates a context by copying the entries from aMap.- Parameters:
entries- the map, cannot benull- Returns:
- the new context
- Throws:
NullPointerException- whenentriesis null
-
contains
Checks whether the context has an entry for a given key.- Parameters:
key- the key- Returns:
truewhen there is an entry forkey,falseotherwise
-
get
Get a value for a key.- Type Parameters:
T- the value type- Parameters:
key- the key- Returns:
- the value
- Throws:
NoSuchElementException- when there is no entry forkey
-
getOrElse
Get a value for a key, or provide an alternative value when not present.- Type Parameters:
T- the value type- Parameters:
key- the keyalternativeSupplier- the alternative value supplier when there is no entry forkey- Returns:
- the value
-
put
Stores a value for a given key.- Parameters:
key- the keyvalue- the value, cannot benull- Returns:
- this context
-
delete
Delete an entry for a given key, if present.- Parameters:
key- the key- Returns:
- this context
-
isEmpty
public boolean isEmpty()Test whether the context is empty.- Returns:
trueif the context is empty,falseotherwise
-
keys
Gives the set of keys present in the context at the time the method is being called.Note that each call to this method produces a copy.
- Returns:
- the set of keys
-
equals
-
hashCode
public int hashCode() -
toString
-