com.hazelcast.core
Interface ReplicatedMap<K,V>

Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
All Superinterfaces:
DistributedObject, Map<K,V>
All Known Implementing Classes:
ClientReplicatedMapProxy, ReplicatedMapProxy

@Beta
public interface ReplicatedMap<K,V>
extends Map<K,V>, DistributedObject

A ReplicatedMap is a map-like data structure with non-strong consistency (so-called eventually consistent) and values locally stored on every node of the cluster. When accessing values, due to the eventually consistency, it is possible to read stale data since replication is not handled in a synchronous way.

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 and the cluster again is in a consistent state.

When a new node joins the cluster, the new node initially will request existing values from older nodes and replicate them locally.

Since:
3.2

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Method Summary
 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 is used for wiping data out of the replicated maps.
 Set<Map.Entry<K,V>> entrySet()
          Returns a Set view of the mappings contained in this map.
 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 Collection view of the values contained in this map.
 Collection<V> values(Comparator<V> comparator)
          Returns a Collection view of the values contained in this map.
 
Methods inherited from interface java.util.Map
containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size
 
Methods inherited from interface com.hazelcast.core.DistributedObject
destroy, getId, getName, getPartitionKey, getServiceName
 

Method Detail

put

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.

Parameters:
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

clear

void clear()

The clear operation is used for wiping data out of the replicated maps. It is the only synchronous remote operation in this implementation, so be aware that this might be a slow operation.

If some node fails on executing the operation, it is retried for at most 3 times (on the failing nodes only). If not working after the third time, this method throws a OperationTimeoutException back to the caller.

Specified by:
clear in interface Map<K,V>
Throws:
OperationTimeoutException - thrown if clear could not executed on remote nodes

removeEntryListener

boolean removeEntryListener(String id)
Removes the specified entry listener. Returns silently if there was no such listener added before.

Parameters:
id - id of the registered listener
Returns:
true if registration is removed, false otherwise

addEntryListener

String addEntryListener(EntryListener<K,V> listener)
Adds an entry listener for this map. The listener will be notified for all map add/remove/update/evict events.

Parameters:
listener - entry listener

addEntryListener

String addEntryListener(EntryListener<K,V> listener,
                        K key)
Adds the specified entry listener for the specified key. The listener will be notified for all add/remove/update/evict events of the specified key only.

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.

Parameters:
listener - the entry listener
key - the key to listen to
Throws:
NullPointerException - if the specified key is null

addEntryListener

String addEntryListener(EntryListener<K,V> listener,
                        Predicate<K,V> predicate)
Adds an continuous entry listener for this map. The listener will be notified for map add/remove/update/evict events filtered by the given predicate.

Parameters:
listener - the entry listener
predicate - the predicate for filtering entries

addEntryListener

String addEntryListener(EntryListener<K,V> listener,
                        Predicate<K,V> predicate,
                        K key)
Adds an continuous entry listener for this map. Listener will get notified for map add/remove/update/evict events filtered by given predicate.

Parameters:
listener - the entry listener
predicate - the predicate for filtering entries
key - the key to listen to

values

Collection<V> values()
Returns a 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 in the collection, and vice-versa.
The order of the elements is not guaranteed due to the internal asynchronous replication behavior. If a specific order is needed, use values(java.util.Comparator) to force reordering of the elements before returning.

Specified by:
values in interface Map<K,V>
Returns:
a collection view of the values contained in this map

values

Collection<V> values(Comparator<V> comparator)
Returns a 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 in the collection, and vice-versa.
The order of the elements is guaranteed by executing the given Comparator before returning the elements.

Parameters:
comparator - the Comparator to sort the returned elements
Returns:
a collection view of the values contained in this map

entrySet

Set<Map.Entry<K,V>> entrySet()
Returns a Set view of the mappings contained in this map. The set is NOT backed by the map, so changes to the map are NOT reflected in the set, and vice-versa.
The order of the elements is not guaranteed due to the internal asynchronous replication behavior.

Specified by:
entrySet in interface Map<K,V>
Returns:
a set view of the mappings contained in this map


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.