Author: ron.sigal(a)jboss.com
Date: 2010-07-22 11:55:52 -0400 (Thu, 22 Jul 2010)
New Revision: 5925
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java
Log:
JBREM-1234: Gets localhost in a static block; made Logger static.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java 2010-07-22
15:55:26 UTC (rev 5924)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java 2010-07-22
15:55:52 UTC (rev 5925)
@@ -151,8 +151,40 @@
private boolean isStarted = false;
private boolean isCreated = false;
- protected final Logger log = Logger.getLogger(getClass());
+ protected static final Logger log = Logger.getLogger(Connector.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(Connector.class.getName() + " unable to get local host
address", e.getCause());
+ throw new ExceptionInInitializerError(e.getCause());
+ }
+ catch (SecurityException e)
+ {
+ log.debug(Connector.class.getName() + " unable to get local host
address", e);
+ throw e;
+ }
+ }
+
/**
* Empty constructor.
*/
@@ -1540,30 +1572,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();
}
});
}
@@ -1572,4 +1590,21 @@
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");
+ }
+ }
}