public interface EventuallyConsistentMap<K,V> extends DistributedPrimitive
This map does not offer read after writes consistency. Operations are serialized via the timestamps issued by the clock service. If two updates are in conflict, the update with the more recent timestamp will endure.
The interface is mostly similar to Map
with some minor
semantic changes and the addition of a listener framework (because the map
can be mutated by clients on other instances, not only through the local Java
API).
Clients are expected to register an
EventuallyConsistentMapListener
if they
are interested in receiving notifications of update to the map.
Null values are not allowed in this map.
DistributedPrimitive.Status, DistributedPrimitive.Type
DEFAULT_OPERATION_TIMEOUT_MILLIS, DEFAULT_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,
java.util.function.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.
|
java.util.Set<java.util.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.
|
java.util.Set<K> |
keySet()
Returns a set of the keys in this map.
|
default DistributedPrimitive.Type |
primitiveType()
Returns the type of primitive.
|
void |
put(K key,
V value)
Associates the specified value to the specified key in this map.
|
void |
putAll(java.util.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.
|
java.util.Collection<V> |
values()
Returns a collections of values in this map.
|
addStatusChangeListener, applicationId, destroy, name, removeStatusChangeListener, statusChangeListeners
default DistributedPrimitive.Type primitiveType()
DistributedPrimitive
primitiveType
in interface DistributedPrimitive
int size()
boolean isEmpty()
boolean containsKey(K key)
key
- the key to check if this map containsboolean containsValue(V value)
value
- the value to check if this map has a mapping forV get(K key)
key
- the key to look up in this mapvoid put(K key, V value)
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.
key
- the key to add a mapping for in this mapvalue
- the value to associate with the key in this mapV remove(K key)
Clients are expected to register an EventuallyConsistentMapListener
if
they are interested in receiving notification of updates to the map.
key
- the key to remove the mapping forvoid remove(K key, V value)
This 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.
key
- the key to remove the mapping forvalue
- the value mapped to the keyV compute(K key, java.util.function.BiFunction<K,V,V> recomputeFunction)
If the function returns null, the mapping is removed (or remains absent if initially absent).
key
- map keyrecomputeFunction
- function to recompute a new valuevoid putAll(java.util.Map<? extends K,? extends V> m)
This will be more efficient in communication than calling individual put operations.
m
- a map of values to add to this mapvoid clear()
java.util.Set<K> keySet()
java.util.Collection<V> values()
java.util.Set<java.util.Map.Entry<K,V>> entrySet()
void addListener(EventuallyConsistentMapListener<K,V> listener)
listener
- listener to register for eventsvoid removeListener(EventuallyConsistentMapListener<K,V> listener)
listener
- listener to deregister for events