Author: ron.sigal(a)jboss.com
Date: 2010-08-02 16:49:49 -0400 (Mon, 02 Aug 2010)
New Revision: 5961
Added:
remoting2/branches/2.2/src/main/org/jboss/remoting/util/LocalHostUtil.java
Log:
JBREM-1235: Provides a fast alternative to InetAddress.getLocalHost().
Added: remoting2/branches/2.2/src/main/org/jboss/remoting/util/LocalHostUtil.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/util/LocalHostUtil.java
(rev 0)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/util/LocalHostUtil.java 2010-08-02
20:49:49 UTC (rev 5961)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @author tags. See the COPYRIGHT.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.jboss.remoting.util;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Aug 2, 2010
+ */
+public class LocalHostUtil
+{
+ private static InetAddress LOCAL_HOST;
+
+ static
+ {
+ try
+ {
+ LOCAL_HOST = InetAddress.getLocalHost();
+ }
+ catch (UnknownHostException e)
+ {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+
+ public static InetAddress getLocalHost() throws UnknownHostException
+ {
+ if (LOCAL_HOST != null)
+ {
+ return LOCAL_HOST;
+ }
+
+ try
+ {
+ return LOCAL_HOST = InetAddress.getLocalHost();
+ }
+ catch (UnknownHostException e)
+ {
+ return InetAddress.getByName("127.0.0.1");
+ }
+ }
+}