org.jboss.ha.framework.server
Class HATarget

java.lang.Object
  extended by org.jboss.ha.framework.server.HATarget
All Implemented Interfaces:
DistributedReplicantManager.ReplicantListener

public class HATarget
extends Object
implements DistributedReplicantManager.ReplicantListener

Control point representing a clustered service. Works with the DistributedReplicantManager to makes available a list of replicants (objects used to identify remote service endpoints around the cluster) for the service. Guards access to the service via the invocationsAllowed() and setInvocationsAuthorization(int) methods.

Version:
$Revision: 74879 $

Revisions:

2002/01/13: Bill Burke

  1. Initial revision
Author:
bill@burkecentral.com

Field Summary
protected  int allowInvocationsStatus
           
protected  int clusterViewId
           
static int DISABLE_INVOCATIONS
          Argument to setInvocationsAuthorization(int) that indicates invocationsAllowed() should return false.
static int ENABLE_INVOCATIONS
          Argument to setInvocationsAuthorization(int) that indicates invocationsAllowed() should return true.
protected  CountDownLatch latch
           
protected  org.jboss.logging.Logger log
           
static int MAKE_INVOCATIONS_WAIT
          Argument to setInvocationsAuthorization(int) that indicates calls to invocationsAllowed() should block until a different value is passed to setInvocationsAuthorization(int).
protected  HAPartition partition
           
protected  String replicantName
           
protected  ArrayList replicants
           
protected  Serializable target
           
 
Constructor Summary
HATarget(HAPartition partition, String replicantName, Serializable target, int allowInvocations)
          Creates a new HATarget.
 
Method Summary
protected  void cleanExistenceInCurrentHAPartition()
          Unregister's with the partition's DistributedReplicantManager.
 void destroy()
          Removes the local node from the distributed registry of nodes providing the service and causes invocationsAllowed() to return false.
 void disable()
          Removes the local node from the distributed registry of nodes providing the service.
 HAPartition getAssociatedPartition()
           
 long getCurrentViewId()
          Gets the current view id for the clustered service.
 ArrayList getReplicants()
          Gets the replicants for the clustered service.
protected  void init()
          Deprecated. this will be removed in the next major release
 boolean invocationsAllowed()
          Returns whether invocations on the target service are currently allowed on this node.
protected  void releaseCurrentLatch()
          Releases any latch blocking threads in invocationsAllowed().
 void replicantsChanged(String key, List newReplicants, int newReplicantsViewId, boolean merge)
          Callback called when the content/list of replicant for a given replicant key has changed
 void setInvocationsAuthorization(int status)
          Sets the behavior expected from invocationsAllowed().
 String toString()
           
protected  void updateHAPartition(HAPartition partition)
          Associates this target with the given partition, registering with the partition's DistributedReplicantManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DISABLE_INVOCATIONS

public static final int DISABLE_INVOCATIONS
Argument to setInvocationsAuthorization(int) that indicates invocationsAllowed() should return false.

See Also:
Constant Field Values

MAKE_INVOCATIONS_WAIT

public static final int MAKE_INVOCATIONS_WAIT
Argument to setInvocationsAuthorization(int) that indicates calls to invocationsAllowed() should block until a different value is passed to setInvocationsAuthorization(int).

See Also:
Constant Field Values

ENABLE_INVOCATIONS

public static final int ENABLE_INVOCATIONS
Argument to setInvocationsAuthorization(int) that indicates invocationsAllowed() should return true.

See Also:
Constant Field Values

replicantName

protected String replicantName

replicants

protected ArrayList replicants

partition

protected HAPartition partition

log

protected org.jboss.logging.Logger log

clusterViewId

protected int clusterViewId

target

protected Serializable target

allowInvocationsStatus

protected int allowInvocationsStatus

latch

protected CountDownLatch latch
Constructor Detail

HATarget

public HATarget(HAPartition partition,
                String replicantName,
                Serializable target,
                int allowInvocations)
         throws Exception
Creates a new HATarget.

Parameters:
partition - the HAPartition for the service's cluster
replicantName - the name of the service
target - the service's replicant
allowInvocations - true if invocationsAllowed() should return true immediately; false if not
Throws:
Exception
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getCurrentViewId

public long getCurrentViewId()
Gets the current view id for the clustered service.


destroy

public void destroy()
Removes the local node from the distributed registry of nodes providing the service and causes invocationsAllowed() to return false.


disable

public void disable()
Removes the local node from the distributed registry of nodes providing the service. After this call, the HATarget can still be queried for view change, etc. but the local node's instance of the service is no longer registered with the cluster.

NOTE: Calling this method does not cause invocationsAllowed() to return false. Use destroy() unless your application needs to separately control the two aspects of shutting down a clustered service.


getReplicants

public ArrayList getReplicants()
Gets the replicants for the clustered service. A replicant is a service-specific object, typically something that represents a remote service endpoint for the service on a particular cluster node. Examples include an RMI stub, a JBoss Remoting InvokerLocator or an HTTP URL.


setInvocationsAuthorization

public void setInvocationsAuthorization(int status)
Sets the behavior expected from invocationsAllowed().

Parameters:
status - ENABLE_INVOCATIONS, DISABLE_INVOCATIONS or MAKE_INVOCATIONS_WAIT

invocationsAllowed

public boolean invocationsAllowed()
                           throws InterruptedException
Returns whether invocations on the target service are currently allowed on this node. Will block if setInvocationsAuthorization(int) has been set to MAKE_INVOCATIONS_WAIT.

Returns:
truee if it is valid to make invocations on the service, false otherwise
Throws:
InterruptedException - if the current thread is interrupted while blocking waiting for MAKE_INVOCATIONS_WAIT

getAssociatedPartition

public HAPartition getAssociatedPartition()

replicantsChanged

public void replicantsChanged(String key,
                              List newReplicants,
                              int newReplicantsViewId,
                              boolean merge)
Description copied from interface: DistributedReplicantManager.ReplicantListener
Callback called when the content/list of replicant for a given replicant key has changed

Specified by:
replicantsChanged in interface DistributedReplicantManager.ReplicantListener
Parameters:
key - The name of the key of the replicant that has changed
newReplicants - The list of new replicants for the give replicant key. This list will be in a consistent order on all cluster nodes on which the current viewId is in effect
newReplicantsViewId - The new replicant view id corresponding to this change
merge - Is the change due to a merge (i.e. the healing of a cluster split)?

init

@Deprecated
protected void init()
             throws Exception
Deprecated. this will be removed in the next major release

Allows subclasses to perform initialization work.

Throws:
Exception

updateHAPartition

protected void updateHAPartition(HAPartition partition)
                          throws Exception
Associates this target with the given partition, registering with the partition's DistributedReplicantManager.

Parameters:
partition - the partition
Throws:
Exception

cleanExistenceInCurrentHAPartition

protected void cleanExistenceInCurrentHAPartition()
Unregister's with the partition's DistributedReplicantManager.


releaseCurrentLatch

protected void releaseCurrentLatch()
Releases any latch blocking threads in invocationsAllowed().



Copyright © 2009 JBoss, a division of Red Hat, Inc.. All Rights Reserved.