public class EventuallyConsistentMapImpl<K,V> extends Object implements EventuallyConsistentMap<K,V>
DistributedPrimitive.Status, DistributedPrimitive.TypeDEFAULT_OPERTATION_TIMEOUT_MILLIS| Modifier and Type | Method and Description |
|---|---|
void |
addListener(EventuallyConsistentMapListener<K,V> listener)
Adds the specified listener to the map which will be notified whenever
the mappings in the map are changed.
|
void |
clear()
Removes all mappings from this map.
|
V |
compute(K key,
BiFunction<K,V,V> recomputeFunction)
Attempts to compute a mapping for the specified key and its current mapped
value (or null if there is no current mapping).
|
boolean |
containsKey(K key)
Returns true if the map contains a mapping for the specified key.
|
boolean |
containsValue(V value)
Returns true if the map contains a mapping from any key to the specified
value.
|
CompletableFuture<Void> |
destroy()
Purges state associated with this primitive.
|
Set<Map.Entry<K,V>> |
entrySet()
Returns a set of mappings contained in this map.
|
V |
get(K key)
Returns the value mapped to the specified key.
|
boolean |
isEmpty()
Returns true if this map is empty.
|
Set<K> |
keySet()
Returns a set of the keys in this map.
|
String |
name()
Returns the name of this primitive.
|
void |
put(K key,
V value)
Associates the specified value to the specified key in this map.
|
void |
putAll(Map<? extends K,? extends V> m)
Adds mappings for all key-value pairs in the specified map to this map.
|
V |
remove(K key)
Removes the mapping associated with the specified key from the map.
|
void |
remove(K key,
V value)
Removes the given key-value mapping from the map, if it exists.
|
void |
removeListener(EventuallyConsistentMapListener<K,V> listener)
Removes the specified listener from the map such that it will no longer
receive change notifications.
|
int |
size()
Returns the number of key-value mappings in this map.
|
Collection<V> |
values()
Returns a collections of values in this map.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitprimitiveTypeaddStatusChangeListener, applicationId, removeStatusChangeListener, statusChangeListenerspublic String name()
DistributedPrimitivename in interface DistributedPrimitivepublic int size()
EventuallyConsistentMapsize in interface EventuallyConsistentMap<K,V>public boolean isEmpty()
EventuallyConsistentMapisEmpty in interface EventuallyConsistentMap<K,V>public boolean containsKey(K key)
EventuallyConsistentMapcontainsKey in interface EventuallyConsistentMap<K,V>key - the key to check if this map containspublic boolean containsValue(V value)
EventuallyConsistentMapcontainsValue in interface EventuallyConsistentMap<K,V>value - the value to check if this map has a mapping forpublic V get(K key)
EventuallyConsistentMapget in interface EventuallyConsistentMap<K,V>key - the key to look up in this mappublic void put(K key, V value)
EventuallyConsistentMap
Note: this differs from the specification of Map
because it does not return the previous value associated with the key.
Clients are expected to register an
EventuallyConsistentMapListener if
they are interested in receiving notification of updates to the map.
Null values are not allowed in the map.
put in interface EventuallyConsistentMap<K,V>key - the key to add a mapping for in this mapvalue - the value to associate with the key in this mappublic V remove(K key)
EventuallyConsistentMap
Clients are expected to register an EventuallyConsistentMapListener if
they are interested in receiving notification of updates to the map.
remove in interface EventuallyConsistentMap<K,V>key - the key to remove the mapping forpublic void remove(K key, V value)
EventuallyConsistentMapThis actually means remove any values up to and including the timestamp given by the map's timestampProvider. Any mappings that produce an earlier timestamp than this given key-value pair will be removed, and any mappings that produce a later timestamp will supersede this remove.
Note: this differs from the specification of Map
because it does not return a boolean indication whether a value was removed.
Clients are expected to register an
EventuallyConsistentMapListener if
they are interested in receiving notification of updates to the map.
remove in interface EventuallyConsistentMap<K,V>key - the key to remove the mapping forvalue - the value mapped to the keypublic V compute(K key, BiFunction<K,V,V> recomputeFunction)
EventuallyConsistentMapIf the function returns null, the mapping is removed (or remains absent if initially absent).
compute in interface EventuallyConsistentMap<K,V>key - map keyrecomputeFunction - function to recompute a new valuepublic void putAll(Map<? extends K,? extends V> m)
EventuallyConsistentMapThis will be more efficient in communication than calling individual put operations.
putAll in interface EventuallyConsistentMap<K,V>m - a map of values to add to this mappublic void clear()
EventuallyConsistentMapclear in interface EventuallyConsistentMap<K,V>public Set<K> keySet()
EventuallyConsistentMapkeySet in interface EventuallyConsistentMap<K,V>public Collection<V> values()
EventuallyConsistentMapvalues in interface EventuallyConsistentMap<K,V>public Set<Map.Entry<K,V>> entrySet()
EventuallyConsistentMapentrySet in interface EventuallyConsistentMap<K,V>public void addListener(EventuallyConsistentMapListener<K,V> listener)
EventuallyConsistentMapaddListener in interface EventuallyConsistentMap<K,V>listener - listener to register for eventspublic void removeListener(EventuallyConsistentMapListener<K,V> listener)
EventuallyConsistentMapremoveListener in interface EventuallyConsistentMap<K,V>listener - listener to deregister for eventspublic CompletableFuture<Void> destroy()
DistributedPrimitiveImplementations can override and provide appropriate clean up logic for purging any state state associated with the primitive. Whether modifications made within the destroy method have local or global visibility is left unspecified.
destroy in interface DistributedPrimitiveCompletableFuture that is completed when the operation completes