public class EventuallyConsistentMapImpl<K,V> extends Object implements EventuallyConsistentMap<K,V>
| Constructor and Description |
|---|
EventuallyConsistentMapImpl(String mapName,
org.onosproject.cluster.ClusterService clusterService,
org.onosproject.store.cluster.messaging.ClusterCommunicationService clusterCommunicator,
org.onlab.util.KryoNamespace.Builder serializerBuilder,
ClockService<K,V> clockService)
Creates a new eventually consistent map shared amongst multiple instances.
|
EventuallyConsistentMapImpl(String mapName,
org.onosproject.cluster.ClusterService clusterService,
org.onosproject.store.cluster.messaging.ClusterCommunicationService clusterCommunicator,
org.onlab.util.KryoNamespace.Builder serializerBuilder,
ClockService<K,V> clockService,
java.util.function.BiFunction<K,V,Collection<org.onosproject.cluster.NodeId>> peerUpdateFunction)
Creates a new eventually consistent map shared amongst multiple instances.
|
| 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.
|
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.
|
void |
destroy()
Shuts down the map and breaks communication between different instances.
|
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.
|
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.
|
void |
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.
|
EventuallyConsistentMapImpl<K,V> |
withBroadcastMessageExecutor(ExecutorService executor)
Sets the executor to use for broadcasting messages and returns this
instance for method chaining.
|
EventuallyConsistentMapImpl<K,V> |
withTombstonesDisabled(boolean status) |
public EventuallyConsistentMapImpl(String mapName, org.onosproject.cluster.ClusterService clusterService, org.onosproject.store.cluster.messaging.ClusterCommunicationService clusterCommunicator, org.onlab.util.KryoNamespace.Builder serializerBuilder, ClockService<K,V> clockService, java.util.function.BiFunction<K,V,Collection<org.onosproject.cluster.NodeId>> peerUpdateFunction)
Each map is identified by a string map name. EventuallyConsistentMapImpl objects in different JVMs that use the same map name will form a distributed map across JVMs (provided the cluster service is aware of both nodes).
The client is expected to provide an
KryoNamespace.Builder with which all classes that
will be stored in this map have been registered (including referenced
classes). This serializer will be used to serialize both K and V for
inter-node notifications.
The client must provide an ClockService
which can generate timestamps for a given key. The clock service is free
to generate timestamps however it wishes, however these timestamps will
be used to serialize updates to the map so they must be strict enough
to ensure updates are properly ordered for the use case (i.e. in some
cases wallclock time will suffice, whereas in other cases logical time
will be necessary).
mapName - a String identifier for the map.clusterService - the cluster serviceclusterCommunicator - the cluster communications serviceserializerBuilder - a Kryo namespace builder that can serialize
both K and VclockService - a clock service able to generate timestamps
for KpeerUpdateFunction - function that provides a set of nodes to immediately
update to when there writes to the mappublic EventuallyConsistentMapImpl(String mapName, org.onosproject.cluster.ClusterService clusterService, org.onosproject.store.cluster.messaging.ClusterCommunicationService clusterCommunicator, org.onlab.util.KryoNamespace.Builder serializerBuilder, ClockService<K,V> clockService)
Take a look at the other constructor for usage information. The only difference is that a BiFunction is provided that returns all nodes in the cluster, so all nodes will be sent write updates immediately.
mapName - a String identifier for the map.clusterService - the cluster serviceclusterCommunicator - the cluster communications serviceserializerBuilder - a Kryo namespace builder that can serialize
both K and VclockService - a clock service able to generate timestamps
for Kpublic EventuallyConsistentMapImpl<K,V> withTombstonesDisabled(boolean status)
public EventuallyConsistentMapImpl<K,V> withBroadcastMessageExecutor(ExecutorService executor)
executor - executor servicepublic 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 void remove(K key)
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.
remove in interface EventuallyConsistentMap<K,V>key - the key to remove the mapping forpublic void remove(K key, V value)
EventuallyConsistentMap
This actually means remove any values up to and including the timestamp
given by ClockService.getTimestamp(Object, Object).
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 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 void destroy()
EventuallyConsistentMapRuntimeException.destroy in interface EventuallyConsistentMap<K,V>Copyright © 2015. All rights reserved.