User: patriot1burke
  Date: 02/01/13 17:56:29

  Added:       src/main/org/jboss/ha/framework/server HATarget.java
  Log:
  Heterogeneous Partitions.  Also fixed problem where you could get bogus failover 
targets
  if making calls when a server starts up.
  
  This class abstracts out replicant updates.
  
  Revision  Changes    Path
  1.1                  jbossmx/src/main/org/jboss/ha/framework/server/HATarget.java
  
  Index: HATarget.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE WebOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.ha.framework.server;
  
  import java.util.ArrayList;
  import 
org.jboss.ha.framework.interfaces.DistributedReplicantManager.ReplicantListener;
  import org.jboss.ha.framework.interfaces.LoadBalancePolicy;
  import org.jboss.ha.framework.interfaces.HAPartition;
  import java.io.Serializable;
  /** 
   *   This class is a holder of replicants.
   *
   *   @author [EMAIL PROTECTED]
   *   @version $Revision: 1.1 $
   *
   * <p><b>Revisions:</b><br>
   * <p><b>2002/01/13: Bill Burke</b>
   * <ol>
   *   <li>Initial revision
   * </ol>
   */
  
  public class HATarget implements ReplicantListener
  {
     // Constants -----------------------------------------------------
     
     // Attributes ----------------------------------------------------
     
     protected String replicantName;
     protected ArrayList replicants = new ArrayList();
     protected HAPartition partition = null;
     protected org.jboss.logging.Logger log;
     protected long clusterViewId = -1;
     protected Serializable target;
     // Static --------------------------------------------------------
     
     // Constructors --------------------------------------------------
     
     public HATarget(HAPartition partition, 
                   String replicantName,
                   Serializable target) 
        throws Exception
     {
        this.replicantName = replicantName;      
        this.log = org.jboss.logging.Logger.getLogger(this.getClass());
        this.target = target;
        updateHAPartition(partition);
     }
  
     // Public --------------------------------------------------------
  
     public long getCurrentViewId()
     {
        return clusterViewId;
     }
     
     public void destroy()
     {
        try
        {
           this.cleanExistenceInCurrentHAPartition();
        } 
        catch (Exception e)
        {
           e.printStackTrace();
        }
     }
     
     public ArrayList getReplicants() throws Exception
     {
        return replicants;
     }
     
     public void updateHAPartition(HAPartition partition) throws Exception
     {
        cleanExistenceInCurrentHAPartition();
        
        this.partition = partition;
        
        
partition.getDistributedReplicantManager().registerListener(this.replicantName, this);
        partition.getDistributedReplicantManager().add(this.replicantName, 
this.target);
        
        this.clusterViewId = partition.getCurrentViewId();
     }
     
     // DistributedReplicantManager.ReplicantListener implementation 
----------------------------------------------
        
     public void replicantsChanged(String key, ArrayList newReplicants)
     {
        if (log.isDebugEnabled())
          log.debug("replicantsChanged '" + replicantName + "' to " + 
newReplicants.size());
        synchronized(replicants)
        {
           // client has reference to replicants so it will automatically get
           // updated
           replicants.clear();
           replicants.addAll(newReplicants);
        }
        this.clusterViewId = partition.getCurrentViewId();
     }
     
     // Package protected ---------------------------------------------
     
     // Protected -----------------------------------------------------
     
     protected void cleanExistenceInCurrentHAPartition()
     {
        if (this.partition != null)
        {
         try
         {
            
this.partition.getDistributedReplicantManager().unregisterListener(this.replicantName, 
this);
            this.partition.getDistributedReplicantManager().remove 
(this.replicantName);         
         } 
         catch (Exception e)
         {
            e.printStackTrace ();
         }
        }      
     }
  
     // Private -------------------------------------------------------
     
     // Inner classes -------------------------------------------------
     
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to