Author: ron.sigal(a)jboss.com
Date: 2010-07-22 11:51:49 -0400 (Thu, 22 Jul 2010)
New Revision: 5918
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerLocator.java
Log:
JBREM-1234: Gets localhost in a static block.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerLocator.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerLocator.java 2010-07-22
15:51:21 UTC (rev 5917)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerLocator.java 2010-07-22
15:51:49 UTC (rev 5918)
@@ -254,11 +254,11 @@
boolean byHost = Boolean.valueOf(bindByHost).booleanValue();
if(byHost)
{
- return InetAddress.getLocalHost().getHostName();
+ return getLocalHost().getHostName();
}
else
{
- return InetAddress.getLocalHost().getHostAddress();
+ return getLocalHost().getHostAddress();
}
}
});
@@ -347,7 +347,56 @@
return b.toString();
}
+ 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(InvokerLocator.class.getName() + " unable to get local host
address", e.getCause());
+ throw new ExceptionInInitializerError(e.getCause());
+ }
+ catch (SecurityException e)
+ {
+ log.debug(InvokerLocator.class.getName() + " unable to get local host
address", e);
+ throw e;
+ }
+ }
+ private static InetAddress getLocalHost() throws UnknownHostException
+ {
+ if (LOCAL_HOST != null)
+ {
+ return LOCAL_HOST;
+ }
+
+ try
+ {
+ return InetAddress.getLocalHost();
+ }
+ catch (UnknownHostException e)
+ {
+ return InetAddress.getByName("127.0.0.1");
+ }
+ }
+
/**
* Constructs the object used to identify a remoting server via simple uri format
string (e.g. socket://myhost:7000).
* Note: the uri passed may not always be the one returned via call to getLocatorURI()
as may need to change if
@@ -555,11 +604,11 @@
if(byHost)
{
- return InetAddress.getLocalHost().getHostName();
+ return getLocalHost().getHostName();
}
else
{
- return InetAddress.getLocalHost().getHostAddress();
+ return getLocalHost().getHostAddress();
}
}
});
Show replies by date