[jboss-cvs] JBossAS SVN: r104456 - in trunk: testsuite/src/main/org/jboss/test/cluster/defaultcfg/test and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue May 4 16:22:08 EDT 2010


Author: bstansberry at jboss.com
Date: 2010-05-04 16:22:07 -0400 (Tue, 04 May 2010)
New Revision: 104456

Added:
   trunk/testsuite/src/main/org/jboss/test/cluster/testutil/MockClusterNode.java
Modified:
   trunk/cluster/src/main/java/org/jboss/ha/framework/server/ClusterNodeImpl.java
   trunk/cluster/src/main/java/org/jboss/ha/framework/server/ClusterPartition.java
   trunk/cluster/src/main/java/org/jboss/ha/framework/server/JChannelFactory.java
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/LookupSucceededFilterUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/cluster/testutil/TestClusterNodeFactory.java
   trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-jboss-beans.xml
Log:
[JBAS-7254] Replace additional_data usage with values passed to Channel.setName()

Modified: trunk/cluster/src/main/java/org/jboss/ha/framework/server/ClusterNodeImpl.java
===================================================================
--- trunk/cluster/src/main/java/org/jboss/ha/framework/server/ClusterNodeImpl.java	2010-05-04 19:58:17 UTC (rev 104455)
+++ trunk/cluster/src/main/java/org/jboss/ha/framework/server/ClusterNodeImpl.java	2010-05-04 20:22:07 UTC (rev 104456)
@@ -50,27 +50,29 @@
    
    // Attributes ----------------------------------------------------
   
-   protected final String id;
-   protected String jgId = null;
-   protected final Address originalJGAddress;
-   protected final AddressPort address;
+   private final String id;
+   private final Address jgAddress;
+   private final AddressPort address;
 
    // Static --------------------------------------------------------
    
    // Constructors --------------------------------------------------
        
-   public ClusterNodeImpl(Address jgAddress, AddressPort a)
+   ClusterNodeImpl(String id, Address jgAddress, AddressPort addressPort)
    {
-      this.address = a;
-      this.originalJGAddress = jgAddress;
-      if (a != null)
+      if (id == null)
       {
-         this.id = a.getHostAddress() + ":" + a.getPort();
+         throw new IllegalArgumentException("Null id");
       }
-      else
+      if (addressPort == null)
       {
-         this.id = jgAddress.toString();
+         throw new IllegalArgumentException("Null addressPort");
       }
+      this.id = id;
+      this.address = addressPort;
+      
+      this.jgAddress = jgAddress;
+      
    }
   
    // Public --------------------------------------------------------
@@ -79,32 +81,24 @@
    {
       return this.id;
    }
-
-   public String getJGName()
-   {
-      if (jgId == null)
-      {
-         jgId = createJGName(); 
-      }
-      
-      return jgId;
-   }
-
-   public Address getOriginalJGAddress()
-   {
-      return this.originalJGAddress;
-   }
+   
    public InetAddress getIpAddress()
    {
       return this.address.getInetAddress();
    }
+   
    public int getPort()
    {
       return this.address.getPort();      
    }
 
-   // Comparable implementation ----------------------------------------------
+   // Package protected ----------------------------------------------
 
+   Address getOriginalJGAddress()
+   {
+      return this.jgAddress;
+   }
+   
    // Comparable implementation ----------------------------------------------
 
    public int compareTo(ClusterNode o)
@@ -117,6 +111,7 @@
 
       return this.id.compareTo(o.getName());
    }
+   
    // java.lang.Object overrides ---------------------------------------------------
 
    public boolean equals(Object obj)
@@ -141,35 +136,7 @@
    
    // Protected -----------------------------------------------------
 
-   protected String getShortName(String hostname)
-   {
-      int index = hostname.indexOf('.');
 
-      if (hostname == null) return "";
-      if (index > 0 && !Character.isDigit(hostname.charAt(0)))
-         return hostname.substring(0, index);
-      else
-         return hostname;
-   }
-   
-   protected String createJGName()
-   {
-      StringBuffer sb = new StringBuffer();
-      java.net.InetAddress jgIPAddr = address.getInetAddress();
-      if (jgIPAddr == null)
-         sb.append("<null>");
-      else
-      {
-         if (jgIPAddr.isMulticastAddress())
-            sb.append(jgIPAddr.getHostAddress());
-         else
-            sb.append(getShortName(getFastHostName(jgIPAddr)));
-      }
-      sb.append(":" + address.getPort());
-      
-      return sb.toString();
-   }
-
    // Private -------------------------------------------------------
    
    /**

Modified: trunk/cluster/src/main/java/org/jboss/ha/framework/server/ClusterPartition.java
===================================================================
--- trunk/cluster/src/main/java/org/jboss/ha/framework/server/ClusterPartition.java	2010-05-04 19:58:17 UTC (rev 104455)
+++ trunk/cluster/src/main/java/org/jboss/ha/framework/server/ClusterPartition.java	2010-05-04 20:22:07 UTC (rev 104456)
@@ -106,6 +106,7 @@
 import org.jgroups.stack.IpAddress;
 import org.jgroups.util.Rsp;
 import org.jgroups.util.RspList;
+import org.jgroups.util.UUID;
 
 /**
  * {@link HAPartition} implementation based on a
@@ -560,7 +561,14 @@
          }
          addressMap.put(a, result);
       }
-      return new ClusterNodeImpl(a, new AddressPort(result.getIpAddress(), result.getPort()));
+      AddressPort addrPort = new AddressPort(result.getIpAddress(), result.getPort());
+      // FIXME -- when JGroups exposes UUID.get() via Channel, use that
+      String id = UUID.get(a);
+      if (id == null)
+      {
+         id = addrPort.getHostAddress() + ":" + addrPort.getPort();
+      }
+      return new ClusterNodeImpl(id, a, addrPort);
    }
 
    /**

Modified: trunk/cluster/src/main/java/org/jboss/ha/framework/server/JChannelFactory.java
===================================================================
--- trunk/cluster/src/main/java/org/jboss/ha/framework/server/JChannelFactory.java	2010-05-04 19:58:17 UTC (rev 104455)
+++ trunk/cluster/src/main/java/org/jboss/ha/framework/server/JChannelFactory.java	2010-05-04 20:22:07 UTC (rev 104456)
@@ -59,7 +59,6 @@
 import org.jgroups.ChannelException;
 import org.jgroups.ChannelFactory;
 import org.jgroups.ChannelListenerAdapter;
-import org.jgroups.Event;
 import org.jgroups.Global;
 import org.jgroups.JChannel;
 import org.jgroups.conf.ConfiguratorFactory;
@@ -68,7 +67,6 @@
 import org.jgroups.conf.ProtocolStackConfigurator;
 import org.jgroups.jmx.JmxConfigurator;
 import org.jgroups.protocols.TP;
-import org.jgroups.Address;
 import org.jgroups.stack.Protocol;
 import org.jgroups.stack.ProtocolStack;
 import org.jgroups.util.DefaultThreadFactory;
@@ -1275,23 +1273,21 @@
    
    private void setChannelUniqueId(Channel channel)
    {
-      Address address = channel.getAddress();
-      if (address == null)
+      String logical_address_name = channel.getName();
+      if (logical_address_name == null)
       {
          // We push the independent name in the protocol stack before connecting to the cluster
          if (this.nodeName == null || "".equals(this.nodeName)) {
             this.nodeName = generateUniqueNodeName();
          }
          
-         log.debug("Passing unique node id " + nodeName + " to the channel as additional data");
+         log.debug("Assigning unique node id " + nodeName + " to the channel");
          
-         HashMap<String, byte[]> staticNodeName = new HashMap<String, byte[]>();
-         staticNodeName.put("additional_data", this.nodeName.getBytes());
-         channel.downcall(new Event(Event.CONFIG, staticNodeName));         
+         channel.setName(this.nodeName);        
       }    
    }
 
-   private String generateUniqueNodeName ()
+   private synchronized String generateUniqueNodeName ()
    {
       // we first try to find a simple meaningful name:
       // 1st) "local-IP:JNDI_PORT" if JNDI is running on this machine

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/LookupSucceededFilterUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/LookupSucceededFilterUnitTestCase.java	2010-05-04 19:58:17 UTC (rev 104455)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/LookupSucceededFilterUnitTestCase.java	2010-05-04 20:22:07 UTC (rev 104456)
@@ -25,11 +25,10 @@
 
 import org.jboss.ha.framework.interfaces.ClusterNode;
 import org.jboss.ha.framework.interfaces.ResponseFilter;
-import org.jboss.ha.framework.server.ClusterNodeImpl;
+import org.jboss.ha.framework.server.ClusterNodeFactory;
 import org.jboss.ha.framework.server.ClusterPartition;
 import org.jboss.ha.framework.server.RspFilterAdapter;
 import org.jboss.ha.jndi.LookupSucceededFilter;
-import org.jboss.ha.framework.server.ClusterNodeFactory;
 import org.jboss.test.cluster.testutil.TestClusterNodeFactory;
 import org.jgroups.Address;
 import org.jgroups.blocks.RspFilter;

Added: trunk/testsuite/src/main/org/jboss/test/cluster/testutil/MockClusterNode.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/testutil/MockClusterNode.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/testutil/MockClusterNode.java	2010-05-04 20:22:07 UTC (rev 104456)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.testutil;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+
+/**
+ * A MockClusterNode.
+ * 
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public class MockClusterNode implements ClusterNode
+{
+
+   private static final long serialVersionUID = 1L;
+
+   private final InetAddress address;
+   private final int port;
+   private final String name;
+   
+   public MockClusterNode(int port) throws UnknownHostException
+   {
+      this(InetAddress.getLocalHost(), port);
+   }
+   
+   public MockClusterNode(InetAddress addr, int port)
+   {
+      this.address = addr;
+      this.port = port;
+      this.name = addr.getHostAddress() + ":" + port;
+   }
+   
+   public InetAddress getIpAddress()
+   {
+      return address;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public int getPort()
+   {
+      return port;
+   }
+
+   public int compareTo(ClusterNode o)
+   {      
+      return o == null ? - 1 : name.compareTo(o.getName());
+   }
+
+}

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/testutil/TestClusterNodeFactory.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/testutil/TestClusterNodeFactory.java	2010-05-04 19:58:17 UTC (rev 104455)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/testutil/TestClusterNodeFactory.java	2010-05-04 20:22:07 UTC (rev 104456)
@@ -36,6 +36,6 @@
 	
 	public ClusterNode getClusterNode(Address address){
 		IpAddress ip = (IpAddress) address;
-		return new ClusterNodeImpl(address,new AddressPort(ip.getIpAddress(), ip.getPort()));
+		return new MockClusterNode(ip.getIpAddress(), ip.getPort());
 	}   
 }

Modified: trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-jboss-beans.xml
===================================================================
--- trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-jboss-beans.xml	2010-05-04 19:58:17 UTC (rev 104455)
+++ trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-jboss-beans.xml	2010-05-04 20:22:07 UTC (rev 104456)
@@ -105,8 +105,7 @@
    <bean class="org.jboss.ha.singleton.PreferredMasterElectionPolicy"
           name="PreferredMasterElectionPolicy_1">
      <property name="position">0</property>
-     <!--  55200 is the default bind_port for the JGroups UDP stack -->
-     <property name="preferredMaster">${node0.bind.address:127.0.0.1}:55200</property>
+     <property name="preferredMaster">${node0.bind.address:127.0.0.1}:1099</property>
    </bean>
 
    <bean class="org.jboss.ha.singleton.HASingletonController" 
@@ -131,8 +130,7 @@
    <bean class="org.jboss.ha.singleton.PreferredMasterElectionPolicy"
           name="PreferredMasterElectionPolicy_2">
      <property name="position">-1</property>
-     <!--  55200 is the default bind_port for the JGroups UDP stack -->
-     <property name="preferredMaster">${node0.bind.address:127.0.0.1}:55200</property>
+     <property name="preferredMaster">${node0.bind.address:127.0.0.1}:1099</property>
    </bean>
 
    <bean class="org.jboss.ha.singleton.HASingletonController" 




More information about the jboss-cvs-commits mailing list