K
- The type of KeyV
- The type of Valuepublic abstract class AbstractReplicatedMap<K,V> extends Object implements Map<K,V>, Serializable, RpcCallback, ChannelListener, MembershipListener, Heartbeat
Modifier and Type | Class and Description |
---|---|
static class |
AbstractReplicatedMap.MapEntry<K,V> |
static class |
AbstractReplicatedMap.MapMessage |
static interface |
AbstractReplicatedMap.MapOwner |
Modifier and Type | Field and Description |
---|---|
protected 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.
|
protected Channel |
channel
Reference to the channel for sending messages
|
protected int |
channelSendOptions
Our default send options
|
protected int |
currentNode
The node we are currently backing up data to, this index will rotate
on a round robin basis
|
static int |
DEFAULT_INITIAL_CAPACITY
The default initial capacity - MUST be a power of two.
|
static float |
DEFAULT_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 ConcurrentMap<K,AbstractReplicatedMap.MapEntry<K,V>> |
innerMap |
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 HashMap<Member,Long> |
mapMembers
A list of members in our map
|
protected String |
mapname
Readable string of the mapContextName value
|
protected AbstractReplicatedMap.MapOwner |
mapOwner
The owner of this map, ala a SessionManager for example
|
protected RpcChannel |
rpcChannel
The RpcChannel to send RPC messages through
|
protected long |
rpcTimeout
Timeout for RPC messages, how long we will wait for a reply
|
protected static StringManager |
sm |
protected Object |
stateMutex
Simple lock object for transfers
|
protected boolean |
stateTransferred
Has the state been transferred
|
Constructor and Description |
---|
AbstractReplicatedMap(AbstractReplicatedMap.MapOwner owner,
Channel channel,
long timeout,
String mapContextName,
int initialCapacity,
float loadFactor,
int channelSendOptions,
ClassLoader[] cls,
boolean terminate)
Creates a new map
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(Serializable msg,
Member sender)
Invoked by the channel to determine if the listener will process this message or not.
|
void |
breakdown() |
protected void |
broadcast(int msgtype,
boolean rpc)
Helper method to broadcast a message to all members in a channel
|
void |
clear() |
void |
clear(boolean notify) |
boolean |
containsKey(Object key)
Returns true if the key has an entry in the map.
|
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
Set<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.
|
boolean |
equals(Object o) |
Member[] |
excludeFromSet(Member[] mbrs,
Member[] set) |
void |
finalize() |
V |
get(Object key) |
long |
getAccessTimeout() |
Channel |
getChannel() |
int |
getChannelSendOptions() |
ClassLoader[] |
getExternalLoaders() |
AbstractReplicatedMap.MapEntry<K,V> |
getInternal(Object key) |
byte[] |
getMapContextName() |
Member[] |
getMapMembers() |
Member[] |
getMapMembers(HashMap<Member,Long> members) |
Member[] |
getMapMembersExcl(Member[] exclude) |
AbstractReplicatedMap.MapOwner |
getMapOwner() |
int |
getNextBackupIndex() |
Member |
getNextBackupNode() |
protected abstract int |
getReplicateMessageType() |
RpcChannel |
getRpcChannel() |
long |
getRpcTimeout() |
protected abstract int |
getStateMessageType() |
Object |
getStateMutex() |
int |
hashCode() |
void |
heartbeat()
Heartbeat invocation for resources cleanup etc
|
protected 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
|
boolean |
inSet(Member m,
Member[] set) |
boolean |
isEmpty() |
boolean |
isStateTransferred() |
Set<K> |
keySet() |
Set<K> |
keySetFull() |
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.
|
void |
mapMemberAdded(Member member) |
void |
memberAdded(Member member)
A member was added to the group
|
protected void |
memberAlive(Member member)
We have received a member alive notification
|
void |
memberDisappeared(Member member)
A member was removed from the group
If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD data |
void |
messageReceived(Serializable msg,
Member sender)
Receive a message from the channel
|
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.
|
protected void |
printMap(String header) |
protected abstract Member[] |
publishEntryInfo(Object key,
Object value) |
V |
put(K key,
V value) |
V |
put(K key,
V value,
boolean notify) |
void |
putAll(Map<? extends K,? extends V> m)
Copies all values from one map to this instance
|
V |
remove(Object key)
Removes an object from this map, it will also remove it from
|
V |
remove(Object key,
boolean notify) |
void |
replicate(boolean complete)
This can be invoked by a periodic thread to replicate out any changes.
|
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
|
Serializable |
replyRequest(Serializable msg,
Member sender) |
void |
setAccessTimeout(long accessTimeout) |
void |
setChannelSendOptions(int channelSendOptions) |
void |
setExternalLoaders(ClassLoader[] externalLoaders) |
void |
setMapOwner(AbstractReplicatedMap.MapOwner mapOwner) |
int |
size() |
int |
sizeFull() |
void |
transferState() |
Collection<V> |
values() |
protected Member[] |
wrap(Member m)
Helper methods, wraps a single member in an array
|
protected static final StringManager sm
public static final int DEFAULT_INITIAL_CAPACITY
public static final float DEFAULT_LOAD_FACTOR
protected final ConcurrentMap<K,AbstractReplicatedMap.MapEntry<K,V>> innerMap
protected transient long rpcTimeout
protected transient Channel channel
protected transient RpcChannel rpcChannel
protected transient byte[] mapContextName
protected transient boolean stateTransferred
protected final transient Object stateMutex
protected transient int channelSendOptions
protected transient AbstractReplicatedMap.MapOwner mapOwner
protected transient ClassLoader[] externalLoaders
protected transient int currentNode
protected transient long accessTimeout
protected transient String mapname
public AbstractReplicatedMap(AbstractReplicatedMap.MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, float loadFactor, int channelSendOptions, ClassLoader[] cls, boolean terminate)
channel
- The channel to use for communicationtimeout
- long - timeout for RPC messagesmapContextName
- String - unique name for this map, to allow multiple maps per channelinitialCapacity
- int - the size of this map, see HashMaploadFactor
- float - load factor, see HashMapcls
- - a list of classloaders to be used for deserialization of objects.terminate
- - Flag for whether to terminate this map that failed to start.protected abstract int getStateMessageType()
protected abstract int getReplicateMessageType()
protected Member[] wrap(Member m)
m
- Memberprotected void init(AbstractReplicatedMap.MapOwner owner, Channel channel, String mapContextName, long timeout, int channelSendOptions, ClassLoader[] cls, boolean terminate)
owner
- Objectchannel
- ChannelmapContextName
- Stringtimeout
- longchannelSendOptions
- intcls
- ClassLoader[]terminate
- - Flag for whether to terminate this map that failed to start.protected void ping(long timeout) throws ChannelException
timeout
- longChannelException
protected void memberAlive(Member member)
member
- Memberprotected void broadcast(int msgtype, boolean rpc) throws ChannelException
msgtype
- intrpc
- booleanChannelException
public void breakdown()
public void finalize() throws Throwable
public int hashCode()
hashCode
in interface Map<K,V>
hashCode
in interface ChannelListener
hashCode
in class Object
Object.hashCode()
public boolean equals(Object o)
equals
in interface Map<K,V>
equals
in interface ChannelListener
equals
in class Object
o
- ObjectObject.equals(Object)
public Member[] getMapMembers()
public void replicate(Object key, boolean complete)
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 replicatedpublic void replicate(boolean complete)
complete
- booleanpublic void transferState()
public Serializable replyRequest(Serializable msg, Member sender)
replyRequest
in interface RpcCallback
msg
- Serializablepublic void leftOver(Serializable msg, Member sender)
leftOver
in interface RpcCallback
msg
- Serializablesender
- Memberpublic void messageReceived(Serializable msg, Member sender)
ChannelListener
messageReceived
in interface ChannelListener
msg
- Serializablesender
- - the source of the messagepublic boolean accept(Serializable msg, Member sender)
ChannelListener
accept
in interface ChannelListener
msg
- Serializablesender
- Memberpublic void mapMemberAdded(Member member)
public void memberAdded(Member member)
MembershipListener
memberAdded
in interface MembershipListener
member
- Member - the member that was addedpublic void memberDisappeared(Member member)
MembershipListener
memberDisappeared
in interface MembershipListener
member
- MemberMember.SHUTDOWN_PAYLOAD
public int getNextBackupIndex()
public Member getNextBackupNode()
protected abstract Member[] publishEntryInfo(Object key, Object value) throws ChannelException
ChannelException
public void heartbeat()
Heartbeat
public AbstractReplicatedMap.MapEntry<K,V> getInternal(Object key)
protected void printMap(String header)
public boolean containsKey(Object key)
get(key)
will make this entry primary for the groupcontainsKey
in interface Map<K,V>
key
- Objectpublic void putAll(Map<? extends K,? extends V> m)
public void clear(boolean notify)
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
public Set<Map.Entry<K,AbstractReplicatedMap.MapEntry<K,V>>> entrySetFull()
public int sizeFull()
public Channel getChannel()
public byte[] getMapContextName()
public RpcChannel getRpcChannel()
public long getRpcTimeout()
public Object getStateMutex()
public boolean isStateTransferred()
public AbstractReplicatedMap.MapOwner getMapOwner()
public ClassLoader[] getExternalLoaders()
public int getChannelSendOptions()
public long getAccessTimeout()
public void setMapOwner(AbstractReplicatedMap.MapOwner mapOwner)
public void setExternalLoaders(ClassLoader[] externalLoaders)
public void setChannelSendOptions(int channelSendOptions)
public void setAccessTimeout(long accessTimeout)
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.