org.jboss.ha.framework.server
Class HAPartitionImpl

java.lang.Object
  extended byorg.jgroups.blocks.RpcDispatcher
      extended byorg.jboss.ha.framework.server.HAPartitionImpl
All Implemented Interfaces:
HAPartition (src)

public class HAPartitionImpl
extends org.jgroups.blocks.RpcDispatcher
implements HAPartition (src)

This class is an abstraction class for a JGroups RPCDispatch and JChannel. It is a default implementation of HAPartition for the JGroups framework

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.jboss.ha.framework.interfaces.HAPartition (src)
HAPartition.AsynchHAMembershipExtendedListener (src) , HAPartition.AsynchHAMembershipListener (src) , HAPartition.HAMembershipExtendedListener (src) , HAPartition.HAMembershipListener (src) , HAPartition.HAPartitionStateTransfer (src)
 
Field Summary
protected  java.util.ArrayList asynchListeners
          The asynch HAMembershipListener and HAMembershipExtendedListeners
protected  java.lang.Thread asynchNotifyThread
          The Thread used to send membership change notifications asynchronously
protected  LinkedQueue asynchViewChanges
          The LinkedQueue of changes to notify asynch listeners of
protected  JChannel channel
          The JGroups partition channel
protected  Logger (src) clusterLifeCycleLog
           
protected  long currentViewId
          The current cluster view id
protected  DistributedStateImpl (src) dsManager
          The cluster state manager
 java.util.Vector history
           
protected  java.util.Vector jgmembers
           
protected  java.util.Vector jgotherMembers
           
protected  java.util.ArrayList listeners
          The HAMembershipListener and HAMembershipExtendedListeners
protected  org.jgroups.stack.IpAddress localJGAddress
          the local JG IP Address
protected  Logger (src) log
          The cluster instance log category
protected  ClusterNode (src) me
          me as a ClusterNode
protected  java.util.Vector members
          The current cluster partition members
protected  java.lang.String nodeName
          The cluster transport protocol address string
protected  java.util.Vector otherMembers
          The partition members other than this node
protected  java.lang.String partitionName
          The JChannel name
protected  DistributedReplicantManagerImpl (src) replicantManager
          The cluster replicant manager
protected  java.util.HashMap rpcHandlers
           
protected  MBeanServer (src) server
          The JMX MBeanServer to use for registrations
protected  long state_transfer_timeout
          Number of ms to wait for state
protected  java.util.HashMap stateHandlers
           
protected  long timeout
          The timeout for cluster RPC calls
 
Constructor Summary
HAPartitionImpl(java.lang.String partitionName, org.jgroups.JChannel channel, boolean deadlock_detection)
           
HAPartitionImpl(java.lang.String partitionName, org.jgroups.JChannel channel, boolean deadlock_detection, MBeanServer (src)  server)
           
 
Method Summary
protected  void bind(java.lang.String jndiName, java.lang.Object who, java.lang.Class classType, javax.naming.Context ctx)
          Helper method that binds the partition in the JNDI tree.
 void block()
           
 void callAsynchMethodOnCluster(java.lang.String objName, java.lang.String methodName, java.lang.Object[] args, boolean excludeSelf)
          Deprecated. Use callAsynchMethodOnCluster(String, String, Object[], Class[], boolean) instead
 void callAsynchMethodOnCluster(java.lang.String objName, java.lang.String methodName, java.lang.Object[] args, java.lang.Class[] types, boolean excludeSelf)
          This function is an abstraction of RpcDispatcher for asynchronous messages
 java.util.ArrayList callMethodOnCluster(java.lang.String objName, java.lang.String methodName, java.lang.Object[] args, boolean excludeSelf)
          Deprecated. Use callMethodOnCluster(String,String,Object[],Class[], boolean) instead
 java.util.ArrayList callMethodOnCluster(java.lang.String objName, java.lang.String methodName, java.lang.Object[] args, java.lang.Class[] types, boolean excludeSelf)
          This function is an abstraction of RpcDispatcher.
 java.util.ArrayList callMethodOnCluster(java.lang.String objName, java.lang.String methodName, java.lang.Object[] args, java.lang.Class[] types, boolean excludeSelf, long methodTimeout)
           
 void closePartition()
           
 ClusterNode (src) [] getClusterNodes()
          Return the member nodes that built the current view i.e.
 java.util.Vector getCurrentView()
          Return the list of member nodes that built the current view i.e.
 long getCurrentViewId()
          Each time the partition topology changes, a new view is computed.
protected  java.util.Vector getDeadMembers(java.util.Vector oldMembers, java.util.Vector newMembers)
          Helper method that returns a vector of dead members from two input vectors: new and old vectors of two views.
 DistributedReplicantManager (src) getDistributedReplicantManager()
          Accessor to the DRM that is linked to this partition.
 DistributedState (src) getDistributedStateService()
          Accessor the the DistributedState (DS) that is linked to this partition.
 long getMethodCallTimeout()
           
protected  java.util.Vector getNewMembers(java.util.Vector oldMembers, java.util.Vector allMembers)
          Helper method that returns a vector of new members from two input vectors: new and old vectors of two views.
 java.lang.String getNodeName()
          Return the name of the current name in the current partition.
 java.lang.String getPartitionName()
          The name of the partition.
 byte[] getState()
           
 long getStateTransferTimeout()
           
 java.lang.Object handle(Message req)
          Message contains MethodCall.
 void init()
           
 boolean isCurrentNodeCoordinator()
           
 void logHistory(java.lang.String message)
           
protected  void notifyListeners(java.util.ArrayList theListeners, long viewID, java.util.Vector allMembers, java.util.Vector deadMembers, java.util.Vector newMembers, java.util.Vector originatingGroups)
           
static java.lang.Object objectFromByteBuffer(byte[] buffer)
          Creates an object from a byte buffer
static byte[] objectToByteBuffer(java.lang.Object obj)
          Serializes an object into a byte buffer.
 void receive(org.jgroups.Message msg)
           
 void registerMembershipListener(HAPartition.HAMembershipListener (src)  listener)
          Subscribes to receive HAMembershipListener events.
 void registerRPCHandler(java.lang.String objName, java.lang.Object subscriber)
          The partition receives RPC calls from other nodes in the cluster and demultiplex them, according to a service name, to a particular service.
 void setMethodCallTimeout(long timeout)
           
 void setState(byte[] obj)
           
 void setStateTransferTimeout(long state_transfer_timeout)
           
 void startPartition()
           
 void subscribeToStateTransferEvents(java.lang.String objectName, HAPartition.HAPartitionStateTransfer (src)  subscriber)
          Register a service that will participate in state transfer protocol and receive callbacks
 void suspect(org.jgroups.Address suspected_mbr)
           
protected  java.util.Vector translateAddresses(java.util.Vector jgAddresses)
           
 void unregisterMembershipListener(HAPartition.HAMembershipListener (src)  listener)
          Unsubscribes from receiving HAMembershipListener events.
 void unregisterRPCHandler(java.lang.String objName, java.lang.Object subscriber)
          Unregister the service from the partition
 void unsubscribeFromStateTransferEvents(java.lang.String objectName, HAPartition.HAPartitionStateTransfer (src)  subscriber)
          Unregister a service from state transfer callbacks.
protected  void verifyNodeIsUnique(java.util.Vector javaGroupIpAddresses)
           
 void viewAccepted(View newView)
          Notification of a cluster view change.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rpcHandlers

protected java.util.HashMap rpcHandlers

stateHandlers

protected java.util.HashMap stateHandlers

listeners

protected java.util.ArrayList listeners
The HAMembershipListener and HAMembershipExtendedListeners


asynchListeners

protected java.util.ArrayList asynchListeners
The asynch HAMembershipListener and HAMembershipExtendedListeners


asynchViewChanges

protected LinkedQueue asynchViewChanges
The LinkedQueue of changes to notify asynch listeners of


asynchNotifyThread

protected java.lang.Thread asynchNotifyThread
The Thread used to send membership change notifications asynchronously


members

protected java.util.Vector members
The current cluster partition members


jgmembers

protected java.util.Vector jgmembers

history

public java.util.Vector history

otherMembers

protected java.util.Vector otherMembers
The partition members other than this node


jgotherMembers

protected java.util.Vector jgotherMembers

partitionName

protected java.lang.String partitionName
The JChannel name


localJGAddress

protected org.jgroups.stack.IpAddress localJGAddress
the local JG IP Address


nodeName

protected java.lang.String nodeName
The cluster transport protocol address string


me

protected ClusterNode (src)  me
me as a ClusterNode


timeout

protected long timeout
The timeout for cluster RPC calls


channel

protected JChannel channel
The JGroups partition channel


replicantManager

protected DistributedReplicantManagerImpl (src)  replicantManager
The cluster replicant manager


dsManager

protected DistributedStateImpl (src)  dsManager
The cluster state manager


log

protected Logger (src)  log
The cluster instance log category


clusterLifeCycleLog

protected Logger (src)  clusterLifeCycleLog

currentViewId

protected long currentViewId
The current cluster view id


server

protected MBeanServer (src)  server
The JMX MBeanServer to use for registrations


state_transfer_timeout

protected long state_transfer_timeout
Number of ms to wait for state

Constructor Detail

HAPartitionImpl

public HAPartitionImpl(java.lang.String partitionName,
                       org.jgroups.JChannel channel,
                       boolean deadlock_detection,
                       MBeanServer (src)  server)
                throws java.lang.Exception

HAPartitionImpl

public HAPartitionImpl(java.lang.String partitionName,
                       org.jgroups.JChannel channel,
                       boolean deadlock_detection)
                throws java.lang.Exception
Method Detail

objectFromByteBuffer

public static java.lang.Object objectFromByteBuffer(byte[] buffer)
                                             throws java.lang.Exception
Creates an object from a byte buffer

Throws:
java.lang.Exception

objectToByteBuffer

public static byte[] objectToByteBuffer(java.lang.Object obj)
                                 throws java.lang.Exception
Serializes an object into a byte buffer. The object has to implement interface Serializable or Externalizable

Throws:
java.lang.Exception

getStateTransferTimeout

public long getStateTransferTimeout()

setStateTransferTimeout

public void setStateTransferTimeout(long state_transfer_timeout)

getMethodCallTimeout

public long getMethodCallTimeout()

setMethodCallTimeout

public void setMethodCallTimeout(long timeout)

init

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

startPartition

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

closePartition

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

getState

public byte[] getState()

setState

public void setState(byte[] obj)

receive

public void receive(org.jgroups.Message msg)

suspect

public void suspect(org.jgroups.Address suspected_mbr)

block

public void block()

viewAccepted

public void viewAccepted(View newView)
Notification of a cluster view change. This is done from the JG protocol handlder thread and we must be careful to not unduly block this thread. Because of this there are two types of listeners, synchronous and asynchronous. The synchronous listeners are messaged with the view change event using the calling thread while the asynchronous listeners are messaged using a seperate thread.

Parameters:
newView -

getNodeName

public java.lang.String getNodeName()
Description copied from interface: HAPartition (src)
Return the name of the current name in the current partition. The name is dynamically determined by the partition.

Specified by:
getNodeName in interface HAPartition (src)
Returns:
The partition name

getPartitionName

public java.lang.String getPartitionName()
Description copied from interface: HAPartition (src)
The name of the partition. Either set when creating the partition (MBEAN definition) or uses the default name

Specified by:
getPartitionName in interface HAPartition (src)
Returns:
Name of the current partition

getDistributedReplicantManager

public DistributedReplicantManager (src)  getDistributedReplicantManager()
Description copied from interface: HAPartition (src)
Accessor to the DRM that is linked to this partition.

Specified by:
getDistributedReplicantManager in interface HAPartition (src)
Returns:
the DRM linked to this partition

getDistributedStateService

public DistributedState (src)  getDistributedStateService()
Description copied from interface: HAPartition (src)
Accessor the the DistributedState (DS) that is linked to this partition.

Specified by:
getDistributedStateService in interface HAPartition (src)
Returns:
the DistributedState service

getCurrentViewId

public long getCurrentViewId()
Description copied from interface: HAPartition (src)
Each time the partition topology changes, a new view is computed. A view is a list of members, the first member being the coordinator of the view. Each view also has a distinct identifier.

Specified by:
getCurrentViewId in interface HAPartition (src)
Returns:
The identifier of the current view

getCurrentView

public java.util.Vector getCurrentView()
Description copied from interface: HAPartition (src)
Return the list of member nodes that built the current view i.e. the current partition.

Specified by:
getCurrentView in interface HAPartition (src)
Returns:
An array of Strings containing the node names

getClusterNodes

public ClusterNode (src) [] getClusterNodes()
Description copied from interface: HAPartition (src)
Return the member nodes that built the current view i.e. the current partition.

Specified by:
getClusterNodes in interface HAPartition (src)
Returns:
An array of ClusterNode containing the node names

isCurrentNodeCoordinator

public boolean isCurrentNodeCoordinator()

registerRPCHandler

public void registerRPCHandler(java.lang.String objName,
                               java.lang.Object subscriber)
Description copied from interface: HAPartition (src)
The partition receives RPC calls from other nodes in the cluster and demultiplex them, according to a service name, to a particular service. Consequently, each service must first subscribe with a particular service name in the partition. The subscriber does not need to implement any specific interface: the call is handled dynamically through reflection.

Specified by:
registerRPCHandler in interface HAPartition (src)
Parameters:
objName - Name of the subscribing service (demultiplexing key)
subscriber - object to be called when receiving a RPC for its key.

unregisterRPCHandler

public void unregisterRPCHandler(java.lang.String objName,
                                 java.lang.Object subscriber)
Description copied from interface: HAPartition (src)
Unregister the service from the partition

Specified by:
unregisterRPCHandler in interface HAPartition (src)
Parameters:
objName - Name of the service key (on which the demultiplexing occurs)
subscriber - The target object that unsubscribes

callMethodOnCluster

public java.util.ArrayList callMethodOnCluster(java.lang.String objName,
                                               java.lang.String methodName,
                                               java.lang.Object[] args,
                                               boolean excludeSelf)
                                        throws java.lang.Exception
Deprecated. Use callMethodOnCluster(String,String,Object[],Class[], boolean) instead

Specified by:
callMethodOnCluster in interface HAPartition (src)
Parameters:
objName -
methodName -
args -
excludeSelf -
Returns:
Throws:
java.lang.Exception

callMethodOnCluster

public java.util.ArrayList callMethodOnCluster(java.lang.String objName,
                                               java.lang.String methodName,
                                               java.lang.Object[] args,
                                               java.lang.Class[] types,
                                               boolean excludeSelf)
                                        throws java.lang.Exception
This function is an abstraction of RpcDispatcher.

Specified by:
callMethodOnCluster in interface HAPartition (src)
Parameters:
objName - Name of the target service name on which calls are de-multiplexed
methodName - name of the Java method to be called on remote services
args - array of Java Object representing the set of parameters to be given to the remote method
types - The types of the parameters
excludeSelf - indicates if the RPC must also be made on the current node of the partition or only on remote nodes
Returns:
an array of answers from remote nodes
Throws:
java.lang.Exception - Throws if a communication exception occurs

callMethodOnCluster

public java.util.ArrayList callMethodOnCluster(java.lang.String objName,
                                               java.lang.String methodName,
                                               java.lang.Object[] args,
                                               java.lang.Class[] types,
                                               boolean excludeSelf,
                                               long methodTimeout)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

callAsynchMethodOnCluster

public void callAsynchMethodOnCluster(java.lang.String objName,
                                      java.lang.String methodName,
                                      java.lang.Object[] args,
                                      boolean excludeSelf)
                               throws java.lang.Exception
Deprecated. Use callAsynchMethodOnCluster(String, String, Object[], Class[], boolean) instead

Specified by:
callAsynchMethodOnCluster in interface HAPartition (src)
Parameters:
objName -
methodName -
args -
excludeSelf -
Throws:
java.lang.Exception

callAsynchMethodOnCluster

public void callAsynchMethodOnCluster(java.lang.String objName,
                                      java.lang.String methodName,
                                      java.lang.Object[] args,
                                      java.lang.Class[] types,
                                      boolean excludeSelf)
                               throws java.lang.Exception
This function is an abstraction of RpcDispatcher for asynchronous messages

Specified by:
callAsynchMethodOnCluster in interface HAPartition (src)
Parameters:
objName - Name of the target service name on which calls are de-multiplexed
methodName - name of the Java method to be called on remote services
args - array of Java Object representing the set of parameters to be given to the remote method
types - The types of the parameters
excludeSelf - indicates if the RPC must also be made on the current node of the partition or only on remote nodes
Throws:
java.lang.Exception - Throws if a communication exception occurs

subscribeToStateTransferEvents

public void subscribeToStateTransferEvents(java.lang.String objectName,
                                           HAPartition.HAPartitionStateTransfer (src)  subscriber)
Description copied from interface: HAPartition (src)
Register a service that will participate in state transfer protocol and receive callbacks

Specified by:
subscribeToStateTransferEvents in interface HAPartition (src)
Parameters:
objectName - Name of the service that subscribes for state stransfer events. This name must be identical for all identical services in the cluster.
subscriber - Object implementing HAPartition.HAPartitionStateTransfer (src) and providing or receiving state transfer callbacks

unsubscribeFromStateTransferEvents

public void unsubscribeFromStateTransferEvents(java.lang.String objectName,
                                               HAPartition.HAPartitionStateTransfer (src)  subscriber)
Description copied from interface: HAPartition (src)
Unregister a service from state transfer callbacks.

Specified by:
unsubscribeFromStateTransferEvents in interface HAPartition (src)
Parameters:
objectName - Name of the service that participates in the state transfer protocol
subscriber - Service implementing the state transfer callback methods

registerMembershipListener

public void registerMembershipListener(HAPartition.HAMembershipListener (src)  listener)
Description copied from interface: HAPartition (src)
Subscribes to receive HAPartition.HAMembershipListener (src) events.

Specified by:
registerMembershipListener in interface HAPartition (src)
Parameters:
listener - The membership listener object

unregisterMembershipListener

public void unregisterMembershipListener(HAPartition.HAMembershipListener (src)  listener)
Description copied from interface: HAPartition (src)
Unsubscribes from receiving HAPartition.HAMembershipListener (src) events.

Specified by:
unregisterMembershipListener in interface HAPartition (src)
Parameters:
listener - The listener wishing to unsubscribe

handle

public java.lang.Object handle(Message req)
Message contains MethodCall. Execute it against *this* object and return result. Use MethodCall.Invoke() to do this. Return result. This overrides RpcDispatcher.Handle so that we can dispatch to many different objects.

Parameters:
req - The org.jgroups. representation of the method invocation
Returns:
The serializable return value from the invocation

verifyNodeIsUnique

protected void verifyNodeIsUnique(java.util.Vector javaGroupIpAddresses)
                           throws java.lang.Exception
Throws:
java.lang.Exception

bind

protected void bind(java.lang.String jndiName,
                    java.lang.Object who,
                    java.lang.Class classType,
                    javax.naming.Context ctx)
             throws java.lang.Exception
Helper method that binds the partition in the JNDI tree.

Parameters:
jndiName - Name under which the object must be bound
who - Object to bind in JNDI
classType - Class type under which should appear the bound object
ctx - Naming context under which we bind the object
Throws:
java.lang.Exception - Thrown if a naming exception occurs during binding

getDeadMembers

protected java.util.Vector getDeadMembers(java.util.Vector oldMembers,
                                          java.util.Vector newMembers)
Helper method that returns a vector of dead members from two input vectors: new and old vectors of two views. Dead members are old - new members.

Parameters:
oldMembers - Vector of old members
newMembers - Vector of new members
Returns:
Vector of members that have died between the two views, can be empty.

getNewMembers

protected java.util.Vector getNewMembers(java.util.Vector oldMembers,
                                         java.util.Vector allMembers)
Helper method that returns a vector of new members from two input vectors: new and old vectors of two views.

Parameters:
oldMembers - Vector of old members
allMembers - Vector of new members
Returns:
Vector of members that have joined the partition between the two views

notifyListeners

protected void notifyListeners(java.util.ArrayList theListeners,
                               long viewID,
                               java.util.Vector allMembers,
                               java.util.Vector deadMembers,
                               java.util.Vector newMembers,
                               java.util.Vector originatingGroups)

translateAddresses

protected java.util.Vector translateAddresses(java.util.Vector jgAddresses)

logHistory

public void logHistory(java.lang.String message)