K
- the type of keys maintained by this mapV
- the type of mapped valuespublic interface ReplicatedMap<K,V> extends Map<K,V>, DistributedObject
A ReplicatedMap is a map-like data structure with weak consistency and values locally stored on every node of the cluster.
Whenever a value is written asynchronously, the new value will be internally distributed to all existing cluster members, and eventually every node will have the new value.
When a new node joins the cluster, the new node initially will request existing values from older nodes and replicate them locally.
Supports QuorumQuorumConfig
since 3.10 in cluster versions 3.10 and higher.Modifier and Type | Method and Description |
---|---|
String |
addEntryListener(EntryListener<K,V> listener)
Adds an entry listener for this map.
|
String |
addEntryListener(EntryListener<K,V> listener,
K key)
Adds the specified entry listener for the specified key.
|
String |
addEntryListener(EntryListener<K,V> listener,
Predicate<K,V> predicate)
Adds an continuous entry listener for this map.
|
String |
addEntryListener(EntryListener<K,V> listener,
Predicate<K,V> predicate,
K key)
Adds an continuous entry listener for this map.
|
void |
clear()
The clear operation wipes data out of the replicated maps.
|
Set<Map.Entry<K,V>> |
entrySet()
Returns a lazy
Set view of the mappings contained in this map.A LazySet is optimized for querying speed (preventing eager deserialization and hashing on HashSet insertion) and does NOT provide all operations. |
LocalReplicatedMapStats |
getReplicatedMapStats()
Returns LocalReplicatedMapStats for this replicated map.
|
Set<K> |
keySet()
Returns a lazy
Set view of the key contained in this map.A LazySet is optimized for querying speed (preventing eager deserialization and hashing on HashSet insertion) and does NOT provide all operations. |
V |
put(K key,
V value,
long ttl,
TimeUnit timeUnit)
Associates a given value to the specified key and replicates it to the
cluster.
|
boolean |
removeEntryListener(String id)
Removes the specified entry listener.
|
Collection<V> |
values()
Returns a lazy
Collection view of the values contained in this map.A LazyCollection is optimized for querying speed (preventing eager deserialization and hashing on HashSet insertion) and does NOT provide all operations. |
Collection<V> |
values(Comparator<V> comparator)
Returns an eagerly populated
Collection view of the values contained in this map. |
compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, get, getOrDefault, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size
destroy, getName, getPartitionKey, getServiceName
V put(K key, V value, long ttl, TimeUnit timeUnit)
Associates a given value to the specified key and replicates it to the cluster. If there is an old value, it will be replaced by the specified one and returned from the call.
In addition, you have to specify a ttl and its TimeUnit
to define when the value is outdated and thus should be removed from the
replicated map.
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.ttl
- ttl to be associated with the specified key-value pair.timeUnit
- TimeUnit to be used for the ttl value.void clear()
The clear operation wipes data out of the replicated maps.
If some node fails on executing the operation, it is retried for at most 5 times (on the failing nodes only).
boolean removeEntryListener(String id)
id
- ID of the registered entry listener.String addEntryListener(EntryListener<K,V> listener)
listener
- entry listenerString addEntryListener(EntryListener<K,V> listener, K key)
Warning:
This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.listener
- the entry listener to addkey
- the key to listen toNullPointerException
- if the specified key is nullString addEntryListener(EntryListener<K,V> listener, Predicate<K,V> predicate)
listener
- the entry listener to addpredicate
- the predicate for filtering entriesString addEntryListener(EntryListener<K,V> listener, Predicate<K,V> predicate, K key)
listener
- the entry listenerpredicate
- the predicate for filtering entrieskey
- the key to listen toCollection<V> values()
Collection
view of the values contained in this map.UnsupportedOperationException
. Same is true for operations
like Collection.contains(Object)
and
Collection.containsAll(java.util.Collection)
, which would result in
very poor performance if called repeatedly (for example, in a loop). If the use
case is different from querying the data, please copy the resulting set into a
new List
or similar data structure.
ReplicatedMap<K, V> repMap = ...; // Returns a LazyCollection Collection<V> values = repMap.values(); List<V> copy = new ArrayList<V>(values); if (copy.containsAll(possibleValues)) { // ... }Due to the lazy nature of the returned set, changes to the map (addition, removal, update) might be reflected on the collection.
values(java.util.Comparator)
to force reordering of the
elements before returning.Collection<V> values(Comparator<V> comparator)
Collection
view of the values contained in this map.
The collection is NOT backed by the map, so changes to the map are
NOT reflected on the collection, and vice-versa.Comparator
before returning the elements.comparator
- the Comparator to sort the returned elements.Collection
view of the values contained in this map.Set<Map.Entry<K,V>> entrySet()
Set
view of the mappings contained in this map.UnsupportedOperationException
. Same is true for operations
like Set.contains(Object)
and
Set.containsAll(java.util.Collection)
which would result in
very poor performance if called repeatedly (for example, in a loop). If the use
case is different from querying the data, please copy the resulting set into a
new HashSet
.
ReplicatedMap<K, V> repMap = ...; // Returns a LazySet Set<Map.Entry<K, V>> entrySet = repMap.entrySet(); Set<Map.Entry<K, V>> copy = new HashSet<Map.Entry<K, V>>(entrySet);Due to the lazy nature of the returned set, changes to the map (addition, removal, update) might be reflected on the set.
Set<K> keySet()
Set
view of the key contained in this map.UnsupportedOperationException
. Same is true for operations
like Set.contains(Object)
and
Set.containsAll(java.util.Collection)
which would result in
very poor performance if called repeatedly (for example, in a loop). If the use
case is different from querying the data, please copy the resulting set into a
new HashSet
.
ReplicatedMap<K, V> repMap = ...; // Returns a LazySet Set<K> keySet = repMap.keySet(); Set<K> copy = new HashSet<K>(keySet); for (K key : possibleKeys) { if (!copy.contains(key)) return false; }Due to the lazy nature of the returned set, changes to the map (addition, removal, update) might be reflected on the set.
LocalReplicatedMapStats getReplicatedMapStats()
Copyright © 2018 Hazelcast, Inc.. All Rights Reserved.