FileDocCategorySizeDatePackage
ReplicatedMap.javaAPI DocApache Tomcat 6.0.146191Fri Jul 20 04:20:32 BST 2007org.apache.catalina.tribes.tipis

ReplicatedMap

public class ReplicatedMap extends AbstractReplicatedMap implements org.apache.catalina.tribes.ChannelListener, org.apache.catalina.tribes.group.RpcCallback, org.apache.catalina.tribes.MembershipListener
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 key
  • replicate(boolean) - Scans the entire map for changes and replicates data
the boolean value in the replicate method used to decide whether to only replicate objects that implement the ReplicatedMapEntry interface or to replicate all objects. If an object doesn't implement the ReplicatedMapEntry interface each time the object gets replicated the entire object gets serialized, hence a call to replicate(true) will replicate all objects in this map that are using this node as primary.

REMBER TO CALL breakdown() or finalize() when you are done with the map to avoid memory leaks.

todo
implement periodic sync/transfer thread
author
Filip Hanik
version
1.0
todo
memberDisappeared, should do nothing except change map membership by default it relocates the primary objects

Fields Summary
protected static org.apache.juli.logging.Log
log
Constructors Summary
public ReplicatedMap(Object owner, org.apache.catalina.tribes.Channel channel, long timeout, String mapContextName, int initialCapacity, float loadFactor, ClassLoader[] cls)
Creates a new map

param
channel The channel to use for communication
param
timeout long - timeout for RPC messags
param
mapContextName String - unique name for this map, to allow multiple maps per channel
param
initialCapacity int - the size of this map, see HashMap
param
loadFactor float - load factor, see HashMap


//------------------------------------------------------------------------------
//              CONSTRUCTORS / DESTRUCTORS
//------------------------------------------------------------------------------
                                                               
                  
        super(owner,channel, timeout, mapContextName, initialCapacity, loadFactor, Channel.SEND_OPTIONS_DEFAULT, cls);
    
public ReplicatedMap(Object owner, org.apache.catalina.tribes.Channel channel, long timeout, String mapContextName, int initialCapacity, ClassLoader[] cls)
Creates a new map

param
channel The channel to use for communication
param
timeout long - timeout for RPC messags
param
mapContextName String - unique name for this map, to allow multiple maps per channel
param
initialCapacity int - the size of this map, see HashMap

        super(owner,channel, timeout, mapContextName, initialCapacity, AbstractReplicatedMap.DEFAULT_LOAD_FACTOR,Channel.SEND_OPTIONS_DEFAULT, cls);
    
public ReplicatedMap(Object owner, org.apache.catalina.tribes.Channel channel, long timeout, String mapContextName, ClassLoader[] cls)
Creates a new map

param
channel The channel to use for communication
param
timeout long - timeout for RPC messags
param
mapContextName String - unique name for this map, to allow multiple maps per channel

        super(owner, channel, timeout, mapContextName,AbstractReplicatedMap.DEFAULT_INITIAL_CAPACITY, AbstractReplicatedMap.DEFAULT_LOAD_FACTOR, Channel.SEND_OPTIONS_DEFAULT, cls);
    
Methods Summary
protected intgetStateMessageType()

        return AbstractReplicatedMap.MapMessage.MSG_STATE_COPY;
    
protected org.apache.catalina.tribes.Member[]publishEntryInfo(java.lang.Object key, java.lang.Object value)
publish info about a map pair (key/value) to other nodes in the cluster

param
key Object
param
value Object
return
Member - the backup node
throws
ChannelException

        if  (! (key instanceof Serializable && value instanceof Serializable)  ) return new Member[0];
        //select a backup node
        Member[] backup = getMapMembers();

        if (backup == null || backup.length == 0) return null;

        //publish the data out to all nodes
        MapMessage msg = new MapMessage(getMapContextName(), MapMessage.MSG_COPY, false,
                                        (Serializable) key, (Serializable) value, null, backup);

        getChannel().send(getMapMembers(), msg, getChannelSendOptions());

        return backup;