[jboss-cvs] JBossAS SVN: r69142 - trunk/cluster/src/main/org/jboss/ha/framework/server.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jan 19 19:18:09 EST 2008


Author: bstansberry at jboss.com
Date: 2008-01-19 19:18:08 -0500 (Sat, 19 Jan 2008)
New Revision: 69142

Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterNodeImpl.java
Log:
[JBAS-3794] Remove InetAddress.getHostName() call.

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterNodeImpl.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterNodeImpl.java	2008-01-19 23:42:09 UTC (rev 69141)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterNodeImpl.java	2008-01-20 00:18:08 UTC (rev 69142)
@@ -82,7 +82,7 @@
          if (jgIPAddr.isMulticastAddress())
             sb.append(jgIPAddr.getHostAddress());
          else
-            sb.append(getShortName(jgIPAddr.getHostName()));
+            sb.append(getShortName(getFastHostName(jgIPAddr)));
       }
       sb.append(":" + jgAddress.getPort());
       this.jgId = sb.toString();
@@ -163,6 +163,38 @@
 
    // Private -------------------------------------------------------
    
+   /**
+    * Tries to determine the hostname of the given InetAddress without 
+    * triggering a reverse DNS lookup.  Tries to parse a symbolic hostname 
+    * from {@link InetAddress.toString()}, which is documented to return a 
+    * String of the form "symbolicname/ipaddress" with 'symbolicname' blank 
+    * if not stored in the object.
+    * <p/>
+    * If the symbolic name cannot be determined from InetAddress.toString(),
+    * the value of {@link InetAddress.getHostAddress()} is returned.
+    */
+   private String getFastHostName(InetAddress address)
+   {
+      String result = null;
+      
+      String inetAddr = address.toString();
+      int idx = inetAddr.indexOf(address.getHostAddress());
+      int idx1 = inetAddr.lastIndexOf('/');
+      if (idx1 == idx + 1)
+      {
+         if (idx1 == 0)
+            result = address.getHostAddress();
+         else
+            result = inetAddr.substring(0, idx1);
+      }
+      else
+      {
+         // Doesn't follow the toString() contract!
+         result = address.getHostAddress();
+      }
+      return result;
+   }
+   
    // Inner classes -------------------------------------------------
 
 }




More information about the jboss-cvs-commits mailing list