org.apache.catalina.tribes.tipis
Class LazyReplicatedMap
java.lang.Object
java.util.AbstractMap<K,V>
java.util.concurrent.ConcurrentHashMap
org.apache.catalina.tribes.tipis.AbstractReplicatedMap
org.apache.catalina.tribes.tipis.LazyReplicatedMap
- All Implemented Interfaces:
- Serializable, ConcurrentMap, Map, ChannelListener, RpcCallback, Heartbeat, MembershipListener
public class LazyReplicatedMap
- extends AbstractReplicatedMap
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 the put, putAll, remove
methods.
entrySet, entrySetFull, keySet, keySetFull, returns all non modifiable sets.
If objects (values) in the map change without invoking put()
or remove()
the data can be distributed using two different methods:
replicate(boolean)
and replicate(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 the ReplicatedMapEntry
interface 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
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
- Version:
- 1.0
- Author:
- Filip Hanik
- See Also:
- Serialized Form
Nested classes/interfaces inherited from interface java.util.Map |
Map.Entry<K,V> |
Fields inherited from class org.apache.catalina.tribes.tipis.AbstractReplicatedMap |
accessTimeout, channel, channelSendOptions, currentNode, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, externalLoaders, mapContextName, mapMembers, mapname, mapOwner, rpcChannel, rpcTimeout, stateMutex, stateTransferred |
Constructor Summary |
LazyReplicatedMap(AbstractReplicatedMap.MapOwner owner,
Channel channel,
long timeout,
String mapContextName,
ClassLoader[] cls)
Creates a new map |
LazyReplicatedMap(AbstractReplicatedMap.MapOwner owner,
Channel channel,
long timeout,
String mapContextName,
int initialCapacity,
ClassLoader[] cls)
Creates a new map |
LazyReplicatedMap(AbstractReplicatedMap.MapOwner owner,
Channel channel,
long timeout,
String mapContextName,
int initialCapacity,
float loadFactor,
ClassLoader[] cls)
Creates a new map |
Methods inherited from class org.apache.catalina.tribes.tipis.AbstractReplicatedMap |
accept, breakdown, broadcast, clear, clear, clone, containsKey, containsValue, entrySet, entrySetFull, equals, excludeFromSet, finalize, 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 |
LazyReplicatedMap
public LazyReplicatedMap(AbstractReplicatedMap.MapOwner owner,
Channel channel,
long timeout,
String mapContextName,
int initialCapacity,
float loadFactor,
ClassLoader[] cls)
- Creates a new map
- Parameters:
channel
- The channel to use for communicationtimeout
- long - timeout for RPC messagsmapContextName
- String - unique name for this map, to allow multiple maps per channelinitialCapacity
- int - the size of this map, see HashMaploadFactor
- float - load factor, see HashMap
LazyReplicatedMap
public LazyReplicatedMap(AbstractReplicatedMap.MapOwner owner,
Channel channel,
long timeout,
String mapContextName,
int initialCapacity,
ClassLoader[] cls)
- Creates a new map
- Parameters:
channel
- The channel to use for communicationtimeout
- long - timeout for RPC messagsmapContextName
- String - unique name for this map, to allow multiple maps per channelinitialCapacity
- int - the size of this map, see HashMap
LazyReplicatedMap
public LazyReplicatedMap(AbstractReplicatedMap.MapOwner owner,
Channel channel,
long timeout,
String mapContextName,
ClassLoader[] cls)
- Creates a new map
- Parameters:
channel
- The channel to use for communicationtimeout
- long - timeout for RPC messagsmapContextName
- String - unique name for this map, to allow multiple maps per channel
getStateMessageType
protected int getStateMessageType()
- Specified by:
getStateMessageType
in class AbstractReplicatedMap
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:
publishEntryInfo
in class AbstractReplicatedMap
- Parameters:
key
- Objectvalue
- Object
- Returns:
- Member - the backup node
- Throws:
ChannelException
Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.