Package io.servicetalk.concurrent.api
Interface AsyncContextMap
-
public interface AsyncContextMap
The key-value map stored in theAsyncContext
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
AsyncContextMap.Key<T>
A key identifies a specific object in aAsyncContextMap
.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clear()
Clear the contents of thisAsyncContextMap
.boolean
containsKey(AsyncContextMap.Key<?> key)
Determine if this context contains a key/value entry corresponding tokey
.AsyncContextMap
copy()
Create an isolated copy of the current map.AsyncContextMap.Key<?>
forEach(java.util.function.BiPredicate<AsyncContextMap.Key<?>,java.lang.Object> consumer)
Iterate over the key/value pairs contained in this request context.<T> T
get(AsyncContextMap.Key<T> key)
Get the value associated withkey
, ornull
if no value is associated.boolean
isEmpty()
Determine if there are no key/value pairs in thisAsyncContextMap
.<T> T
put(AsyncContextMap.Key<T> key, T value)
Put a new key/value pair into thisAsyncContextMap
.void
putAll(java.util.Map<AsyncContextMap.Key<?>,java.lang.Object> map)
Put all the key/value pairs into thisAsyncContextMap
.<T> T
remove(AsyncContextMap.Key<T> key)
Remove a key/value pair from thisAsyncContextMap
, and get the previous value (if one exists).boolean
removeAll(java.lang.Iterable<AsyncContextMap.Key<?>> entries)
Remove all key/value pairs from thisAsyncContextMap
associated with the keys from theIterable
.int
size()
Determine the number ofAsyncContextMap.Key
-value mappings.
-
-
-
Method Detail
-
get
@Nullable <T> T get(AsyncContextMap.Key<T> key)
Get the value associated withkey
, ornull
if no value is associated.- Type Parameters:
T
- The anticipated type of object associated withkey
.- Parameters:
key
- the key to lookup.- Returns:
- the value associated with
key
, ornull
if no value is associated.
-
containsKey
boolean containsKey(AsyncContextMap.Key<?> key)
Determine if this context contains a key/value entry corresponding tokey
.- Parameters:
key
- the key to lookup.- Returns:
true
if this context contains a key/value entry corresponding tokey
.false
otherwise.
-
isEmpty
boolean isEmpty()
Determine if there are no key/value pairs in thisAsyncContextMap
.- Returns:
true
if there are no key/value pairs in thisAsyncContextMap
.
-
size
int size()
Determine the number ofAsyncContextMap.Key
-value mappings.- Returns:
- the number of
AsyncContextMap.Key
-value mappings.
-
put
@Nullable <T> T put(AsyncContextMap.Key<T> key, T value)
Put a new key/value pair into thisAsyncContextMap
.- Type Parameters:
T
- The type of object associated withkey
.- Parameters:
key
- the key used to indexvalue
. Cannot benull
.value
- the value to put.- Returns:
- The previous value associated with the
key
, ornull
if there was none. Anull
value may also indicate there was a previous value which wasnull
. - Throws:
java.lang.NullPointerException
- ifkey
isnull
, orvalue
isnull
.java.lang.UnsupportedOperationException
- if this method is not supported.
-
putAll
void putAll(java.util.Map<AsyncContextMap.Key<?>,java.lang.Object> map)
Put all the key/value pairs into thisAsyncContextMap
.- Parameters:
map
- The entries to insert into thisAsyncContextMap
.- Throws:
java.util.ConcurrentModificationException
- Done on a best effort basis ifentries
is detected to be modified while attempting to put all entries.java.lang.UnsupportedOperationException
- if this method is not supported.
-
remove
@Nullable <T> T remove(AsyncContextMap.Key<T> key)
Remove a key/value pair from thisAsyncContextMap
, and get the previous value (if one exists).- Type Parameters:
T
- The type of object associated withkey
.- Parameters:
key
- The key which identifies the key/value to remove.- Returns:
- the previous value associated with
key
, ornull
if there was none. Anull
value may also indicate there was a previous value which wasnull
. If theAsyncContextMap
implementation is immutable this may be a new object. - Throws:
java.lang.UnsupportedOperationException
- if this method is not supported.
-
removeAll
boolean removeAll(java.lang.Iterable<AsyncContextMap.Key<?>> entries)
Remove all key/value pairs from thisAsyncContextMap
associated with the keys from theIterable
.- Parameters:
entries
- The entries to remove from thisAsyncContextMap
.- Returns:
true
if this map has changed as a result of this operation.- Throws:
java.util.ConcurrentModificationException
- Done on a best effort basis ifentries
is detected to be modified while attempting to remove all entries.java.lang.UnsupportedOperationException
- if this method is not supported.
-
clear
void clear()
Clear the contents of thisAsyncContextMap
.- Throws:
java.lang.UnsupportedOperationException
- if this method is not supported.
-
forEach
@Nullable AsyncContextMap.Key<?> forEach(java.util.function.BiPredicate<AsyncContextMap.Key<?>,java.lang.Object> consumer)
Iterate over the key/value pairs contained in this request context.- Parameters:
consumer
- Each key/value pair will be passed as arguments to thisBiPredicate
. Returnstrue
if the consumer wants to keep iterating orfalse
to stop iteration at the current key/value pair.- Returns:
null
ifconsumer
iterated through all key/value pairs or theAsyncContextMap.Key
at which the iteration stopped.
-
copy
AsyncContextMap copy()
Create an isolated copy of the current map. The return value contents are the same as thisAsyncContextMap
but modifications to thisAsyncContextMap
are not visible in the return value, and visa-versa.- Returns:
- an isolated copy of the current map. Tcontents are the same as this
AsyncContextMap
but modifications to thisAsyncContextMap
are not visible in the return value, and visa-versa.
-
-