Author: ron.sigal(a)jboss.com
Date: 2010-07-22 11:51:21 -0400 (Thu, 22 Jul 2010)
New Revision: 5917
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
Log:
JBREM-1234: Gets localhost in a static block.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2010-07-08 21:47:19 UTC
(rev 5916)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2010-07-22 15:51:21 UTC
(rev 5917)
@@ -188,9 +188,82 @@
private static Object invokerDestructionTimerLock = new Object();
private static int clientCounter;
+
+ private static final InetAddress LOCAL_HOST;
// Static
---------------------------------------------------------------------------------------
+ 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(Client.class.getName() + " unable to get local host
address", e.getCause());
+ throw new ExceptionInInitializerError(e.getCause());
+ }
+ catch (SecurityException e)
+ {
+ log.debug(Client.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");
+ }
+ }
+
// Attributes
-----------------------------------------------------------------------------------
/**
@@ -2187,41 +2260,4 @@
return invoker.hashCode() * metadata.hashCode();
}
}
-
- 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