[jboss-cvs] JBossAS SVN: r67722 - in trunk/cluster/src/main/org/jboss/ha/framework: server and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Dec 1 17:23:31 EST 2007


Author: bstansberry at jboss.com
Date: 2007-12-01 17:23:31 -0500 (Sat, 01 Dec 2007)
New Revision: 67722

Added:
   trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterNodeImpl.java
Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterNode.java
   trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
   trunk/cluster/src/main/org/jboss/ha/framework/server/util/TopologyMonitorService.java
Log:
[JBAS-5019] Turn ClusterNode into an interface

Modified: trunk/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterNode.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterNode.java	2007-12-01 19:57:00 UTC (rev 67721)
+++ trunk/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterNode.java	2007-12-01 22:23:31 UTC (rev 67722)
@@ -24,149 +24,24 @@
 import java.net.InetAddress;
 import java.io.Serializable;
 
-import org.jgroups.stack.IpAddress;
-
 /**
- * Replacement for a JG IpAddress that doesn't base its representation
- * on the JG address but on the computed node name added to the IPAddress instead.
- * This is to avoid any problem in the cluster as some nodes may interpret a node name
- * differently (IP resolution, name case, FQDN or host name, etc.)
- *
- * @see org.jboss.ha.framework.server.ClusterPartitionMBean
- *
- * @author  <a href="mailto:sacha.labourey at jboss.org">Sacha Labourey</a>.
+ * Abstract identifier for a member of an @{link HAPartition}.
+ * 
+ * Note: In the JBoss AS 3.x and 4.x series, this was an ordinary class,
+ * not an interface.  For AS 5 it has been converted into an interface that
+ * no longer exposes implementation details like a JGroups IpAddress.
+ * 
+ * @author  Brian Stansberry
  * @version $Revision$
- *   
- * <p><b>Revisions:</b>
- *
- * <p><b>August 17 2003 Sacha Labourey:</b>
- * <ul>
- * <li> First implementation </li> 
- * </ul>
  */
-
-public class ClusterNode
-   implements Comparable, Cloneable, Serializable
+public interface ClusterNode
+   extends Comparable, Cloneable, Serializable
 {
+   String getName();
 
-   // Constants -----------------------------------------------------
-   
-   // Attributes ----------------------------------------------------
+   String getJGName();
 
-   protected String id = null;
-   protected String jgId = null;
-   protected IpAddress originalJGAddress = null;
-
-   // Static --------------------------------------------------------
+   InetAddress getIpAddress();
    
-   // Constructors --------------------------------------------------
-       
-   public ClusterNode()
-   {
-   }
-
-   public ClusterNode(IpAddress jgAddress)
-   {
-      if (jgAddress.getAdditionalData() == null)
-      {
-         this.id = jgAddress.getIpAddress().getHostAddress() + ":" + jgAddress.getPort();
-      }
-      else
-      {
-         this.id = new String(jgAddress.getAdditionalData());
-      }
-
-      this.originalJGAddress = jgAddress;
-      StringBuffer sb = new StringBuffer();
-      java.net.InetAddress jgIPAddr = jgAddress.getIpAddress();
-      if (jgIPAddr == null)
-         sb.append("<null>");
-      else
-      {
-         if (jgIPAddr.isMulticastAddress())
-            sb.append(jgIPAddr.getHostAddress());
-         else
-            sb.append(getShortName(jgIPAddr.getHostName()));
-      }
-      sb.append(":" + jgAddress.getPort());
-      this.jgId = sb.toString();
-   }
-
-   // Public --------------------------------------------------------
-
-   public String getName()
-   {
-      return this.id;
-   }
-
-   public String getJGName()
-   {
-      return this.jgId;
-   }
-
-   public IpAddress getOriginalJGAddress()
-   {
-      return this.originalJGAddress;
-   }
-   public InetAddress getIpAddress()
-   {
-      return this.originalJGAddress.getIpAddress();
-   }
-   public int getPort()
-   {
-      return this.originalJGAddress.getPort();      
-   }
-
-   // Comparable implementation ----------------------------------------------
-
-   // Comparable implementation ----------------------------------------------
-
-   public int compareTo(Object o)
-   {
-      if ((o == null) || !(o instanceof ClusterNode))
-         throw new ClassCastException("ClusterNode.compareTo(): comparison between different classes");
-
-      ClusterNode other = (ClusterNode) o;
-
-      return this.id.compareTo(other.id);
-   }
-   // java.lang.Object overrides ---------------------------------------------------
-
-   public boolean equals(Object obj)
-   {
-      if (obj == null || !(obj instanceof ClusterNode)) return false;
-      
-      ClusterNode other = (ClusterNode) obj;
-      return this.id.equals(other.id);
-   }
-
-   public int hashCode()
-   {
-      return id.hashCode();
-   }
-
-   public String toString()
-   {
-      return this.getName();
-   }
-
-   // Package protected ---------------------------------------------
-   
-   // 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;
-   }
-
-   // Private -------------------------------------------------------
-   
-   // Inner classes -------------------------------------------------
-
+   int getPort();
 }

Added: trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterNodeImpl.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterNodeImpl.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterNodeImpl.java	2007-12-01 22:23:31 UTC (rev 67722)
@@ -0,0 +1,168 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.ha.framework.server;
+
+import java.net.InetAddress;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jgroups.stack.IpAddress;
+
+/**
+ * Replacement for a JG IpAddress that doesn't base its representation
+ * on the JG address but on the computed node name added to the IPAddress instead.
+ * This is to avoid any problem in the cluster as some nodes may interpret a node name
+ * differently (IP resolution, name case, FQDN or host name, etc.)
+ *
+ * @see org.jboss.ha.framework.server.ClusterPartitionMBean
+ *
+ * @author  <a href="mailto:sacha.labourey at jboss.org">Sacha Labourey</a>.
+ * @author Brian Stansberry
+ * @version $Revision: 58561 $
+ */
+
+public class ClusterNodeImpl
+   implements ClusterNode
+{
+   // Constants -----------------------------------------------------
+
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 2713397663824031616L;
+   
+   // Attributes ----------------------------------------------------
+   
+   protected String id = null;
+   protected String jgId = null;
+   protected IpAddress originalJGAddress = null;
+
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+       
+   public ClusterNodeImpl()
+   {
+   }
+
+   public ClusterNodeImpl(IpAddress jgAddress)
+   {
+      if (jgAddress.getAdditionalData() == null)
+      {
+         this.id = jgAddress.getIpAddress().getHostAddress() + ":" + jgAddress.getPort();
+      }
+      else
+      {
+         this.id = new String(jgAddress.getAdditionalData());
+      }
+
+      this.originalJGAddress = jgAddress;
+      StringBuffer sb = new StringBuffer();
+      java.net.InetAddress jgIPAddr = jgAddress.getIpAddress();
+      if (jgIPAddr == null)
+         sb.append("<null>");
+      else
+      {
+         if (jgIPAddr.isMulticastAddress())
+            sb.append(jgIPAddr.getHostAddress());
+         else
+            sb.append(getShortName(jgIPAddr.getHostName()));
+      }
+      sb.append(":" + jgAddress.getPort());
+      this.jgId = sb.toString();
+   }
+
+   // Public --------------------------------------------------------
+
+   public String getName()
+   {
+      return this.id;
+   }
+
+   public String getJGName()
+   {
+      return this.jgId;
+   }
+
+   public IpAddress getOriginalJGAddress()
+   {
+      return this.originalJGAddress;
+   }
+   public InetAddress getIpAddress()
+   {
+      return this.originalJGAddress.getIpAddress();
+   }
+   public int getPort()
+   {
+      return this.originalJGAddress.getPort();      
+   }
+
+   // Comparable implementation ----------------------------------------------
+
+   // Comparable implementation ----------------------------------------------
+
+   public int compareTo(Object o)
+   {
+      if ((o == null) || !(o instanceof ClusterNodeImpl))
+         throw new ClassCastException("ClusterNode.compareTo(): comparison between different classes");
+
+      ClusterNodeImpl other = (ClusterNodeImpl) o;
+
+      return this.id.compareTo(other.id);
+   }
+   // java.lang.Object overrides ---------------------------------------------------
+
+   public boolean equals(Object obj)
+   {
+      if (obj == null || !(obj instanceof ClusterNodeImpl)) return false;
+      
+      ClusterNodeImpl other = (ClusterNodeImpl) obj;
+      return this.id.equals(other.id);
+   }
+
+   public int hashCode()
+   {
+      return id.hashCode();
+   }
+
+   public String toString()
+   {
+      return this.getName();
+   }
+
+   // Package protected ---------------------------------------------
+   
+   // 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;
+   }
+
+   // Private -------------------------------------------------------
+   
+   // Inner classes -------------------------------------------------
+
+}

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java	2007-12-01 19:57:00 UTC (rev 67721)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java	2007-12-01 22:23:31 UTC (rev 67722)
@@ -303,7 +303,7 @@
          
          log.debug("get nodeName");
          this.localJGAddress = (IpAddress)channel.getLocalAddress();
-         this.me = new ClusterNode(this.localJGAddress);
+         this.me = new ClusterNodeImpl(this.localJGAddress);
          this.nodeName = this.me.getName();
 
          // FIXME -- just block waiting for viewAccepted!
@@ -948,6 +948,9 @@
    public Object callMethodOnNode(String serviceName, String methodName,
            Object[] args, Class[] types, long methodTimeout, ClusterNode targetNode) throws Throwable
     {
+       if (!(targetNode instanceof ClusterNodeImpl))
+          throw new IllegalArgumentException("targetNode " + targetNode + " is not an instance of " + 
+                                          ClusterNodeImpl.class + " -- only targetNodes provided by this HAPartition should be used");
        MethodCall m;
        boolean trace = log.isTraceEnabled();
        if(types != null)
@@ -959,7 +962,7 @@
           log.trace("callMethodOnNode( objName="+serviceName
              +", methodName="+methodName);
        }
-       Object rc = dispatcher.callRemoteMethod(targetNode.getOriginalJGAddress(), m, GroupRequest.GET_FIRST, methodTimeout);
+       Object rc = dispatcher.callRemoteMethod(((ClusterNodeImpl)targetNode).getOriginalJGAddress(), m, GroupRequest.GET_FIRST, methodTimeout);
        if (rc != null)
        {
           Object item = rc;
@@ -1004,7 +1007,10 @@
    public void callAsyncMethodOnNode(String serviceName, String methodName,
            Object[] args, Class[] types, long methodTimeout, ClusterNode targetNode) throws Throwable
    {
-       MethodCall m;
+      if (!(targetNode instanceof ClusterNodeImpl))
+         throw new IllegalArgumentException("targetNode " + targetNode + " is not an instance of " + 
+                                         ClusterNodeImpl.class + " -- only targetNodes provided by this HAPartition should be used");
+      MethodCall m;
        boolean trace = log.isTraceEnabled();
        if(types != null)
           m=new MethodCall(serviceName + "." + methodName, args, types);
@@ -1015,7 +1021,7 @@
           log.trace("callAsyncMethodOnNode( objName="+serviceName
              +", methodName="+methodName);
        }
-       dispatcher.callRemoteMethod(targetNode.getOriginalJGAddress(), m, GroupRequest.GET_NONE, methodTimeout);
+       dispatcher.callRemoteMethod(((ClusterNodeImpl)targetNode).getOriginalJGAddress(), m, GroupRequest.GET_NONE, methodTimeout);
    }
 
    private ArrayList processResponseList(RspList rsp, boolean trace)
@@ -1345,7 +1351,7 @@
       for (int i = 0; i < jgAddresses.size(); i++)
       {
          IpAddress addr = (IpAddress) jgAddresses.elementAt(i);
-         result.add(new ClusterNode (addr));
+         result.add(new ClusterNodeImpl(addr));
       }
 
       return result;

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/util/TopologyMonitorService.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/util/TopologyMonitorService.java	2007-12-01 19:57:00 UTC (rev 67721)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/util/TopologyMonitorService.java	2007-12-01 22:23:31 UTC (rev 67722)
@@ -226,8 +226,8 @@
          org.jboss.ha.framework.interfaces.ClusterNode node =
                (org.jboss.ha.framework.interfaces.ClusterNode)addr;
 
-         InetAddress inetAddr = node.getOriginalJGAddress().getIpAddress();
-         Integer port = new Integer(node.getOriginalJGAddress().getPort());
+         InetAddress inetAddr = node.getIpAddress();
+         Integer port = new Integer(node.getPort());
          info = new AddressPort(inetAddr, port);
       }
       catch(Exception e)




More information about the jboss-cvs-commits mailing list