FileDocCategorySizeDatePackage
HATarget.javaAPI DocJBoss 4.2.17771Fri Jul 13 20:52:38 BST 2007org.jboss.ha.framework.server

HATarget

public class HATarget extends Object implements org.jboss.ha.framework.interfaces.DistributedReplicantManager.ReplicantListener
This class is a holder and manager of replicants. It manages lists of replicated objects and changes the list as the HAPartition notifies it.
author
bill@burkecentral.com
version
$Revision: 57188 $

Revisions:

2002/01/13: Bill Burke

  1. Initial revision

Fields Summary
public static final int
DISABLE_INVOCATIONS
public static final int
MAKE_INVOCATIONS_WAIT
public static final int
ENABLE_INVOCATIONS
protected String
replicantName
protected ArrayList
replicants
protected org.jboss.ha.framework.interfaces.HAPartition
partition
protected Logger
log
protected int
clusterViewId
protected Serializable
target
protected int
allowInvocationsStatus
protected EDU.oswego.cs.dl.util.concurrent.Latch
latch
Constructors Summary
public HATarget(org.jboss.ha.framework.interfaces.HAPartition partition, String replicantName, Serializable target, int allowInvocations)

   
      
		    
		    
           
       
   
      this.replicantName = replicantName;      
      this.target = target;      
      init ();
      setInvocationsAuthorization (allowInvocations);
      updateHAPartition(partition);
   
Methods Summary
protected voidcleanExistenceInCurrentHAPartition()

      if (this.partition != null)
      {
         try
         {
            DistributedReplicantManager drm = partition.getDistributedReplicantManager();
            drm.unregisterListener(this.replicantName, this);
            drm.remove(this.replicantName);         
         } 
         catch (Exception e)
         {
            log.error("failed to clean existence in current ha partition", e);
         }
      }    
   
public voiddestroy()

      try
      {
         this.cleanExistenceInCurrentHAPartition();
         
         // maybe some threads are blocked: we let them go here:
         //
         setInvocationsAuthorization (HATarget.DISABLE_INVOCATIONS);
      } 
      catch (Exception e)
      {
         log.error("failed to destroy", e);
      }
   
public voiddisable()

      try
      {
         if (this.partition != null)
         {
            log.debug ("Disabled called on HATarget");
            this.partition.getDistributedReplicantManager().remove (this.replicantName);         
         }      
      } 
      catch (Exception e)
      {
         log.error("failed to disable", e);
      }
   
public org.jboss.ha.framework.interfaces.HAPartitiongetAssociatedPartition()

       return this.partition;
   
public longgetCurrentViewId()

      return (long)clusterViewId;
   
public java.util.ArrayListgetReplicants()

      return replicants;
   
public voidinit()

      this.log = org.jboss.logging.Logger.getLogger(this.getClass());
   
public booleaninvocationsAllowed()

      if (this.allowInvocationsStatus == ENABLE_INVOCATIONS)
         return true;
      else if (this.allowInvocationsStatus == DISABLE_INVOCATIONS)
         return false;
      else if (this.allowInvocationsStatus == MAKE_INVOCATIONS_WAIT)
      {
         latch.acquire ();
         
         // if we arrive here, it means that the status has been changed, so
         // we check for the decision:
         //
         if (this.allowInvocationsStatus == ENABLE_INVOCATIONS)
            return true;
         else
            return false;         
      }    
      else
         return false;
   
protected voidreleaseCurrentLatch()

      latch.release ();
      latch = null;
   
public voidreplicantsChanged(java.lang.String key, java.util.List newReplicants, int newReplicantsViewId)

      if (log.isDebugEnabled())
         log.debug("replicantsChanged '" + replicantName + 
                   "' to " + (newReplicants==null? "0 (null)" : Integer.toString (newReplicants.size() ) ) + 
                   " (intra-view id: " + newReplicantsViewId + ")");
      
      synchronized(replicants)
      {
         // client has reference to replicants so it will automatically get
         // updated
         replicants.clear();
         if (newReplicants != null)
            replicants.addAll(newReplicants);
         
         this.clusterViewId = newReplicantsViewId;
      }
      
   
public synchronized voidsetInvocationsAuthorization(int status)

      if (this.allowInvocationsStatus == status)
      {
         // we don't release and reget a latch if two identical calls are performed
         //
         log.debug ("Invocation authorization called with no-op");
      }
      else
      {
         // CRITICAL CODE! DONT CHANGE ORDER WITHOUT THINKING ABOUT RACE CONDITIONS
         //
         if (status == MAKE_INVOCATIONS_WAIT)
         {
            log.debug ("Invocation authorization called: MAKE_INVOCATIONS_WAIT");
            latch = new Latch();
            this.allowInvocationsStatus = status;
         } 
         else
         {
            log.debug ("Invocation authorization called: " +
               ((status==ENABLE_INVOCATIONS)?"ENABLE_INVOCATIONS":"DISABLE_INVOCATIONS") );
            this.allowInvocationsStatus = status;
            if (latch != null)
               latch.release();
         }         
      }
   
public java.lang.StringtoString()

      StringBuffer buffer = new StringBuffer(super.toString());
      buffer.append('{");
      buffer.append("replicantName="+replicantName);
      buffer.append("partition="+partition.getPartitionName());
      buffer.append("clusterViewId="+clusterViewId);
      buffer.append("allowInvocationsStatus="+allowInvocationsStatus);
      buffer.append("replicants="+replicants);
      buffer.append('}");
      return buffer.toString();
   
public voidupdateHAPartition(org.jboss.ha.framework.interfaces.HAPartition partition)

      cleanExistenceInCurrentHAPartition();
      
      this.partition = partition;
      DistributedReplicantManager drm = partition.getDistributedReplicantManager();
      drm.registerListener(this.replicantName, this);
      drm.add(this.replicantName, this.target);