Interface AsyncDistributedMap<K,V>
- All Superinterfaces:
AsyncPrimitive,DistributedPrimitive
-
Field Summary
Fields inherited from interface io.atomix.client.DistributedPrimitive
DEFAULT_OPERATION_TIMEOUT_MILLIS -
Method Summary
Modifier and TypeMethodDescriptionclear()Removes all of the mappings from this map (optional operation).Attempts to compute a mapping for the specified key and its current mapped value (ornullif there is no current mapping).computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) If the specified key is not already associated with a value (or is mapped tonull), attempts to compute its value using the given mapping function and enters it into this map unlessnull.computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.containsKey(K key) Returnstrueif this map contains a mapping for the specified key.containsValue(V value) Returnstrueif this map maps one or more keys to the specified value.entrySet()Returns aSetview of the mappings contained in this map.Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.getOrDefault(K key, V defaultValue) Returns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.isEmpty()Returnstrueif this map contains no key-value mappings.keySet()Returns aSetview of the keys contained in this map.default CompletableFuture<Cancellable>listen(MapEventListener<K, V> listener) Registers the specified listener to be notified whenever the map is updated.listen(MapEventListener<K, V> listener, Executor executor) Registers the specified listener to be notified whenever the map is updated.Associates the specified value with the specified key in this map (optional operation).Copies all of the mappings from the specified map to this map (optional operation).putIfAbsent(K key, V value) If the specified key is not already associated with a value (or is mapped tonull) associates it with the given value and returnsnull, else returns the current value.Removes the mapping for a key from this map if it is present (optional operation).Removes the entry for the specified key only if it is currently mapped to the specified value.Replaces the entry for the specified key only if it is currently mapped to some value.Replaces the entry for the specified key only if currently mapped to the specified value.size()Returns the number of key-value mappings in this map.default DistributedMap<K,V> sync()Returns a synchronous wrapper around the asynchronous primitive.Returns a synchronous wrapper around the asynchronous primitive.values()Returns aCollectionview of the values contained in this map.Methods inherited from interface io.atomix.client.AsyncPrimitive
closeMethods inherited from interface io.atomix.client.DistributedPrimitive
name
-
Method Details
-
size
CompletableFuture<Integer> size()Returns the number of key-value mappings in this map. If the map contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE.- Returns:
- the number of key-value mappings in this map
-
isEmpty
CompletableFuture<Boolean> isEmpty()Returnstrueif this map contains no key-value mappings.- Returns:
trueif this map contains no key-value mappings
-
containsKey
Returnstrueif this map contains a mapping for the specified key. More formally, returnstrueif and only if this map contains a mapping for a keyksuch that(key==null ? k==null : key.equals(k)). (There can be at most one such mapping.)- Parameters:
key- key whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for the specified key- Throws:
ClassCastException- if the key is of an inappropriate type for this map (optional)NullPointerException- if the specified key is null and this map does not permit null keys (optional)
-
containsValue
Returnstrueif this map maps one or more keys to the specified value. More formally, returnstrueif and only if this map contains at least one mapping to a valuevsuch that(value==null ? v==null : value.equals(v)). This operation will probably require time linear in the map size for most implementations of theMapinterface.- Parameters:
value- value whose presence in this map is to be tested- Returns:
trueif this map maps one or more keys to the specified value- Throws:
ClassCastException- if the value is of an inappropriate type for this map (optional)NullPointerException- if the specified value is null and this map does not permit null values (optional)
-
get
Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.More formally, if this map contains a mapping from a key
kto a valuevsuch that(key==null ? k==null : key.equals(k)), then this method returnsv; otherwise it returnsnull. (There can be at most one such mapping.)If this map permits null values, then a return value of
nulldoes not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key tonull. ThecontainsKeyoperation may be used to distinguish these two cases.- Parameters:
key- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
nullif this map contains no mapping for the key - Throws:
ClassCastException- if the key is of an inappropriate type for this map (optional)NullPointerException- if the specified key is null and this map does not permit null keys (optional)
-
put
Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A mapmis said to contain a mapping for a keykif and only ifm.containsKey(k)would returntrue.)- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey. (Anullreturn can also indicate that the map previously associatednullwithkey, if the implementation supportsnullvalues.) - Throws:
UnsupportedOperationException- if theputoperation is not supported by this mapClassCastException- if the class of the specified key or value prevents it from being stored in this mapNullPointerException- if the specified key or value is null and this map does not permit null keys or valuesIllegalArgumentException- if some property of the specified key or value prevents it from being stored in this map
-
remove
Removes the mapping for a key from this map if it is present (optional operation). More formally, if this map contains a mapping from keykto valuevsuch that(key==null ? k==null : key.equals(k)), that mapping is removed. (The map can contain at most one such mapping.)Returns the value to which this map previously associated the key, or
nullif the map contained no mapping for the key.If this map permits null values, then a return value of
nulldoes not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key tonull.The map will not contain a mapping for the specified key once the call returns.
- Parameters:
key- key whose mapping is to be removed from the map- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey. - Throws:
UnsupportedOperationException- if theremoveoperation is not supported by this mapClassCastException- if the key is of an inappropriate type for this map (optional)NullPointerException- if the specified key is null and this map does not permit null keys (optional)
-
putAll
Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of callingput(k, v)on this map once for each mapping from keykto valuevin the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress.- Parameters:
m- mappings to be stored in this map- Throws:
UnsupportedOperationException- if theputAlloperation is not supported by this mapClassCastException- if the class of a key or value in the specified map prevents it from being stored in this mapNullPointerException- if the specified map is null, or if this map does not permit null keys or values, and the specified map contains null keys or valuesIllegalArgumentException- if some property of a key or value in the specified map prevents it from being stored in this map
-
clear
CompletableFuture<Void> clear()Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.- Throws:
UnsupportedOperationException- if theclearoperation is not supported by this map
-
keySet
AsyncDistributedSet<K> keySet()Returns aSetview of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.- Returns:
- a set view of the keys contained in this map
-
values
AsyncDistributedCollection<V> values()Returns aCollectionview of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Collection.remove,removeAll,retainAllandclearoperations. It does not support theaddoraddAlloperations.- Returns:
- a collection view of the values contained in this map
-
entrySet
AsyncDistributedSet<Map.Entry<K,V>> entrySet()Returns aSetview of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation, or through thesetValueoperation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAllandclearoperations. It does not support theaddoraddAlloperations.- Returns:
- a set view of the mappings contained in this map
-
getOrDefault
Returns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.- Parameters:
key- the key whose associated value is to be returneddefaultValue- the default mapping of the key- Returns:
- the value to which the specified key is mapped, or
defaultValueif this map contains no mapping for the key - Throws:
ClassCastException- if the key is of an inappropriate type for this map (optional)NullPointerException- if the specified key is null and this map does not permit null keys (optional)
-
putIfAbsent
If the specified key is not already associated with a value (or is mapped tonull) associates it with the given value and returnsnull, else returns the current value.- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with the specified key, or
nullif there was no mapping for the key. (Anullreturn can also indicate that the map previously associatednullwith the key, if the implementation supports null values.) - Throws:
UnsupportedOperationException- if theputoperation is not supported by this map (optional)ClassCastException- if the key or value is of an inappropriate type for this map (optional)NullPointerException- if the specified key or value is null, and this map does not permit null keys or values (optional)IllegalArgumentException- if some property of the specified key or value prevents it from being stored in this map (optional)
-
remove
Removes the entry for the specified key only if it is currently mapped to the specified value.- Parameters:
key- key with which the specified value is associatedvalue- value expected to be associated with the specified key- Returns:
trueif the value was removed- Throws:
UnsupportedOperationException- if theremoveoperation is not supported by this map (optional)ClassCastException- if the key or value is of an inappropriate type for this map (optional)NullPointerException- if the specified key or value is null, and this map does not permit null keys or values (optional)
-
replace
Replaces the entry for the specified key only if currently mapped to the specified value.- Parameters:
key- key with which the specified value is associatedoldValue- value expected to be associated with the specified keynewValue- value to be associated with the specified key- Returns:
trueif the value was replaced- Throws:
UnsupportedOperationException- if theputoperation is not supported by this map (optional)ClassCastException- if the class of a specified key or value prevents it from being stored in this mapNullPointerException- if a specified key or newValue is null, and this map does not permit null keys or valuesNullPointerException- if oldValue is null and this map does not permit null values (optional)IllegalArgumentException- if some property of a specified key or value prevents it from being stored in this map
-
replace
Replaces the entry for the specified key only if it is currently mapped to some value.- Parameters:
key- key with which the specified value is associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with the specified key, or
nullif there was no mapping for the key. (Anullreturn can also indicate that the map previously associatednullwith the key, if the implementation supports null values.) - Throws:
UnsupportedOperationException- if theputoperation is not supported by this map (optional)ClassCastException- if the class of the specified key or value prevents it from being stored in this map (optional)NullPointerException- if the specified key or value is null, and this map does not permit null keys or valuesIllegalArgumentException- if some property of the specified key or value prevents it from being stored in this map
-
computeIfAbsent
If the specified key is not already associated with a value (or is mapped tonull), attempts to compute its value using the given mapping function and enters it into this map unlessnull.If the function returns
nullno mapping is recorded. If the function itself throws an (unchecked) exception, the exception is rethrown, and no mapping is recorded. The most common usage is to construct a new object serving as an initial mapped value or memoized result, as in:map.computeIfAbsent(key, k -> new Value(f(k)));Or to implement a multi-value map,
Map<K,Collection<V>>, supporting multiple values per key:map.computeIfAbsent(key, k -> new HashSet<V>()).add(v);- Parameters:
key- key with which the specified value is to be associatedmappingFunction- the function to compute a value- Returns:
- the current (existing or computed) value associated with the specified key, or null if the computed value is null
- Throws:
NullPointerException- if the specified key is null and this map does not support null keys, or the mappingFunction is nullUnsupportedOperationException- if theputoperation is not supported by this map (optional)ClassCastException- if the class of the specified key or value prevents it from being stored in this map (optional)
-
computeIfPresent
CompletableFuture<V> computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.If the function returns
null, the mapping is removed. If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.- Parameters:
key- key with which the specified value is to be associatedremappingFunction- the function to compute a value- Returns:
- the new value associated with the specified key, or null if none
- Throws:
NullPointerException- if the specified key is null and this map does not support null keys, or the remappingFunction is nullUnsupportedOperationException- if theputoperation is not supported by this map (optional)ClassCastException- if the class of the specified key or value prevents it from being stored in this map (optional)
-
compute
Attempts to compute a mapping for the specified key and its current mapped value (ornullif there is no current mapping). For example, to either create or append aStringmsg to a value mapping:If the function returns
null, the mapping is removed (or remains absent if initially absent). If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.- Parameters:
key- key with which the specified value is to be associatedremappingFunction- the function to compute a value- Returns:
- the new value associated with the specified key, or null if none
- Throws:
NullPointerException- if the specified key is null and this map does not support null keys, or the remappingFunction is nullUnsupportedOperationException- if theputoperation is not supported by this map (optional)ClassCastException- if the class of the specified key or value prevents it from being stored in this map (optional)
-
listen
Registers the specified listener to be notified whenever the map is updated.- Parameters:
listener- listener to notify about map events- Returns:
- future that will be completed when the operation finishes
-
listen
Registers the specified listener to be notified whenever the map is updated.- Parameters:
listener- listener to notify about map eventsexecutor- executor to use for handling incoming map events- Returns:
- future that will be completed when the operation finishes
-
sync
Description copied from interface:AsyncPrimitiveReturns a synchronous wrapper around the asynchronous primitive.- Specified by:
syncin interfaceAsyncPrimitive- Returns:
- the synchronous primitive
-
sync
Description copied from interface:AsyncPrimitiveReturns a synchronous wrapper around the asynchronous primitive.- Specified by:
syncin interfaceAsyncPrimitive- Parameters:
operationTimeout- the synchronous operation timeout- Returns:
- the synchronous primitive
-