Package io.servicetalk.concurrent.api
Interface AsyncContextMap
-
public interface AsyncContextMapThe key-value map stored in theAsyncContext.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classAsyncContextMap.Key<T>A key identifies a specific object in aAsyncContextMap.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclear()Clear the contents of thisAsyncContextMap.booleancontainsKey(AsyncContextMap.Key<?> key)Determine if this context contains a key/value entry corresponding tokey.AsyncContextMapcopy()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> Tget(AsyncContextMap.Key<T> key)Get the value associated withkey, ornullif no value is associated.booleanisEmpty()Determine if there are no key/value pairs in thisAsyncContextMap.<T> Tput(AsyncContextMap.Key<T> key, T value)Put a new key/value pair into thisAsyncContextMap.voidputAll(java.util.Map<AsyncContextMap.Key<?>,java.lang.Object> map)Put all the key/value pairs into thisAsyncContextMap.<T> Tremove(AsyncContextMap.Key<T> key)Remove a key/value pair from thisAsyncContextMap, and get the previous value (if one exists).booleanremoveAll(java.lang.Iterable<AsyncContextMap.Key<?>> entries)Remove all key/value pairs from thisAsyncContextMapassociated with the keys from theIterable.intsize()Determine the number ofAsyncContextMap.Key-value mappings.
-
-
-
Method Detail
-
get
@Nullable <T> T get(AsyncContextMap.Key<T> key)
Get the value associated withkey, ornullif 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, ornullif 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:
trueif this context contains a key/value entry corresponding tokey.falseotherwise.
-
isEmpty
boolean isEmpty()
Determine if there are no key/value pairs in thisAsyncContextMap.- Returns:
trueif 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, ornullif there was none. Anullvalue may also indicate there was a previous value which wasnull. - Throws:
java.lang.NullPointerException- ifkeyisnull, orvalueisnull.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 ifentriesis 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, ornullif there was none. Anullvalue may also indicate there was a previous value which wasnull. If theAsyncContextMapimplementation 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 thisAsyncContextMapassociated with the keys from theIterable.- Parameters:
entries- The entries to remove from thisAsyncContextMap.- Returns:
trueif this map has changed as a result of this operation.- Throws:
java.util.ConcurrentModificationException- Done on a best effort basis ifentriesis 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. Returnstrueif the consumer wants to keep iterating orfalseto stop iteration at the current key/value pair.- Returns:
nullifconsumeriterated through all key/value pairs or theAsyncContextMap.Keyat which the iteration stopped.
-
copy
AsyncContextMap copy()
Create an isolated copy of the current map. The return value contents are the same as thisAsyncContextMapbut modifications to thisAsyncContextMapare not visible in the return value, and visa-versa.- Returns:
- an isolated copy of the current map. Tcontents are the same as this
AsyncContextMapbut modifications to thisAsyncContextMapare not visible in the return value, and visa-versa.
-
-