public class ReplicatedHashMap<K,V> extends AbstractMap<K,V> implements ConcurrentMap<K,V>, Receiver, ReplicatedMap<K,V>
ConcurrentMap with replication of the contents across a cluster.
Any change to the hashmap (clear(), put(), remove() etc) will transparently be propagated to all replicas in the group.
All read-only methods will always access the local replica.
Keys and values added to the hashmap must be serializable, the reason being that they will be sent across the network to all replicas of the group.
AReplicatedHashMap allows one to implement a distributed naming service in just a couple of lines.
An instance of this class will contact an existing member of the group to fetch its initial state.
| Modifier and Type | Class and Description |
|---|---|
static interface |
ReplicatedHashMap.Notification<K,V> |
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Modifier and Type | Field and Description |
|---|---|
protected RequestOptions |
call_options |
protected RpcDispatcher |
disp |
protected Log |
log |
protected ConcurrentMap<K,V> |
map
wrapped map instance
|
protected static Map<Short,Method> |
methods |
| Constructor and Description |
|---|
ReplicatedHashMap(Channel channel)
Constructs a new ReplicatedHashMap with channel.
|
ReplicatedHashMap(ConcurrentMap<K,V> map,
Channel channel)
Constructs a new ReplicatedHashMap using provided map instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
_clear() |
V |
_put(K key,
V value) |
void |
_putAll(Map<? extends K,? extends V> map) |
V |
_putIfAbsent(K key,
V value) |
V |
_remove(Object key) |
boolean |
_remove(Object key,
Object value) |
V |
_replace(K key,
V value) |
boolean |
_replace(K key,
V oldValue,
V newValue) |
void |
addNotifier(ReplicatedHashMap.Notification n) |
void |
block()
Block sending and receiving of messages until ViewAccepted is called
|
void |
clear()
Removes all of the mappings from this map.
|
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
V |
get(Object key) |
Channel |
getChannel() |
String |
getClusterName() |
Address |
getLocalAddress() |
void |
getState(OutputStream ostream)
Allows an application to write a state through a provided OutputStream.
|
long |
getTimeout()
The timeout (in milliseconds) for blocking updates
|
protected void |
init() |
boolean |
isBlockingUpdates() |
Set<K> |
keySet() |
V |
put(K key,
V value)
Maps the specified key to the specified value in this table.
|
void |
putAll(Map<? extends K,? extends V> m)
Copies all of the mappings from the specified map to this one.
|
V |
putIfAbsent(K key,
V value) |
void |
receive(Message msg)
Called when a message is received.
|
V |
remove(Object key)
Removes the key (and its corresponding value) from this map.
|
boolean |
remove(Object key,
Object value) |
void |
removeNotifier(ReplicatedHashMap.Notification n) |
V |
replace(K key,
V value) |
boolean |
replace(K key,
V oldValue,
V newValue) |
void |
setBlockingUpdates(boolean blocking_updates)
Whether updates across the cluster should be asynchronous (default) or synchronous)
|
void |
setState(InputStream istream)
Allows an application to read a state through a provided InputStream.
|
void |
setTimeout(long timeout)
Sets the cluster call timeout (until all acks have been received)
|
int |
size() |
void |
start(long state_timeout)
Fetches the state
|
void |
stop() |
void |
suspect(Address suspected_mbr)
Called when a member is suspected
|
static <K,V> ReplicatedMap<K,V> |
synchronizedMap(ReplicatedMap<K,V> map)
Creates a synchronized facade for a ReplicatedMap.
|
void |
unblock()
Called after the FLUSH protocol has unblocked previously blocked senders, and
messages can be sent again.
|
Collection<V> |
values() |
void |
viewAccepted(View new_view)
Called when a change in membership has occurred.
|
protected RpcDispatcher disp
protected final RequestOptions call_options
protected final Log log
protected ConcurrentMap<K,V> map
public ReplicatedHashMap(Channel channel)
start(long) to start this map.public ReplicatedHashMap(ConcurrentMap<K,V> map, Channel channel)
protected final void init()
public boolean isBlockingUpdates()
public void setBlockingUpdates(boolean blocking_updates)
blocking_updates - public long getTimeout()
public void setTimeout(long timeout)
timeout - The timeout (in milliseconds) for blocking updatespublic final void start(long state_timeout)
throws Exception
state_timeout - Exceptionpublic Address getLocalAddress()
public String getClusterName()
public Channel getChannel()
public void addNotifier(ReplicatedHashMap.Notification n)
public void removeNotifier(ReplicatedHashMap.Notification n)
public void stop()
public V put(K key, V value)
The value can be retrieved by calling the get method with a key that is equal to the original key.
put in interface Map<K,V>put in class AbstractMap<K,V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keyNullPointerException - if the specified key or value is nullpublic V putIfAbsent(K key, V value)
putIfAbsent in interface ConcurrentMap<K,V>NullPointerException - if the specified key or value is nullpublic void putAll(Map<? extends K,? extends V> m)
public void clear()
public V remove(Object key)
remove in interface Map<K,V>remove in class AbstractMap<K,V>key - the key that needs to be removedNullPointerException - if the specified key is nullpublic boolean remove(Object key, Object value)
remove in interface ConcurrentMap<K,V>NullPointerException - if the specified key is nullpublic boolean replace(K key, V oldValue, V newValue)
replace in interface ConcurrentMap<K,V>NullPointerException - if any of the arguments are nullpublic V replace(K key, V value)
replace in interface ConcurrentMap<K,V>NullPointerException - if the specified key or value is nullpublic V _putIfAbsent(K key, V value)
_putIfAbsent in interface ReplicatedMap<K,V>public void _putAll(Map<? extends K,? extends V> map)
_putAll in interface ReplicatedMap<K,V>Map.putAll(java.util.Map)public void _clear()
_clear in interface ReplicatedMap<K,V>public boolean _remove(Object key, Object value)
_remove in interface ReplicatedMap<K,V>public boolean _replace(K key, V oldValue, V newValue)
_replace in interface ReplicatedMap<K,V>public void receive(Message msg)
MessageListenerreceive in interface MessageListenerpublic void getState(OutputStream ostream) throws Exception
MessageListenergetState in interface MessageListenerostream - the OutputStreamException - if the streaming fails, any exceptions should be thrown so that the state requester
can re-throw them and let the caller know what happenedOutputStream.close()public void setState(InputStream istream) throws Exception
MessageListenersetState in interface MessageListeneristream - the InputStreamException - if the streaming fails, any exceptions should be thrown so that the state requester
can catch them and thus know what happenedInputStream.close()public void viewAccepted(View new_view)
MembershipListenerChannel.connect(String) returns.viewAccepted in interface MembershipListenerpublic void suspect(Address suspected_mbr)
suspect in interface MembershipListenerpublic void block()
block in interface MembershipListenerpublic void unblock()
MembershipListenerNote that during new view installation we provide guarantee that unblock invocation strictly follows view installation at some node A belonging to that view . However, some other message M may squeeze in between view and unblock callbacks. For more details see https://jira.jboss.org/jira/browse/JGRP-986
unblock in interface MembershipListenerpublic static <K,V> ReplicatedMap<K,V> synchronizedMap(ReplicatedMap<K,V> map)
map - public boolean containsKey(Object key)
containsKey in interface Map<K,V>containsKey in class AbstractMap<K,V>public boolean containsValue(Object value)
containsValue in interface Map<K,V>containsValue in class AbstractMap<K,V>public int size()
public Collection<V> values()
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.