[jboss-cvs] JBossAS SVN: r109714 - trunk/cluster/src/main/java/org/jboss/ha/singleton.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 3 19:03:12 EST 2010


Author: pferraro
Date: 2010-12-03 19:03:12 -0500 (Fri, 03 Dec 2010)
New Revision: 109714

Modified:
   trunk/cluster/src/main/java/org/jboss/ha/singleton/PreferredMasterElectionPolicy.java
Log:
JBAS-8710 HASingleton PreferredMasterElectionPolicy failing with IPv6 addresses
Replace fragile string comparison with address/port comparison.

Modified: trunk/cluster/src/main/java/org/jboss/ha/singleton/PreferredMasterElectionPolicy.java
===================================================================
--- trunk/cluster/src/main/java/org/jboss/ha/singleton/PreferredMasterElectionPolicy.java	2010-12-03 22:31:46 UTC (rev 109713)
+++ trunk/cluster/src/main/java/org/jboss/ha/singleton/PreferredMasterElectionPolicy.java	2010-12-04 00:03:12 UTC (rev 109714)
@@ -29,7 +29,6 @@
 import java.util.List;
 
 import org.jboss.ha.framework.interfaces.ClusterNode;
-import org.jboss.logging.Logger;
 
 /**
  * Election policy that chooses the node where the singleton should run based on 
@@ -45,8 +44,6 @@
    extends HASingletonElectionPolicySimple 
    implements PreferredMasterElectionPolicyMBean
 {
-   private Logger log = Logger.getLogger(this.getClass());
-   
    private volatile InetSocketAddress preferredMaster;
    
    // -------------------------------------------------------------  Properties
@@ -54,6 +51,7 @@
    /**
     * @see PreferredMasterElectionPolicyMBean#setPreferredMaster(String)
     */
+   @Override
    public void setPreferredMaster(String value)
    {
       String node = (value != null) ? value.trim() : "";
@@ -91,6 +89,7 @@
    /**
     * @see PreferredMasterElectionPolicyMBean#getPreferredMaster()
     */
+   @Override
    public String getPreferredMaster()
    {
       InetSocketAddress address = this.preferredMaster;
@@ -110,36 +109,16 @@
       // If preferred master is defined and contained in cluster, return it
       if (sockAddress != null) 
       {
-         InetAddress address = sockAddress.getAddress();
-         int port = sockAddress.getPort();
-         
-         // First find by address
-         master = this.find(candidates, address.getHostAddress(), port);
-         
-         if (master == null)
+         for (ClusterNode candidate: candidates)
          {
-            // Then try by hostname
-            master = this.find(candidates, address.getHostName(), port);
+            if ((candidate.getPort() == sockAddress.getPort()) && candidate.getIpAddress().equals(sockAddress.getAddress()))
+            {
+               master = candidate;
+               break;
+            }
          }
       }
       
       return (master != null) ? master : super.elect(candidates);
    }
-   
-   private ClusterNode find(List<ClusterNode> candidates, String host, int port)
-   {
-      String node = host + ":" + port;
-      
-      this.log.debug("Checking if " + node + " is in candidate list: " + candidates);
-      
-      for (ClusterNode candidate: candidates)
-      {
-         if (candidate.getName().equals(node))
-         {
-            return candidate;
-         }
-      }
-      
-      return null;
-   }
 }
\ No newline at end of file



More information about the jboss-cvs-commits mailing list