Package org.apache.catalina.tribes.tipis
Class LazyReplicatedMap<K,V>
- java.lang.Object
- 
- org.apache.catalina.tribes.tipis.AbstractReplicatedMap<K,V>
- 
- org.apache.catalina.tribes.tipis.LazyReplicatedMap<K,V>
 
 
- 
- Type Parameters:
- K- The type of Key
- V- The type of Value
 - All Implemented Interfaces:
- java.io.Serializable,- java.util.Map<K,V>,- ChannelListener,- RpcCallback,- Heartbeat,- MembershipListener
 
 public class LazyReplicatedMap<K,V> extends AbstractReplicatedMap<K,V> A smart implementation of a stateful replicated map. uses primary/secondary backup strategy. One node is always the primary and one node is always the backup. This map is synchronized across a cluster, and only has one backup member.
 A perfect usage for this map would be a session map for a session manager in a clustered environment.
 The only way to modify this list is to use theput, putAll, removemethods. entrySet, entrySetFull, keySet, keySetFull, returns all non modifiable sets.
 If objects (values) in the map change without invokingput()orremove()the data can be distributed using two different methods:
 replicate(boolean)andreplicate(Object, boolean)
 These two methods are very important two understand. The map can work with two set of value objects:
 1. Serializable - the entire object gets serialized each time it is replicated
 2. ReplicatedMapEntry - this interface allows for a isDirty() flag and to replicate diffs if desired.
 Implementing theReplicatedMapEntryinterface allows you to decide what objects get replicated and how much data gets replicated each time.
 If you implement a smart AOP mechanism to detect changes in underlying objects, you can replicate only those changes by implementing the ReplicatedMapEntry interface, and return true when isDiffable() is invoked.
 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
 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- See Also:
- Serialized Form
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class org.apache.catalina.tribes.tipis.AbstractReplicatedMapAbstractReplicatedMap.MapEntry<K,V>, AbstractReplicatedMap.MapMessage, AbstractReplicatedMap.MapOwner
 
- 
 - 
Field Summary- 
Fields inherited from class org.apache.catalina.tribes.tipis.AbstractReplicatedMapaccessTimeout, channel, channelSendOptions, currentNode, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, externalLoaders, innerMap, mapContextName, mapMembers, mapname, mapOwner, rpcChannel, rpcTimeout, sm, stateMutex, stateTransferred
 
- 
 - 
Constructor SummaryConstructors Constructor Description LazyReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, java.lang.String mapContextName, int initialCapacity, float loadFactor, java.lang.ClassLoader[] cls)Creates a new mapLazyReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, java.lang.String mapContextName, int initialCapacity, java.lang.ClassLoader[] cls)Creates a new mapLazyReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, java.lang.String mapContextName, java.lang.ClassLoader[] cls)Creates a new mapLazyReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, java.lang.String mapContextName, java.lang.ClassLoader[] cls, boolean terminate)Creates a new map
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intgetReplicateMessageType()protected intgetStateMessageType()protected Member[]publishEntryInfo(java.lang.Object key, java.lang.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.AbstractReplicatedMapaccept, 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, mapMemberAdded, memberAdded, memberAlive, memberDisappeared, messageReceived, ping, printMap, put, put, putAll, remove, remove, replicate, replicate, replyRequest, setAccessTimeout, setChannelSendOptions, setExternalLoaders, setMapOwner, size, sizeFull, transferState, values, wrap
 
- 
 
- 
- 
- 
Constructor Detail- 
LazyReplicatedMappublic LazyReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, java.lang.String mapContextName, int initialCapacity, float loadFactor, java.lang.ClassLoader[] cls) Creates a new map- Parameters:
- owner- The map owner
- channel- The channel to use for communication
- timeout- long - timeout for RPC messages
- mapContextName- String - unique name for this map, to allow multiple maps per channel
- initialCapacity- int - the size of this map, see HashMap
- loadFactor- float - load factor, see HashMap
- cls- Class loaders
 
 - 
LazyReplicatedMappublic LazyReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, java.lang.String mapContextName, int initialCapacity, java.lang.ClassLoader[] cls) Creates a new map- Parameters:
- owner- The map owner
- channel- The channel to use for communication
- timeout- long - timeout for RPC messages
- mapContextName- String - unique name for this map, to allow multiple maps per channel
- initialCapacity- int - the size of this map, see HashMap
- cls- Class loaders
 
 - 
LazyReplicatedMappublic LazyReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, java.lang.String mapContextName, java.lang.ClassLoader[] cls) Creates a new map- Parameters:
- owner- The map owner
- channel- The channel to use for communication
- timeout- long - timeout for RPC messages
- mapContextName- String - unique name for this map, to allow multiple maps per channel
- cls- Class loaders
 
 - 
LazyReplicatedMappublic LazyReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, java.lang.String mapContextName, java.lang.ClassLoader[] cls, boolean terminate) Creates a new map- Parameters:
- owner- The map owner
- channel- The channel to use for communication
- timeout- long - timeout for RPC messages
- mapContextName- String - unique name for this map, to allow multiple maps per channel
- cls- Class loaders
- terminate- boolean - Flag for whether to terminate this map that failed to start.
 
 
- 
 - 
Method Detail- 
getStateMessageTypeprotected int getStateMessageType() - Specified by:
- getStateMessageTypein class- AbstractReplicatedMap<K,V>
 
 - 
getReplicateMessageTypeprotected int getReplicateMessageType() - Specified by:
- getReplicateMessageTypein class- AbstractReplicatedMap<K,V>
 
 - 
publishEntryInfoprotected Member[] publishEntryInfo(java.lang.Object key, java.lang.Object value) throws ChannelException publish info about a map pair (key/value) to other nodes in the cluster- Specified by:
- publishEntryInfoin class- AbstractReplicatedMap<K,V>
- Parameters:
- key- Object
- value- Object
- Returns:
- Member - the backup node
- Throws:
- ChannelException- Cluster error
 
 
- 
 
-