com.hazelcast.replicatedmap.impl
Class ReplicatedMapProxy<K,V>

java.lang.Object
  extended by com.hazelcast.spi.AbstractDistributedObject
      extended by com.hazelcast.replicatedmap.impl.ReplicatedMapProxy<K,V>
Type Parameters:
K - key type
V - value type
All Implemented Interfaces:
DistributedObject, ReplicatedMap<K,V>, InitializingObject, Map<K,V>

public class ReplicatedMapProxy<K,V>
extends AbstractDistributedObject
implements ReplicatedMap<K,V>, InitializingObject

The internal ReplicatedMap implementation proxying the requests to the underlying ReplicatedRecordStore


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class com.hazelcast.spi.AbstractDistributedObject
PARTITIONING_STRATEGY
 
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.
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set<Map.Entry<K,V>> entrySet()
          Returns a Set view of the mappings contained in this map.
 V get(Object key)
           
 String getName()
          Returns the unique name for this DistributedObject.
 String getPartitionKey()
          Returns the key of the partition that this DistributedObject is assigned to.
 LocalReplicatedMapStats getReplicatedMapStats()
           
 String getServiceName()
          Returns the service name for this object.
 int hashCode()
           
 void initialize()
           
 boolean isEmpty()
           
 Set<K> keySet()
           
 V put(K key, V value)
           
 V put(K key, V value, long ttl, TimeUnit timeUnit)
          Associates a given value to the specified key and replicates it to the cluster.
 void putAll(Map<? extends K,? extends V> m)
           
 V remove(Object key)
           
 boolean removeEntryListener(String id)
          Removes the specified entry listener.
 void setPreReplicationHook(PreReplicationHook preReplicationHook)
           
 int size()
           
 boolean storageEquals(Object o)
           
 String toString()
           
 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 class com.hazelcast.spi.AbstractDistributedObject
destroy, equals, getId, getNameAsPartitionAwareData, getNodeEngine, getService, invalidate, postDestroy, throwNotActiveException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals
 
Methods inherited from interface com.hazelcast.core.DistributedObject
destroy, getId
 

Method Detail

getName

public String getName()
Description copied from interface: DistributedObject
Returns the unique name for this DistributedObject. The returned value will never be null.

Specified by:
getName in interface DistributedObject
Returns:
the unique name for this object.

getPartitionKey

public String getPartitionKey()
Description copied from interface: DistributedObject
Returns the key of the partition that this DistributedObject is assigned to. The returned value only has meaning for a non-partitioned data structure like an IAtomicLong. For a partitioned data structure like an IMap, the returned value will not be null, but otherwise undefined.

Specified by:
getPartitionKey in interface DistributedObject
Overrides:
getPartitionKey in class AbstractDistributedObject
Returns:
the partition key.

getServiceName

public String getServiceName()
Description copied from interface: DistributedObject
Returns the service name for this object.

Specified by:
getServiceName in interface DistributedObject
Specified by:
getServiceName in class AbstractDistributedObject
Returns:
the service name for this object.

size

public int size()
Specified by:
size in interface Map<K,V>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K,V>

get

public V get(Object key)
Specified by:
get in interface Map<K,V>

put

public V put(K key,
             V value)
Specified by:
put in interface Map<K,V>

put

public V put(K key,
             V value,
             long ttl,
             TimeUnit timeUnit)
Description copied from interface: ReplicatedMap

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.

Specified by:
put in interface ReplicatedMap<K,V>
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

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>

putAll

public void putAll(Map<? extends K,? extends V> m)
Specified by:
putAll in interface Map<K,V>

clear

public void clear()
Description copied from interface: ReplicatedMap

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 ReplicatedMap<K,V>
Specified by:
clear in interface Map<K,V>

removeEntryListener

public boolean removeEntryListener(String id)
Description copied from interface: ReplicatedMap
Removes the specified entry listener. Returns silently if there was no such listener added before.

Specified by:
removeEntryListener in interface ReplicatedMap<K,V>
Parameters:
id - id of the registered listener
Returns:
true if registration is removed, false otherwise

addEntryListener

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

Specified by:
addEntryListener in interface ReplicatedMap<K,V>
Parameters:
listener - entry listener

addEntryListener

public String addEntryListener(EntryListener<K,V> listener,
                               K key)
Description copied from interface: ReplicatedMap
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.

Specified by:
addEntryListener in interface ReplicatedMap<K,V>
Parameters:
listener - the entry listener
key - the key to listen to

addEntryListener

public String addEntryListener(EntryListener<K,V> listener,
                               Predicate<K,V> predicate)
Description copied from interface: ReplicatedMap
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.

Specified by:
addEntryListener in interface ReplicatedMap<K,V>
Parameters:
listener - the entry listener
predicate - the predicate for filtering entries

addEntryListener

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

Specified by:
addEntryListener in interface ReplicatedMap<K,V>
Parameters:
listener - the entry listener
predicate - the predicate for filtering entries
key - the key to listen to

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>

values

public Collection<V> values()
Description copied from interface: ReplicatedMap
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 ReplicatedMap.values(java.util.Comparator) to force reordering of the elements before returning.

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

values

public Collection<V> values(Comparator<V> comparator)
Description copied from interface: ReplicatedMap
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.

Specified by:
values in interface ReplicatedMap<K,V>
Parameters:
comparator - the Comparator to sort the returned elements
Returns:
a collection view of the values contained in this map

entrySet

public Set<Map.Entry<K,V>> entrySet()
Description copied from interface: ReplicatedMap
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 ReplicatedMap<K,V>
Specified by:
entrySet in interface Map<K,V>
Returns:
a set view of the mappings contained in this map

storageEquals

public boolean storageEquals(Object o)

hashCode

public int hashCode()
Specified by:
hashCode in interface Map<K,V>
Overrides:
hashCode in class AbstractDistributedObject

toString

public String toString()
Overrides:
toString in class AbstractDistributedObject

initialize

public void initialize()
Specified by:
initialize in interface InitializingObject

getReplicatedMapStats

public LocalReplicatedMapStats getReplicatedMapStats()

setPreReplicationHook

public void setPreReplicationHook(PreReplicationHook preReplicationHook)


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