Author: ron.sigal(a)jboss.com
Date: 2010-07-22 11:54:55 -0400 (Thu, 22 Jul 2010)
New Revision: 5923
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/ident/Identity.java
Log:
JBREM-1234: Gets localhost in a static block; added Logger.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ident/Identity.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ident/Identity.java 2010-07-22
15:54:27 UTC (rev 5922)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ident/Identity.java 2010-07-22
15:54:55 UTC (rev 5923)
@@ -21,6 +21,7 @@
*/
package org.jboss.remoting.ident;
+import org.jboss.logging.Logger;
import org.jboss.remoting.network.NetworkRegistry;
import org.jboss.remoting.util.SecurityUtility;
@@ -66,7 +67,81 @@
}
private static transient Map identities = new WeakHashMap(2);
+
+ private static final Logger log = Logger.getLogger(Identity.class);
+ 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(Identity.class.getName() + " unable to get local host
address", e.getCause());
+ throw new ExceptionInInitializerError(e.getCause());
+ }
+ catch (SecurityException e)
+ {
+ log.debug(Identity.class.getName() + " unable to get local host
address", e);
+ throw e;
+ }
+ }
+
+ static private InetAddress getLocalHost() throws UnknownHostException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return doGetLocalHost();
+ }
+
+ try
+ {
+ return (InetAddress) AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+ public Object run() throws UnknownHostException
+ {
+ return doGetLocalHost();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (UnknownHostException) e.getCause();
+ }
+ }
+
+ 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");
+ }
+ }
+
private final String instanceid;
private final InetAddress ip;
private final String serverid;
@@ -562,41 +637,4 @@
throw (RuntimeException) e.getCause();
}
}
-
- static private InetAddress getLocalHost() throws UnknownHostException
- {
- if (SecurityUtility.skipAccessControl())
- {
- try
- {
- return InetAddress.getLocalHost();
- }
- catch (IOException e)
- {
- return InetAddress.getByName("127.0.0.1");
- }
- }
-
- try
- {
- return (InetAddress) AccessController.doPrivileged( new
PrivilegedExceptionAction()
- {
- public Object run() throws IOException
- {
- try
- {
- return InetAddress.getLocalHost();
- }
- catch (IOException e)
- {
- return InetAddress.getByName("127.0.0.1");
- }
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw (UnknownHostException) e.getCause();
- }
- }
}
Show replies by date