[jboss-remoting-commits] JBoss Remoting SVN: r5919 - remoting2/branches/2.x/src/main/org/jboss/remoting.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Thu Jul 22 11:52:22 EDT 2010


Author: ron.sigal at jboss.com
Date: 2010-07-22 11:52:22 -0400 (Thu, 22 Jul 2010)
New Revision: 5919

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
Log:
JBREM-1234: Gets localhost in a static block.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java	2010-07-22 15:51:49 UTC (rev 5918)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java	2010-07-22 15:52:22 UTC (rev 5919)
@@ -230,7 +230,39 @@
    // Static ---------------------------------------------------------------------------------------
 
    private static boolean trace = log.isTraceEnabled();
+   private static final InetAddress LOCAL_HOST;
 
+   static
+   {
+      try
+      {
+         LOCAL_HOST = (InetAddress) AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws UnknownHostException
+            {
+               try
+               {
+                  return InetAddress.getLocalHost();
+               }
+               catch (UnknownHostException e)
+               {
+                  return InetAddress.getByName("127.0.0.1");
+               }
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         log.debug(ServerInvoker.class.getName() + " unable to get local host address", e.getCause());
+         throw new ExceptionInInitializerError(e.getCause());
+      }
+      catch (SecurityException e)
+      {
+         log.debug(ServerInvoker.class.getName() + " unable to get local host address", e);
+         throw e;
+      }
+   }
+
    // Attributes -----------------------------------------------------------------------------------
 
    /**
@@ -2203,30 +2235,16 @@
    {
       if (SecurityUtility.skipAccessControl())
       {
-         try
-         {
-            return InetAddress.getLocalHost();
-         }
-         catch (IOException e)
-         {
-            return InetAddress.getByName("127.0.0.1");
-         }
+         return doGetLocalHost();
       }
 
       try
       {
          return (InetAddress) AccessController.doPrivileged( new PrivilegedExceptionAction()
          {
-            public Object run() throws IOException
+            public Object run() throws UnknownHostException
             {
-               try
-               {
-                  return InetAddress.getLocalHost();
-               }
-               catch (IOException e)
-               {
-                  return InetAddress.getByName("127.0.0.1");
-               }
+               return doGetLocalHost();
             }
          });
       }
@@ -2236,6 +2254,23 @@
       }
    }
    
+   static private InetAddress doGetLocalHost() throws UnknownHostException
+   {
+      if (LOCAL_HOST != null)
+      {
+         return LOCAL_HOST;
+      }
+
+      try
+      {
+         return InetAddress.getLocalHost();
+      }
+      catch (UnknownHostException e)
+      {
+         return InetAddress.getByName("127.0.0.1");
+      }
+   }
+   
    static private InetAddress getAddressByName(final String host) throws UnknownHostException
    {
       if (SecurityUtility.skipAccessControl())



More information about the jboss-remoting-commits mailing list