Package org.apache.catalina.tribes.tipis
Class ReplicatedMap<K,V>
- java.lang.Object
-
- org.apache.catalina.tribes.tipis.AbstractReplicatedMap<K,V>
-
- org.apache.catalina.tribes.tipis.ReplicatedMap<K,V>
-
- Type Parameters:
K- The type of KeyV- The type of Value
- All Implemented Interfaces:
Serializable,Map<K,V>,ChannelListener,RpcCallback,Heartbeat,MembershipListener
public class ReplicatedMap<K,V> extends AbstractReplicatedMap<K,V>
All-to-all replication for a hash map implementation. Each node in the cluster will carry an identical copy of the map.
This map implementation doesn't have a background thread running to replicate changes. If you do have changes without invoking put/remove then you need to invoke one of the following methods:replicate(Object,boolean)- replicates only the object that belongs to the keyreplicate(boolean)- Scans the entire map for changes and replicates data
booleanvalue in thereplicatemethod used to decide whether to only replicate objects that implement theReplicatedMapEntryinterface or to replicate all objects. If an object doesn't implement theReplicatedMapEntryinterface each time the object gets replicated the entire object gets serialized, hence a call toreplicate(true)will replicate all objects in this map that are using this node as primary.
REMEMBER TO CALLbreakdown()when you are done with the map to avoid memory leaks.
TODO implement periodic sync/transfer thread
TODO memberDisappeared, should do nothing except change map membership by default it relocates the primary objects- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.catalina.tribes.tipis.AbstractReplicatedMap
AbstractReplicatedMap.MapEntry<K,V>, AbstractReplicatedMap.MapMessage, AbstractReplicatedMap.MapOwner
-
-
Field Summary
-
Fields inherited from class org.apache.catalina.tribes.tipis.AbstractReplicatedMap
accessTimeout, channel, channelSendOptions, currentNode, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, externalLoaders, innerMap, mapContextName, mapMembers, mapname, mapOwner, rpcChannel, rpcTimeout, sm, stateMutex, stateTransferred
-
-
Constructor Summary
Constructors Constructor Description ReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, float loadFactor, ClassLoader[] cls)Creates a new mapReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, ClassLoader[] cls)Creates a new mapReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, String mapContextName, ClassLoader[] cls)Creates a new mapReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, String mapContextName, ClassLoader[] cls, boolean terminate)Creates a new map
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intgetReplicateMessageType()protected intgetStateMessageType()voidmapMemberAdded(Member member)voidmemberDisappeared(Member member)A member was removed from the group
If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD dataprotected Member[]publishEntryInfo(Object key, Object value)publish info about a map pair (key/value) to other nodes in the cluster-
Methods inherited from class org.apache.catalina.tribes.tipis.AbstractReplicatedMap
accept, breakdown, broadcast, clear, clear, containsKey, containsValue, entrySet, entrySetFull, equals, excludeFromSet, get, getAccessTimeout, getChannel, getChannelSendOptions, getExternalLoaders, getInternal, getMapContextName, getMapMembers, getMapMembers, getMapMembersExcl, getMapOwner, getNextBackupIndex, getNextBackupNode, getRpcChannel, getRpcTimeout, getStateMutex, hashCode, heartbeat, init, inSet, isEmpty, isStateTransferred, keySet, keySetFull, leftOver, memberAdded, memberAlive, messageReceived, ping, printMap, put, put, putAll, remove, remove, replicate, replicate, replyRequest, setAccessTimeout, setChannelSendOptions, setExternalLoaders, setMapOwner, size, sizeFull, transferState, values, wrap
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
ReplicatedMap
public ReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, float loadFactor, ClassLoader[] cls)
Creates a new map- Parameters:
owner- The map ownerchannel- The channel to use for communicationtimeout- long - timeout for RPC messagesmapContextName- String - unique name for this map, to allow multiple maps per channelinitialCapacity- int - the size of this map, see HashMaploadFactor- float - load factor, see HashMapcls- Class loaders
-
ReplicatedMap
public ReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, ClassLoader[] cls)
Creates a new map- Parameters:
owner- The map ownerchannel- The channel to use for communicationtimeout- long - timeout for RPC messagesmapContextName- String - unique name for this map, to allow multiple maps per channelinitialCapacity- int - the size of this map, see HashMapcls- Class loaders
-
ReplicatedMap
public ReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, String mapContextName, ClassLoader[] cls)
Creates a new map- Parameters:
owner- The map ownerchannel- The channel to use for communicationtimeout- long - timeout for RPC messagesmapContextName- String - unique name for this map, to allow multiple maps per channelcls- Class loaders
-
ReplicatedMap
public ReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, String mapContextName, ClassLoader[] cls, boolean terminate)
Creates a new map- Parameters:
owner- The map ownerchannel- The channel to use for communicationtimeout- long - timeout for RPC messagesmapContextName- String - unique name for this map, to allow multiple maps per channelcls- Class loadersterminate- boolean - Flag for whether to terminate this map that failed to start.
-
-
Method Detail
-
getStateMessageType
protected int getStateMessageType()
- Specified by:
getStateMessageTypein classAbstractReplicatedMap<K,V>
-
getReplicateMessageType
protected int getReplicateMessageType()
- Specified by:
getReplicateMessageTypein classAbstractReplicatedMap<K,V>
-
publishEntryInfo
protected Member[] publishEntryInfo(Object key, Object value) throws ChannelException
publish info about a map pair (key/value) to other nodes in the cluster- Specified by:
publishEntryInfoin classAbstractReplicatedMap<K,V>- Parameters:
key- Objectvalue- Object- Returns:
- Member - the backup node
- Throws:
ChannelException- Cluster error
-
memberDisappeared
public void memberDisappeared(Member member)
Description copied from interface:MembershipListenerA member was removed from the group
If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD data- Specified by:
memberDisappearedin interfaceMembershipListener- Overrides:
memberDisappearedin classAbstractReplicatedMap<K,V>- Parameters:
member- Member- See Also:
Member.SHUTDOWN_PAYLOAD
-
mapMemberAdded
public void mapMemberAdded(Member member)
- Overrides:
mapMemberAddedin classAbstractReplicatedMap<K,V>
-
-