Author: ron.sigal(a)jboss.com
Date: 2010-07-22 11:55:26 -0400 (Thu, 22 Jul 2010)
New Revision: 5924
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/stream/StreamServer.java
Log:
JBREM-1234: Gets localhost in a static block.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/stream/StreamServer.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/stream/StreamServer.java 2010-07-22
15:54:55 UTC (rev 5923)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/stream/StreamServer.java 2010-07-22
15:55:26 UTC (rev 5924)
@@ -73,7 +73,39 @@
public static final String STREAM_HOST_KEY = "remoting.stream.host";
public static final String STREAM_PORT_KEY = "remoting.stream.port";
+ 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(StreamServer.class.getName() + " unable to get local host
address", e.getCause());
+ throw new ExceptionInInitializerError(e.getCause());
+ }
+ catch (SecurityException e)
+ {
+ log.debug(StreamServer.class.getName() + " unable to get local host
address", e);
+ throw e;
+ }
+ }
+
/**
* Creates the server wrapped around the specified input stream.
* This will create the remoting server as well.
@@ -342,30 +374,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();
}
});
}
@@ -375,30 +393,37 @@
}
}
+ 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 String getLocalHostName() throws UnknownHostException
- {
+ {
if (SecurityUtility.skipAccessControl())
{
- return getLocalHost().getHostName();
+ return doGetLocalHost().getHostName();
}
try
{
return (String) AccessController.doPrivileged( new PrivilegedExceptionAction()
{
- public Object run() throws IOException
+ public Object run() throws UnknownHostException
{
- InetAddress address = null;
- try
- {
- address = InetAddress.getLocalHost();
- }
- catch (IOException e)
- {
- address = InetAddress.getByName("127.0.0.1");
- }
-
- return address.getHostName();
+ return doGetLocalHost().getHostName();
}
});
}
Show replies by date