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:
- Serializable,- Map<K,,- V> - ChannelListener,- RpcCallback,- Heartbeat,- MembershipListener
- Direct Known Subclasses:
- LazyReplicatedMap,- ReplicatedMap
public abstract class AbstractReplicatedMap<K,V> 
extends Object
implements Map<K,V>, Serializable, RpcCallback, ChannelListener, MembershipListener, Heartbeat 
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic interface
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected longSince 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 ChannelReference to the channel for sending messagesprotected intOur default send optionsprotected intThe node we are currently backing up data to, this index will rotate on a round robin basisstatic final intThe default initial capacity - MUST be a power of two.static final floatThe load factor used when none specified in constructor.protected ClassLoader[]External class loaders if serialization and deserialization is to be performed successfully.protected final ConcurrentMap<K,AbstractReplicatedMap.MapEntry<K, V>> protected byte[]The Map context name makes this map unique, this allows us to have more than one map shared through one channelA list of members in our mapprotected StringReadable string of the mapContextName valueprotected AbstractReplicatedMap.MapOwnerThe owner of this map, ala a SessionManager for exampleprotected RpcChannelThe RpcChannel to send RPC messages throughprotected longTimeout for RPC messages, how long we will wait for a replyprotected static final StringManagerprotected final ObjectSimple lock object for transfersprotected booleanHas the state been transferred
- 
Constructor SummaryConstructorsConstructorDescriptionAbstractReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, float loadFactor, int channelSendOptions, ClassLoader[] cls, boolean terminate) Creates a new map.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanaccept(Serializable msg, Member sender) Invoked by the channel to determine if the listener will process this message or not.voidprotected voidbroadcast(int msgtype, boolean rpc) Helper method to broadcast a message to all members in a channelvoidclear()voidclear(boolean notify) booleancontainsKey(Object key) Returns true if the key has an entry in the map.booleancontainsValue(Object value) entrySet()Returns the entire contents of the map Map.Entry.getValue() will return a LazyReplicatedMap.MapEntry object containing all the information about the object.booleanMember[]excludeFromSet(Member[] mbrs, Member[] set) longintgetInternal(Object key) byte[]Member[]Member[]getMapMembers(HashMap<Member, Long> members) Member[]getMapMembersExcl(Member[] exclude) intprotected abstract intlongprotected abstract intinthashCode()voidHeartbeat invocation for resources cleanup etcprotected voidinit(AbstractReplicatedMap.MapOwner owner, Channel channel, String mapContextName, long timeout, int channelSendOptions, 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 transferbooleanbooleanisEmpty()booleankeySet()voidleftOver(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(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 voidprotected abstract Member[]publishEntryInfo(Object key, Object value) voidCopies all values from one map to this instanceRemoves an object from this map, it will also remove it fromvoidreplicate(boolean complete) This can be invoked by a periodic thread to replicate out any changes.voidReplicates 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 replicatedreplyRequest(Serializable msg, Member sender) Allows sending a response to a received message.voidsetAccessTimeout(long accessTimeout) voidsetChannelSendOptions(int channelSendOptions) voidsetExternalLoaders(ClassLoader[] externalLoaders) voidsetMapOwner(AbstractReplicatedMap.MapOwner mapOwner) intsize()intsizeFull()voidvalues()protected Member[]Helper methods, wraps a single member in an arrayMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Field Details- 
sm
- 
DEFAULT_INITIAL_CAPACITYpublic static final int DEFAULT_INITIAL_CAPACITYThe default initial capacity - MUST be a power of two.- See Also:
 
- 
DEFAULT_LOAD_FACTORpublic static final float DEFAULT_LOAD_FACTORThe load factor used when none specified in constructor.- See Also:
 
- 
innerMap
- 
rpcTimeoutprotected transient long rpcTimeoutTimeout for RPC messages, how long we will wait for a reply
- 
channelReference to the channel for sending messages
- 
rpcChannelThe RpcChannel to send RPC messages through
- 
mapContextNameprotected transient byte[] mapContextNameThe Map context name makes this map unique, this allows us to have more than one map shared through one channel
- 
stateTransferredprotected transient boolean stateTransferredHas the state been transferred
- 
stateMutexSimple lock object for transfers
- 
mapMembersA list of members in our map
- 
channelSendOptionsprotected transient int channelSendOptionsOur default send options
- 
mapOwnerThe owner of this map, ala a SessionManager for example
- 
externalLoadersExternal class loaders if serialization and deserialization is to be performed successfully.
- 
currentNodeprotected transient int currentNodeThe node we are currently backing up data to, this index will rotate on a round robin basis
- 
accessTimeoutprotected transient long accessTimeoutSince 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.
- 
mapnameReadable string of the mapContextName value
 
- 
- 
Constructor Details- 
AbstractReplicatedMappublic AbstractReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, float loadFactor, int channelSendOptions, 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 Details- 
getStateMessageTypeprotected abstract int getStateMessageType()
- 
getReplicateMessageTypeprotected abstract int getReplicateMessageType()
- 
wrapHelper methods, wraps a single member in an array- Parameters:
- m- Member
- Returns:
- Member[]
 
- 
initprotected void init(AbstractReplicatedMap.MapOwner owner, Channel channel, String mapContextName, long timeout, int channelSendOptions, 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.
 
- 
pingSends 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
 
- 
memberAliveWe have received a member alive notification- Parameters:
- member- Member
 
- 
broadcastHelper 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()
- 
equals
- 
getMapMembers
- 
getMapMembers
- 
getMapMembersExcl
- 
replicateReplicates 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()
- 
replyRequestDescription 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
 
- 
leftOverIf 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
 
- 
messageReceivedDescription copied from interface:ChannelListenerReceive a message from the channel- Specified by:
- messageReceivedin interface- ChannelListener
- Parameters:
- msg- Serializable
- sender- - the source of the message
 
- 
acceptDescription 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
 
- 
mapMemberAdded
- 
inSet
- 
excludeFromSet
- 
memberAddedDescription copied from interface:MembershipListenerA member was added to the group- Specified by:
- memberAddedin interface- MembershipListener
- Parameters:
- member- Member - the member that was added
 
- 
memberDisappearedDescription 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:
 
- 
getNextBackupIndexpublic int getNextBackupIndex()
- 
getNextBackupNode
- 
publishEntryInfo- Throws:
- ChannelException
 
- 
heartbeatpublic void heartbeat()Description copied from interface:HeartbeatHeartbeat invocation for resources cleanup etc
- 
removeRemoves an object from this map, it will also remove it from
- 
remove
- 
getInternal
- 
get
- 
printMap
- 
containsKeyReturns 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- Specified by:
- containsKeyin interface- Map<K,- V> 
- Parameters:
- key- Object
- Returns:
- boolean
 
- 
put
- 
put
- 
putAllCopies all values from one map to this instance
- 
clearpublic void clear()
- 
clearpublic void clear(boolean notify) 
- 
containsValue- Specified by:
- containsValuein interface- Map<K,- V> 
 
- 
entrySetFullReturns the entire contents of the map Map.Entry.getValue() will return a LazyReplicatedMap.MapEntry object containing all the information about the object.- Returns:
- Set
 
- 
keySetFull
- 
sizeFullpublic int sizeFull()
- 
entrySet
- 
keySet
- 
sizepublic int size()
- 
isEmptypublic boolean isEmpty()
- 
values
- 
getChannel
- 
getMapContextNamepublic byte[] getMapContextName()
- 
getRpcChannel
- 
getRpcTimeoutpublic long getRpcTimeout()
- 
getStateMutex
- 
isStateTransferredpublic boolean isStateTransferred()
- 
getMapOwner
- 
getExternalLoaders
- 
getChannelSendOptionspublic int getChannelSendOptions()
- 
getAccessTimeoutpublic long getAccessTimeout()
- 
setMapOwner
- 
setExternalLoaders
- 
setChannelSendOptionspublic void setChannelSendOptions(int channelSendOptions) 
- 
setAccessTimeoutpublic void setAccessTimeout(long accessTimeout) 
 
-