org.apache.catalina.tribes.tipis

Class AbstractReplicatedMap

public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements RpcCallback, ChannelListener, MembershipListener, Heartbeat

Version: 1.0

Author: Filip Hanik

Nested Class Summary
static classAbstractReplicatedMap.MapEntry
static classAbstractReplicatedMap.MapMessage
static interfaceAbstractReplicatedMap.MapOwner
Field Summary
protected longaccessTimeout
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.
protected Channelchannel
Reference to the channel for sending messages
protected intchannelSendOptions
Our default send options
protected intcurrentNode
The node we are currently backing up data to, this index will rotate on a round robin basis
static intDEFAULT_INITIAL_CAPACITY
The default initial capacity - MUST be a power of two.
static floatDEFAULT_LOAD_FACTOR
The load factor used when none specified in constructor.
protected ClassLoader[]externalLoaders
External class loaders if serialization and deserialization is to be performed successfully.
protected static Loglog
protected byte[]mapContextName
The Map context name makes this map unique, this allows us to have more than one map shared through one channel
protected HashMapmapMembers
A list of members in our map
protected Stringmapname
Readable string of the mapContextName value
protected AbstractReplicatedMap.MapOwnermapOwner
The owner of this map, ala a SessionManager for example
protected RpcChannelrpcChannel
The RpcChannel to send RPC messages through
protected longrpcTimeout
Timeout for RPC messages, how long we will wait for a reply
protected ObjectstateMutex
Simple lock object for transfers
protected booleanstateTransferred
Has the state been transferred
Constructor Summary
AbstractReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, float loadFactor, int channelSendOptions, ClassLoader[] cls)
Creates a new map
Method Summary
booleanaccept(Serializable msg, Member sender)
voidbreakdown()
protected voidbroadcast(int msgtype, boolean rpc)
Helper method to broadcast a message to all members in a channel
voidclear()
voidclear(boolean notify)
Objectclone()
booleancontainsKey(Object key)
Returns true if the key has an entry in the map.
booleancontainsValue(Object value)
SetentrySet()
SetentrySetFull()
Returns the entire contents of the map Map.Entry.getValue() will return a LazyReplicatedMap.MapEntry object containing all the information about the object.
booleanequals(Object o)
Member[]excludeFromSet(Member[] mbrs, Member[] set)
voidfinalize()
Objectget(Object key)
longgetAccessTimeout()
ChannelgetChannel()
intgetChannelSendOptions()
ClassLoader[]getExternalLoaders()
AbstractReplicatedMap.MapEntrygetInternal(Object key)
byte[]getMapContextName()
Member[]getMapMembers(HashMap members)
Member[]getMapMembers()
Member[]getMapMembersExcl(Member[] exclude)
AbstractReplicatedMap.MapOwnergetMapOwner()
intgetNextBackupIndex()
MembergetNextBackupNode()
RpcChannelgetRpcChannel()
longgetRpcTimeout()
protected abstract intgetStateMessageType()
ObjectgetStateMutex()
inthashCode()
voidheartbeat()
protected voidinit(AbstractReplicatedMap.MapOwner owner, Channel channel, String mapContextName, long timeout, int channelSendOptions, ClassLoader[] cls)
Initializes the map by creating the RPC channel, registering itself as a channel listener This method is also responsible for initiating the state transfer
booleaninSet(Member m, Member[] set)
booleanisEmpty()
booleanisStateTransferred()
SetkeySet()
SetkeySetFull()
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)
protected voidmemberAlive(Member member)
We have received a member alive notification
voidmemberDisappeared(Member member)
voidmessageReceived(Serializable msg, Member sender)
protected 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(String header)
protected abstract Member[]publishEntryInfo(Object key, Object value)
Objectput(Object key, Object value)
Objectput(Object key, Object value, boolean notify)
voidputAll(Map m)
Copies all values from one map to this instance
Objectremove(Object key)
Removes an object from this map, it will also remove it from
Objectremove(Object key, boolean notify)
protected booleanremoveEldestEntry(Entry eldest)
voidreplicate(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
voidreplicate(boolean complete)
This can be invoked by a periodic thread to replicate out any changes.
SerializablereplyRequest(Serializable msg, Member sender)
voidsetAccessTimeout(long accessTimeout)
voidsetChannelSendOptions(int channelSendOptions)
voidsetExternalLoaders(ClassLoader[] externalLoaders)
voidsetMapOwner(AbstractReplicatedMap.MapOwner mapOwner)
intsize()
intsizeFull()
voidtransferState()
Collectionvalues()
protected Member[]wrap(Member m)
Helper methods, wraps a single member in an array

Field Detail

accessTimeout

protected 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.

channel

protected transient Channel channel
Reference to the channel for sending messages

channelSendOptions

protected transient int channelSendOptions
Our default send options

currentNode

protected transient int currentNode
The node we are currently backing up data to, this index will rotate on a round robin basis

DEFAULT_INITIAL_CAPACITY

public static final int DEFAULT_INITIAL_CAPACITY
The default initial capacity - MUST be a power of two.

DEFAULT_LOAD_FACTOR

public static final float DEFAULT_LOAD_FACTOR
The load factor used when none specified in constructor.

externalLoaders

protected transient ClassLoader[] externalLoaders
External class loaders if serialization and deserialization is to be performed successfully.

log

protected static Log log

mapContextName

protected transient byte[] mapContextName
The Map context name makes this map unique, this allows us to have more than one map shared through one channel

mapMembers

protected transient HashMap mapMembers
A list of members in our map

mapname

protected transient String mapname
Readable string of the mapContextName value

mapOwner

protected transient AbstractReplicatedMap.MapOwner mapOwner
The owner of this map, ala a SessionManager for example

rpcChannel

protected transient RpcChannel rpcChannel
The RpcChannel to send RPC messages through

rpcTimeout

protected transient long rpcTimeout
Timeout for RPC messages, how long we will wait for a reply

stateMutex

protected transient Object stateMutex
Simple lock object for transfers

stateTransferred

protected transient boolean stateTransferred
Has the state been transferred

Constructor Detail

AbstractReplicatedMap

public AbstractReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, float loadFactor, int channelSendOptions, ClassLoader[] cls)
Creates a new map

Parameters: channel The channel to use for communication timeout long - timeout for RPC messags 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 - a list of classloaders to be used for deserialization of objects.

Method Detail

accept

public boolean accept(Serializable msg, Member sender)

breakdown

public void breakdown()

broadcast

protected void broadcast(int msgtype, boolean rpc)
Helper method to broadcast a message to all members in a channel

Parameters: msgtype int rpc boolean

Throws: ChannelException

clear

public void clear()

clear

public void clear(boolean notify)

clone

public Object clone()

containsKey

public boolean containsKey(Object key)
Returns true if the key has an entry in the map. The entry can be a proxy or a backup entry, invoking get(key) will make this entry primary for the group

Parameters: key Object

Returns: boolean

containsValue

public boolean containsValue(Object value)

entrySet

public Set entrySet()

entrySetFull

public Set 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

equals

public boolean equals(Object o)

excludeFromSet

public Member[] excludeFromSet(Member[] mbrs, Member[] set)

finalize

public void finalize()

get

public Object get(Object key)

getAccessTimeout

public long getAccessTimeout()

getChannel

public Channel getChannel()

getChannelSendOptions

public int getChannelSendOptions()

getExternalLoaders

public ClassLoader[] getExternalLoaders()

getInternal

public AbstractReplicatedMap.MapEntry getInternal(Object key)

getMapContextName

public byte[] getMapContextName()

getMapMembers

public Member[] getMapMembers(HashMap members)

getMapMembers

public Member[] getMapMembers()

getMapMembersExcl

public Member[] getMapMembersExcl(Member[] exclude)

getMapOwner

public AbstractReplicatedMap.MapOwner getMapOwner()

getNextBackupIndex

public int getNextBackupIndex()

getNextBackupNode

public Member getNextBackupNode()

getRpcChannel

public RpcChannel getRpcChannel()

getRpcTimeout

public long getRpcTimeout()

getStateMessageType

protected abstract int getStateMessageType()

getStateMutex

public Object getStateMutex()

hashCode

public int hashCode()

heartbeat

public void heartbeat()

init

protected void init(AbstractReplicatedMap.MapOwner owner, Channel channel, String mapContextName, long timeout, int channelSendOptions, ClassLoader[] cls)
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[]

inSet

public boolean inSet(Member m, Member[] set)

isEmpty

public boolean isEmpty()

isStateTransferred

public boolean isStateTransferred()

keySet

public Set keySet()

keySetFull

public Set keySetFull()

leftOver

public void leftOver(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.

Parameters: msg Serializable sender Member

mapMemberAdded

public void mapMemberAdded(Member member)

memberAdded

public void memberAdded(Member member)

memberAlive

protected void memberAlive(Member member)
We have received a member alive notification

Parameters: member Member

memberDisappeared

public void memberDisappeared(Member member)

messageReceived

public void messageReceived(Serializable msg, Member sender)

ping

protected void ping(long timeout)
Sends a ping out to all the members in the cluster, not just map members that this map is alive.

Parameters: timeout long

Throws: ChannelException

printMap

protected void printMap(String header)

publishEntryInfo

protected abstract Member[] publishEntryInfo(Object key, Object value)

put

public Object put(Object key, Object value)

put

public Object put(Object key, Object value, boolean notify)

putAll

public void putAll(Map m)
Copies all values from one map to this instance

Parameters: m Map

remove

public Object remove(Object key)
Removes an object from this map, it will also remove it from

Parameters: key Object

Returns: Object

remove

public Object remove(Object key, boolean notify)

removeEldestEntry

protected boolean removeEldestEntry(Entry eldest)

replicate

public void replicate(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: 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

replicate

public 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

replyRequest

public Serializable replyRequest(Serializable msg, Member sender)

Parameters: msg Serializable

Returns: Serializable - null if no reply should be sent

UNKNOWN: implement state transfer

setAccessTimeout

public void setAccessTimeout(long accessTimeout)

setChannelSendOptions

public void setChannelSendOptions(int channelSendOptions)

setExternalLoaders

public void setExternalLoaders(ClassLoader[] externalLoaders)

setMapOwner

public void setMapOwner(AbstractReplicatedMap.MapOwner mapOwner)

size

public int size()

sizeFull

public int sizeFull()

transferState

public void transferState()

values

public Collection values()

wrap

protected Member[] wrap(Member m)
Helper methods, wraps a single member in an array

Parameters: m Member

Returns: Member[]

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.