org.jboss.ha.framework.server
Class DistributedReplicantManagerImpl

java.lang.Object
  extended byorg.jboss.ha.framework.server.DistributedReplicantManagerImpl
All Implemented Interfaces:
DistributedReplicantManager (src) , DistributedReplicantManagerImplMBean (src) , HAPartition.HAMembershipExtendedListener (src) , HAPartition.HAMembershipListener (src) , HAPartition.HAPartitionStateTransfer (src)

public class DistributedReplicantManagerImpl
extends java.lang.Object
implements DistributedReplicantManagerImplMBean (src) , HAPartition.HAMembershipExtendedListener (src) , HAPartition.HAPartitionStateTransfer (src)

This class manages replicated objects.


Nested Class Summary
protected  class DistributedReplicantManagerImpl.MembersPublisher (src)
           
protected  class DistributedReplicantManagerImpl.MergeMembers (src)
           
 
Nested classes inherited from class org.jboss.ha.framework.interfaces.DistributedReplicantManager (src)
DistributedReplicantManager.ReplicantListener (src)
 
Field Summary
protected  java.lang.Class[] add_types
           
protected  java.util.HashMap intraviewIdCache
           
protected  ObjectName (src) jmxName
           
protected  java.util.HashMap keyListeners
           
protected  java.util.HashMap localReplicants
           
protected  Logger (src) log
           
protected  MBeanServer (src) mbeanserver
           
protected  java.lang.String nodeName
           
protected  HAPartition (src) partition
           
protected  Latch partitionNameKnown
           
protected  java.lang.Class[] remove_types
           
protected  java.util.HashMap replicants
           
protected static java.lang.String SERVICE_NAME
           
protected static int threadID
           
protected  boolean trace
           
 
Constructor Summary
DistributedReplicantManagerImpl(HAPartition (src)  partition, MBeanServer (src)  server)
          This class manages replicated objects through the given partition
 
Method Summary
 void _add(java.lang.String key, java.lang.String nodeName, java.io.Serializable replicant)
          cluster callback called when a new replicant is added on another node
 void _remove(java.lang.String key, java.lang.String nodeName)
          cluster callback called when a replicant is removed by another node
 void add(java.lang.String key, java.io.Serializable replicant)
          Add a replicant, it will be attached to this cluster node
protected  void addReplicant(java.util.HashMap map, java.lang.String key, java.lang.String nodeName, java.io.Serializable replicant)
          Logic for adding replicant to any map.
protected  void addReplicant(java.lang.String key, java.lang.String nodeName, java.io.Serializable replicant)
          Add a replicant to the replicants map.
protected  int calculateReplicantsHash(java.util.List members)
           
protected  void cleanupKeyListeners()
           
 java.util.Collection getAllServices()
          Return a list of all services that have a least one replicant.
 java.io.Serializable getCurrentState()
          Called when a new node need to be initialized.
protected  java.util.Vector getKeysReplicatedByNode(java.lang.String nodeName)
           
 int getReplicantsViewId(java.lang.String key)
          Returns an id corresponding to the current view of this set of replicants.
 void init()
           
 boolean isMasterReplica(java.lang.String key)
          Indicates if the current node is the master replica for this given key.
 java.lang.String listContent()
           
 java.lang.String listXmlContent()
           
 java.io.Serializable lookupLocalReplicant(java.lang.String key)
          Lookup the replicant attached to this cluster node
 java.lang.Object[] lookupLocalReplicants()
          Cluster callback called when a node wants to know our complete list of local replicants
 java.util.List lookupReplicants(java.lang.String key)
          Return a list of all replicants.
 java.util.List lookupReplicantsNodeNames(java.lang.String key)
          Return a list of all replicants node names.
 void membershipChanged(java.util.Vector deadMembers, java.util.Vector newMembers, java.util.Vector allMembers)
          Called when a new partition topology occurs.
 void membershipChangedDuringMerge(java.util.Vector deadMembers, java.util.Vector newMembers, java.util.Vector allMembers, java.util.Vector originatingGroups)
          Extends HAMembershipListener to receive a specific callback when a network-partition merge occurs.
protected  void mergeMembers()
           
protected static int nextThreadID()
           
protected  void notifyKeyListeners(java.lang.String key, java.util.List newReplicants)
          Notifies, through a callback, the listeners for a given replicant that the set of replicants has changed
protected  void purgeDeadMembers(java.util.Vector deadMembers)
          get rid of dead members from replicant list return true if anything was purged.
 void registerListener(java.lang.String key, DistributedReplicantManager.ReplicantListener (src)  subscriber)
          Subscribe a new listener ReplicantListener for replicants change
 void remove(java.lang.String key)
          Remove the entire key from the ReplicationService
protected  boolean removeReplicant(java.lang.String key, java.lang.String nodeName)
           
protected  boolean replicantEntryAlreadyExists(java.util.HashMap map, java.lang.String key, java.lang.String nodeName)
          Indicates if the a replicant already exists for a given key/node pair in the give data structure
protected  boolean replicantEntryAlreadyExists(java.lang.String key, java.lang.String nodeName)
          Indicates if the a replicant already exists for a given key/node pair
protected  void republishLocalReplicants()
           
 void setCurrentState(java.io.Serializable newState)
          This callback method is called when a new service starts on a new node: the state that it should hold is transfered to it through this callback
 void start()
           
 void stop()
           
 void unregisterListener(java.lang.String key, DistributedReplicantManager.ReplicantListener (src)  subscriber)
          Unsubscribe a listener ReplicantListener that had subscribed for replicants changes
protected  int updateReplicantsHashId(java.lang.String key)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVICE_NAME

protected static final java.lang.String SERVICE_NAME
See Also:
Constant Field Values (src)

threadID

protected static int threadID

localReplicants

protected java.util.HashMap localReplicants

replicants

protected java.util.HashMap replicants

keyListeners

protected java.util.HashMap keyListeners

intraviewIdCache

protected java.util.HashMap intraviewIdCache

partition

protected HAPartition (src)  partition

log

protected Logger (src)  log

mbeanserver

protected MBeanServer (src)  mbeanserver

jmxName

protected ObjectName (src)  jmxName

nodeName

protected java.lang.String nodeName

partitionNameKnown

protected Latch partitionNameKnown

trace

protected boolean trace

add_types

protected java.lang.Class[] add_types

remove_types

protected java.lang.Class[] remove_types
Constructor Detail

DistributedReplicantManagerImpl

public DistributedReplicantManagerImpl(HAPartition (src)  partition,
                                       MBeanServer (src)  server)
This class manages replicated objects through the given partition

Parameters:
partition - HAPartition (src) through which replicated objects will be exchanged
Method Detail

init

public void init()
          throws java.lang.Exception
Throws:
java.lang.Exception

start

public void start()
           throws java.lang.Exception
Throws:
java.lang.Exception

stop

public void stop()
          throws java.lang.Exception
Throws:
java.lang.Exception

listContent

public java.lang.String listContent()
                             throws java.lang.Exception
Specified by:
listContent in interface DistributedReplicantManagerImplMBean (src)
Throws:
java.lang.Exception

listXmlContent

public java.lang.String listXmlContent()
                                throws java.lang.Exception
Specified by:
listXmlContent in interface DistributedReplicantManagerImplMBean (src)
Throws:
java.lang.Exception

getCurrentState

public java.io.Serializable getCurrentState()
Description copied from interface: HAPartition.HAPartitionStateTransfer (src)
Called when a new node need to be initialized. This is called on any existing node to determine a current state for this service.

Specified by:
getCurrentState in interface HAPartition.HAPartitionStateTransfer (src)
Returns:
A serializable representation of the state

setCurrentState

public void setCurrentState(java.io.Serializable newState)
Description copied from interface: HAPartition.HAPartitionStateTransfer (src)
This callback method is called when a new service starts on a new node: the state that it should hold is transfered to it through this callback

Specified by:
setCurrentState in interface HAPartition.HAPartitionStateTransfer (src)
Parameters:
newState - The serialized representation of the state of the new service.

getAllServices

public java.util.Collection getAllServices()
Description copied from interface: DistributedReplicantManager (src)
Return a list of all services that have a least one replicant.

Specified by:
getAllServices in interface DistributedReplicantManager (src)
Returns:
A collection of services names (String)

membershipChangedDuringMerge

public void membershipChangedDuringMerge(java.util.Vector deadMembers,
                                         java.util.Vector newMembers,
                                         java.util.Vector allMembers,
                                         java.util.Vector originatingGroups)
Description copied from interface: HAPartition.HAMembershipExtendedListener (src)
Extends HAMembershipListener to receive a specific callback when a network-partition merge occurs. The same restriction on interaction with the JG protocol stack applies.

Specified by:
membershipChangedDuringMerge in interface HAPartition.HAMembershipExtendedListener (src)
Parameters:
deadMembers - A list of nodes that have died since the previous view
newMembers - A list of nodes that have joined the partition since the previous view
allMembers - A list of nodes that built the current view
originatingGroups - A list of list of nodes that were previously partionned and that are now merged

membershipChanged

public void membershipChanged(java.util.Vector deadMembers,
                              java.util.Vector newMembers,
                              java.util.Vector allMembers)
Description copied from interface: HAPartition.HAMembershipListener (src)
Called when a new partition topology occurs. This callback is made using the JG protocol handler thread and so you cannot execute new cluster calls that need this thread. If you need to do that implement the aynchronous version of the listener interface.

Specified by:
membershipChanged in interface HAPartition.HAMembershipListener (src)
Parameters:
deadMembers - A list of nodes that have died since the previous view
newMembers - A list of nodes that have joined the partition since the previous view
allMembers - A list of nodes that built the current view

add

public void add(java.lang.String key,
                java.io.Serializable replicant)
         throws java.lang.Exception
Description copied from interface: DistributedReplicantManager (src)
Add a replicant, it will be attached to this cluster node

Specified by:
add in interface DistributedReplicantManager (src)
Parameters:
key - Replicant name. All replicas around the cluster must use the same key name.
replicant - Local data of the replicant, that is, any serializable data
Throws:
java.lang.Exception - Thrown if a cluster communication problem occurs

remove

public void remove(java.lang.String key)
            throws java.lang.Exception
Description copied from interface: DistributedReplicantManager (src)
Remove the entire key from the ReplicationService

Specified by:
remove in interface DistributedReplicantManager (src)
Parameters:
key - Name of the replicant
Throws:
java.lang.Exception - Thrown if a cluster communication problem occurs

lookupLocalReplicant

public java.io.Serializable lookupLocalReplicant(java.lang.String key)
Description copied from interface: DistributedReplicantManager (src)
Lookup the replicant attached to this cluster node

Specified by:
lookupLocalReplicant in interface DistributedReplicantManager (src)
Parameters:
key - The name of the replicant
Returns:
The local replicant for the give key name

lookupReplicants

public java.util.List lookupReplicants(java.lang.String key)
Description copied from interface: DistributedReplicantManager (src)
Return a list of all replicants.

Specified by:
lookupReplicants in interface DistributedReplicantManager (src)
Parameters:
key - The replicant name
Returns:
An array of serialized replicants available around the cluster for the given key

lookupReplicantsNodeNames

public java.util.List lookupReplicantsNodeNames(java.lang.String key)
Description copied from interface: DistributedReplicantManager (src)
Return a list of all replicants node names.

Specified by:
lookupReplicantsNodeNames in interface DistributedReplicantManager (src)
Parameters:
key - The replicant name
Returns:
An array of replicants node names available around the cluster for the given key

registerListener

public void registerListener(java.lang.String key,
                             DistributedReplicantManager.ReplicantListener (src)  subscriber)
Description copied from interface: DistributedReplicantManager (src)
Subscribe a new listener DistributedReplicantManager.ReplicantListener (src) for replicants change

Specified by:
registerListener in interface DistributedReplicantManager (src)
Parameters:
key - Name of the replicant, must be identical cluster-wide for all identical replicants
subscriber - The subsribing DistributedReplicantManager.ReplicantListener (src)

unregisterListener

public void unregisterListener(java.lang.String key,
                               DistributedReplicantManager.ReplicantListener (src)  subscriber)
Description copied from interface: DistributedReplicantManager (src)
Unsubscribe a listener DistributedReplicantManager.ReplicantListener (src) that had subscribed for replicants changes

Specified by:
unregisterListener in interface DistributedReplicantManager (src)
Parameters:
key - Name of the replicant, must be identical cluster-wide for all identical replicants
subscriber - The unsubscribing DistributedReplicantManager.ReplicantListener (src)

getReplicantsViewId

public int getReplicantsViewId(java.lang.String key)
Description copied from interface: DistributedReplicantManager (src)
Returns an id corresponding to the current view of this set of replicants.

Specified by:
getReplicantsViewId in interface DistributedReplicantManager (src)
Parameters:
key - The replicant name
Returns:
A view id (doesn't grow sequentially)

isMasterReplica

public boolean isMasterReplica(java.lang.String key)
Description copied from interface: DistributedReplicantManager (src)
Indicates if the current node is the master replica for this given key.

Specified by:
isMasterReplica in interface DistributedReplicantManager (src)
Parameters:
key - The replicant name
Returns:
True if this node is the master

_add

public void _add(java.lang.String key,
                 java.lang.String nodeName,
                 java.io.Serializable replicant)
cluster callback called when a new replicant is added on another node

Parameters:
key - Replicant key
nodeName - Node that add the current replicant
replicant - Serialized representation of the replicant

_remove

public void _remove(java.lang.String key,
                    java.lang.String nodeName)
cluster callback called when a replicant is removed by another node

Parameters:
key - Name of the replicant key
nodeName - Node that wants to remove its replicant for the give key

removeReplicant

protected boolean removeReplicant(java.lang.String key,
                                  java.lang.String nodeName)
                           throws java.lang.Exception
Throws:
java.lang.Exception

lookupLocalReplicants

public java.lang.Object[] lookupLocalReplicants()
                                         throws java.lang.Exception
Cluster callback called when a node wants to know our complete list of local replicants

Returns:
A java array of size 2 containing the name of our node in this cluster and the serialized representation of our state
Throws:
java.lang.Exception - Thrown if a cluster communication exception occurs

calculateReplicantsHash

protected int calculateReplicantsHash(java.util.List members)

updateReplicantsHashId

protected int updateReplicantsHashId(java.lang.String key)

addReplicant

protected void addReplicant(java.lang.String key,
                            java.lang.String nodeName,
                            java.io.Serializable replicant)
Add a replicant to the replicants map.

Parameters:
key - replicant key name
nodeName - name of the node that adds this replicant
replicant - Serialized representation of the replica

addReplicant

protected void addReplicant(java.util.HashMap map,
                            java.lang.String key,
                            java.lang.String nodeName,
                            java.io.Serializable replicant)
Logic for adding replicant to any map.

Parameters:
map - structure in which adding the new replicant
key - name of the replicant key
nodeName - name of the node adding the replicant
replicant - serialized representation of the replicant that is added

getKeysReplicatedByNode

protected java.util.Vector getKeysReplicatedByNode(java.lang.String nodeName)

replicantEntryAlreadyExists

protected boolean replicantEntryAlreadyExists(java.lang.String key,
                                              java.lang.String nodeName)
Indicates if the a replicant already exists for a given key/node pair

Parameters:
key - replicant key name
nodeName - name of the node
Returns:
a boolean indicating if a replicant for the given node exists for the given key

replicantEntryAlreadyExists

protected boolean replicantEntryAlreadyExists(java.util.HashMap map,
                                              java.lang.String key,
                                              java.lang.String nodeName)
Indicates if the a replicant already exists for a given key/node pair in the give data structure


notifyKeyListeners

protected void notifyKeyListeners(java.lang.String key,
                                  java.util.List newReplicants)
Notifies, through a callback, the listeners for a given replicant that the set of replicants has changed

Parameters:
key - The replicant key name
newReplicants - The new list of replicants

republishLocalReplicants

protected void republishLocalReplicants()

mergeMembers

protected void mergeMembers()

purgeDeadMembers

protected void purgeDeadMembers(java.util.Vector deadMembers)
get rid of dead members from replicant list return true if anything was purged.


cleanupKeyListeners

protected void cleanupKeyListeners()

nextThreadID

protected static int nextThreadID()