Package org.apache.catalina.tribes.tipis
Class AbstractReplicatedMap<K,V>
- java.lang.Object
- 
- org.apache.catalina.tribes.tipis.AbstractReplicatedMap<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
 - Direct Known Subclasses:
- LazyReplicatedMap,- ReplicatedMap
 
 public abstract class AbstractReplicatedMap<K,V> extends java.lang.Object implements java.util.Map<K,V>, java.io.Serializable, RpcCallback, ChannelListener, MembershipListener, Heartbeat - See Also:
- Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classAbstractReplicatedMap.MapEntry<K,V>static classAbstractReplicatedMap.MapMessagestatic interfaceAbstractReplicatedMap.MapOwner
 - 
Field SummaryFields Modifier and Type Field Description protected longaccessTimeoutSince the map keeps internal membership this is the timeout for a ping message to be responded to If a remote map doesn't respond within this timeframe, its considered dead.protected ChannelchannelReference to the channel for sending messagesprotected intchannelSendOptionsOur default send optionsprotected intcurrentNodeThe node we are currently backing up data to, this index will rotate on a round robin basisstatic intDEFAULT_INITIAL_CAPACITYThe default initial capacity - MUST be a power of two.static floatDEFAULT_LOAD_FACTORThe load factor used when none specified in constructor.protected java.lang.ClassLoader[]externalLoadersExternal class loaders if serialization and deserialization is to be performed successfully.protected java.util.concurrent.ConcurrentMap<K,AbstractReplicatedMap.MapEntry<K,V>>innerMapprotected byte[]mapContextNameThe Map context name makes this map unique, this allows us to have more than one map shared through one channelprotected java.util.HashMap<Member,java.lang.Long>mapMembersA list of members in our mapprotected java.lang.StringmapnameReadable string of the mapContextName valueprotected AbstractReplicatedMap.MapOwnermapOwnerThe owner of this map, ala a SessionManager for exampleprotected RpcChannelrpcChannelThe RpcChannel to send RPC messages throughprotected longrpcTimeoutTimeout for RPC messages, how long we will wait for a replyprotected static StringManagersmprotected java.lang.ObjectstateMutexSimple lock object for transfersprotected booleanstateTransferredHas the state been transferred
 - 
Constructor SummaryConstructors Constructor Description AbstractReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, java.lang.String mapContextName, int initialCapacity, float loadFactor, int channelSendOptions, java.lang.ClassLoader[] cls, boolean terminate)Creates a new map.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanaccept(java.io.Serializable msg, Member sender)Invoked by the channel to determine if the listener will process this message or not.voidbreakdown()protected voidbroadcast(int msgtype, boolean rpc)Helper method to broadcast a message to all members in a channelvoidclear()voidclear(boolean notify)booleancontainsKey(java.lang.Object key)Returns true if the key has an entry in the map.booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<K,V>>entrySet()java.util.Set<java.util.Map.Entry<K,AbstractReplicatedMap.MapEntry<K,V>>>entrySetFull()Returns the entire contents of the map Map.Entry.getValue() will return a LazyReplicatedMap.MapEntry object containing all the information about the object.booleanequals(java.lang.Object o)Member[]excludeFromSet(Member[] mbrs, Member[] set)Vget(java.lang.Object key)longgetAccessTimeout()ChannelgetChannel()intgetChannelSendOptions()java.lang.ClassLoader[]getExternalLoaders()AbstractReplicatedMap.MapEntry<K,V>getInternal(java.lang.Object key)byte[]getMapContextName()Member[]getMapMembers()Member[]getMapMembers(java.util.HashMap<Member,java.lang.Long> members)Member[]getMapMembersExcl(Member[] exclude)AbstractReplicatedMap.MapOwnergetMapOwner()intgetNextBackupIndex()MembergetNextBackupNode()protected abstract intgetReplicateMessageType()RpcChannelgetRpcChannel()longgetRpcTimeout()protected abstract intgetStateMessageType()java.lang.ObjectgetStateMutex()inthashCode()voidheartbeat()Heartbeat invocation for resources cleanup etcprotected voidinit(AbstractReplicatedMap.MapOwner owner, Channel channel, java.lang.String mapContextName, long timeout, int channelSendOptions, java.lang.ClassLoader[] cls, boolean terminate)Initializes the map by creating the RPC channel, registering itself as a channel listener This method is also responsible for initiating the state transferbooleaninSet(Member m, Member[] set)booleanisEmpty()booleanisStateTransferred()java.util.Set<K>keySet()java.util.Set<K>keySetFull()voidleftOver(java.io.Serializable msg, Member sender)If the reply has already been sent to the requesting thread, the rpc callback can handle any data that comes in after the fact.voidmapMemberAdded(Member member)voidmemberAdded(Member member)A member was added to the groupprotected voidmemberAlive(Member member)We have received a member alive notificationvoidmemberDisappeared(Member member)A member was removed from the group
 If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD datavoidmessageReceived(java.io.Serializable msg, Member sender)Receive a message from the channelprotected voidping(long timeout)Sends a ping out to all the members in the cluster, not just map members that this map is alive.protected voidprintMap(java.lang.String header)protected abstract Member[]publishEntryInfo(java.lang.Object key, java.lang.Object value)Vput(K key, V value)Vput(K key, V value, boolean notify)voidputAll(java.util.Map<? extends K,? extends V> m)Copies all values from one map to this instanceVremove(java.lang.Object key)Removes an object from this map, it will also remove it fromVremove(java.lang.Object key, boolean notify)voidreplicate(boolean complete)This can be invoked by a periodic thread to replicate out any changes.voidreplicate(java.lang.Object key, boolean complete)Replicates any changes to the object since the last time The object has to be primary, ie, if the object is a proxy or a backup, it will not be replicatedjava.io.SerializablereplyRequest(java.io.Serializable msg, Member sender)Allows sending a response to a received message.voidsetAccessTimeout(long accessTimeout)voidsetChannelSendOptions(int channelSendOptions)voidsetExternalLoaders(java.lang.ClassLoader[] externalLoaders)voidsetMapOwner(AbstractReplicatedMap.MapOwner mapOwner)intsize()intsizeFull()voidtransferState()java.util.Collection<V>values()protected Member[]wrap(Member m)Helper methods, wraps a single member in an array
 
- 
- 
- 
Field Detail- 
smprotected static final StringManager sm 
 - 
DEFAULT_INITIAL_CAPACITYpublic static final int DEFAULT_INITIAL_CAPACITY The default initial capacity - MUST be a power of two.- See Also:
- Constant Field Values
 
 - 
DEFAULT_LOAD_FACTORpublic static final float DEFAULT_LOAD_FACTOR The load factor used when none specified in constructor.- See Also:
- Constant Field Values
 
 - 
innerMapprotected final java.util.concurrent.ConcurrentMap<K,AbstractReplicatedMap.MapEntry<K,V>> innerMap 
 - 
rpcTimeoutprotected transient long rpcTimeout Timeout for RPC messages, how long we will wait for a reply
 - 
channelprotected transient Channel channel Reference to the channel for sending messages
 - 
rpcChannelprotected transient RpcChannel rpcChannel The RpcChannel to send RPC messages through
 - 
mapContextNameprotected transient byte[] mapContextName The Map context name makes this map unique, this allows us to have more than one map shared through one channel
 - 
stateTransferredprotected transient boolean stateTransferred Has the state been transferred
 - 
stateMutexprotected final transient java.lang.Object stateMutex Simple lock object for transfers
 - 
mapMembersprotected final transient java.util.HashMap<Member,java.lang.Long> mapMembers A list of members in our map
 - 
channelSendOptionsprotected transient int channelSendOptions Our default send options
 - 
mapOwnerprotected transient AbstractReplicatedMap.MapOwner mapOwner The owner of this map, ala a SessionManager for example
 - 
externalLoadersprotected transient java.lang.ClassLoader[] externalLoaders External class loaders if serialization and deserialization is to be performed successfully.
 - 
currentNodeprotected transient int currentNode The node we are currently backing up data to, this index will rotate on a round robin basis
 - 
accessTimeoutprotected transient long accessTimeout Since the map keeps internal membership this is the timeout for a ping message to be responded to If a remote map doesn't respond within this timeframe, its considered dead.
 - 
mapnameprotected transient java.lang.String mapname Readable string of the mapContextName value
 
- 
 - 
Constructor Detail- 
AbstractReplicatedMappublic AbstractReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, java.lang.String mapContextName, int initialCapacity, float loadFactor, int channelSendOptions, 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
- initialCapacity- int - the size of this map, see HashMap
- loadFactor- float - load factor, see HashMap
- channelSendOptions- Send options
- cls- - a list of classloaders to be used for deserialization of objects.
- terminate- - Flag for whether to terminate this map that failed to start.
 
 
- 
 - 
Method Detail- 
getStateMessageTypeprotected abstract int getStateMessageType() 
 - 
getReplicateMessageTypeprotected abstract int getReplicateMessageType() 
 - 
wrapprotected Member[] wrap(Member m) Helper methods, wraps a single member in an array- Parameters:
- m- Member
- Returns:
- Member[]
 
 - 
initprotected void init(AbstractReplicatedMap.MapOwner owner, Channel channel, java.lang.String mapContextName, long timeout, int channelSendOptions, java.lang.ClassLoader[] cls, boolean terminate) Initializes the map by creating the RPC channel, registering itself as a channel listener This method is also responsible for initiating the state transfer- Parameters:
- owner- Object
- channel- Channel
- mapContextName- String
- timeout- long
- channelSendOptions- int
- cls- ClassLoader[]
- terminate- - Flag for whether to terminate this map that failed to start.
 
 - 
pingprotected void ping(long timeout) throws ChannelExceptionSends a ping out to all the members in the cluster, not just map members that this map is alive.- Parameters:
- timeout- long
- Throws:
- ChannelException- Send error
 
 - 
memberAliveprotected void memberAlive(Member member) We have received a member alive notification- Parameters:
- member- Member
 
 - 
broadcastprotected void broadcast(int msgtype, boolean rpc) throws ChannelExceptionHelper method to broadcast a message to all members in a channel- Parameters:
- msgtype- int
- rpc- boolean
- Throws:
- ChannelException- Send error
 
 - 
breakdownpublic void breakdown() 
 - 
hashCodepublic int hashCode() - Specified by:
- hashCodein interface- ChannelListener
- Specified by:
- hashCodein interface- java.util.Map<K,V>
- Overrides:
- hashCodein class- java.lang.Object
- Returns:
- int
- See Also:
- Object.hashCode()
 
 - 
equalspublic boolean equals(java.lang.Object o) - Specified by:
- equalsin interface- ChannelListener
- Specified by:
- equalsin interface- java.util.Map<K,V>
- Overrides:
- equalsin class- java.lang.Object
- Parameters:
- o- Object
- Returns:
- boolean
- See Also:
- Object.equals(Object)
 
 - 
getMapMemberspublic Member[] getMapMembers() 
 - 
replicatepublic void replicate(java.lang.Object key, boolean complete)Replicates any changes to the object since the last time The object has to be primary, ie, if the object is a proxy or a backup, it will not be replicated- Parameters:
- key- The object to replicate
- complete- - if set to true, the object is replicated to its backup if set to false, only objects that implement ReplicatedMapEntry and the isDirty() returns true will be replicated
 
 - 
replicatepublic void replicate(boolean complete) This can be invoked by a periodic thread to replicate out any changes. For maps that don't store objects that implement ReplicatedMapEntry, this method should be used infrequently to avoid large amounts of data transfer- Parameters:
- complete- boolean
 
 - 
transferStatepublic void transferState() 
 - 
replyRequestpublic java.io.Serializable replyRequest(java.io.Serializable msg, Member sender)Description copied from interface:RpcCallbackAllows sending a response to a received message.- Specified by:
- replyRequestin interface- RpcCallback
- Parameters:
- msg- Serializable
- sender- Member
- Returns:
- Serializable - null if no reply should be sent
 
 - 
leftOverpublic void leftOver(java.io.Serializable msg, Member sender)If the reply has already been sent to the requesting thread, the rpc callback can handle any data that comes in after the fact.- Specified by:
- leftOverin interface- RpcCallback
- Parameters:
- msg- Serializable
- sender- Member
 
 - 
messageReceivedpublic void messageReceived(java.io.Serializable msg, Member sender)Description copied from interface:ChannelListenerReceive a message from the channel- Specified by:
- messageReceivedin interface- ChannelListener
- Parameters:
- msg- Serializable
- sender- - the source of the message
 
 - 
acceptpublic boolean accept(java.io.Serializable msg, Member sender)Description copied from interface:ChannelListenerInvoked by the channel to determine if the listener will process this message or not.- Specified by:
- acceptin interface- ChannelListener
- Parameters:
- msg- Serializable
- sender- Member
- Returns:
- boolean
 
 - 
mapMemberAddedpublic void mapMemberAdded(Member member) 
 - 
memberAddedpublic void memberAdded(Member member) Description copied from interface:MembershipListenerA member was added to the group- Specified by:
- memberAddedin interface- MembershipListener
- Parameters:
- member- Member - the member that was added
 
 - 
memberDisappearedpublic 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 interface- MembershipListener
- Parameters:
- member- Member
- See Also:
- Member.SHUTDOWN_PAYLOAD
 
 - 
getNextBackupIndexpublic int getNextBackupIndex() 
 - 
getNextBackupNodepublic Member getNextBackupNode() 
 - 
publishEntryInfoprotected abstract Member[] publishEntryInfo(java.lang.Object key, java.lang.Object value) throws ChannelException - Throws:
- ChannelException
 
 - 
heartbeatpublic void heartbeat() Description copied from interface:HeartbeatHeartbeat invocation for resources cleanup etc
 - 
removepublic V remove(java.lang.Object key) Removes an object from this map, it will also remove it from
 - 
removepublic V remove(java.lang.Object key, boolean notify) 
 - 
getInternalpublic AbstractReplicatedMap.MapEntry<K,V> getInternal(java.lang.Object key) 
 - 
printMapprotected void printMap(java.lang.String header) 
 - 
containsKeypublic boolean containsKey(java.lang.Object key) Returns true if the key has an entry in the map. The entry can be a proxy or a backup entry, invokingget(key)will make this entry primary for the group
 - 
putAllpublic void putAll(java.util.Map<? extends K,? extends V> m) Copies all values from one map to this instance
 - 
clearpublic void clear(boolean notify) 
 - 
containsValuepublic boolean containsValue(java.lang.Object value) 
 - 
entrySetFullpublic java.util.Set<java.util.Map.Entry<K,AbstractReplicatedMap.MapEntry<K,V>>> entrySetFull() Returns the entire contents of the map Map.Entry.getValue() will return a LazyReplicatedMap.MapEntry object containing all the information about the object.- Returns:
- Set
 
 - 
keySetFullpublic java.util.Set<K> keySetFull() 
 - 
sizeFullpublic int sizeFull() 
 - 
valuespublic java.util.Collection<V> values() 
 - 
getChannelpublic Channel getChannel() 
 - 
getMapContextNamepublic byte[] getMapContextName() 
 - 
getRpcChannelpublic RpcChannel getRpcChannel() 
 - 
getRpcTimeoutpublic long getRpcTimeout() 
 - 
getStateMutexpublic java.lang.Object getStateMutex() 
 - 
isStateTransferredpublic boolean isStateTransferred() 
 - 
getMapOwnerpublic AbstractReplicatedMap.MapOwner getMapOwner() 
 - 
getExternalLoaderspublic java.lang.ClassLoader[] getExternalLoaders() 
 - 
getChannelSendOptionspublic int getChannelSendOptions() 
 - 
getAccessTimeoutpublic long getAccessTimeout() 
 - 
setMapOwnerpublic void setMapOwner(AbstractReplicatedMap.MapOwner mapOwner) 
 - 
setExternalLoaderspublic void setExternalLoaders(java.lang.ClassLoader[] externalLoaders) 
 - 
setChannelSendOptionspublic void setChannelSendOptions(int channelSendOptions) 
 - 
setAccessTimeoutpublic void setAccessTimeout(long accessTimeout) 
 
- 
 
-