activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bsny...@apache.org
Subject svn commit: r1028143 - in /activemq/trunk/activemq-core/src/main/java/org/apache/activemq: broker/ broker/region/ transport/tcp/ transport/udp/ util/
Date Wed, 27 Oct 2010 23:56:41 GMT
Author: bsnyder
Date: Wed Oct 27 23:56:40 2010
New Revision: 1028143

URL: http://svn.apache.org/viewvc?rev=1028143&view=rev
Log:
AMQ-2965 - Patched to allow ActiveMQ to start up when DNS resolution is unavailable

Added:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/InetAddressUtil.java
  (with props)
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransport.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?rev=1028143&r1=1028142&r2=1028143&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Wed Oct 27 23:56:40 2010
@@ -197,7 +197,7 @@ public class BrokerService implements Se
 	static {
         String localHostName = "localhost";
         try {
-            localHostName = java.net.InetAddress.getLocalHost().getHostName();
+            localHostName =  InetAddressUtil.getLocalHostName();
         } catch (UnknownHostException e) {
             LOG.error("Failed to resolve localhost");
         }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java?rev=1028143&r1=1028142&r2=1028143&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java
Wed Oct 27 23:56:40 2010
@@ -64,6 +64,7 @@ import org.apache.activemq.thread.TaskRu
 import org.apache.activemq.usage.SystemUsage;
 import org.apache.activemq.util.BrokerSupport;
 import org.apache.activemq.util.IdGenerator;
+import org.apache.activemq.util.InetAddressUtil;
 import org.apache.activemq.util.LongSequenceGenerator;
 import org.apache.activemq.util.ServiceStopper;
 import org.apache.commons.logging.Log;
@@ -615,7 +616,7 @@ public class RegionBroker extends EmptyB
     public String getBrokerName() {
         if (brokerName == null) {
             try {
-                brokerName = java.net.InetAddress.getLocalHost().getHostName().toLowerCase();
+                brokerName = InetAddressUtil.getLocalHostName().toLowerCase();
             } catch (Exception e) {
                 brokerName = "localhost";
             }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java?rev=1028143&r1=1028142&r2=1028143&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
Wed Oct 27 23:56:40 2010
@@ -40,6 +40,7 @@ import org.apache.activemq.Service;
 import org.apache.activemq.transport.Transport;
 import org.apache.activemq.transport.TransportLoggerFactory;
 import org.apache.activemq.transport.TransportThreadSupport;
+import org.apache.activemq.util.InetAddressUtil;
 import org.apache.activemq.util.IntrospectionSupport;
 import org.apache.activemq.util.ServiceStopper;
 import org.apache.activemq.wireformat.WireFormat;
@@ -400,7 +401,7 @@ public class TcpTransport extends Transp
     // -------------------------------------------------------------------------
     protected String resolveHostName(String host) throws UnknownHostException {
         if (isUseLocalHost()) {
-            String localName = InetAddress.getLocalHost().getHostName();
+            String localName = InetAddressUtil.getLocalHostName();
             if (localName != null && localName.equals(host)) {
                 return "localhost";
             }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java?rev=1028143&r1=1028142&r2=1028143&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java
Wed Oct 27 23:56:40 2010
@@ -43,6 +43,7 @@ import org.apache.activemq.transport.Tra
 import org.apache.activemq.transport.TransportServer;
 import org.apache.activemq.transport.TransportServerThreadSupport;
 import org.apache.activemq.util.IOExceptionSupport;
+import org.apache.activemq.util.InetAddressUtil;
 import org.apache.activemq.util.IntrospectionSupport;
 import org.apache.activemq.util.ServiceListener;
 import org.apache.activemq.util.ServiceStopper;
@@ -332,7 +333,7 @@ public class TcpTransportServer extends 
         if (socket.isBound()) {
             if (socket.getInetAddress().isAnyLocalAddress()) {
                 // make it more human readable and useful, an alternative to 0.0.0.0
-                result = InetAddress.getLocalHost().getHostName();
+                result = InetAddressUtil.getLocalHostName();
             } else {
                 result = socket.getInetAddress().getCanonicalHostName();
             }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransport.java?rev=1028143&r1=1028142&r2=1028143&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransport.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/udp/UdpTransport.java
Wed Oct 27 23:56:40 2010
@@ -39,6 +39,7 @@ import org.apache.activemq.transport.rel
 import org.apache.activemq.transport.reliable.ReplayBuffer;
 import org.apache.activemq.transport.reliable.ReplayStrategy;
 import org.apache.activemq.transport.reliable.Replayer;
+import org.apache.activemq.util.InetAddressUtil;
 import org.apache.activemq.util.IntSequenceGenerator;
 import org.apache.activemq.util.ServiceStopper;
 import org.apache.commons.logging.Log;
@@ -340,7 +341,7 @@ public class UdpTransport extends Transp
     }
 
     protected String resolveHostName(String host) throws UnknownHostException {
-        String localName = InetAddress.getLocalHost().getHostName();
+        String localName = InetAddressUtil.getLocalHostName();
         if (localName != null && isUseLocalHost()) {
             if (localName.equals(host)) {
                 return "localhost";

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java?rev=1028143&r1=1028142&r2=1028143&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java Wed
Oct 27 23:56:40 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.activemq.util;
 
-import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -51,7 +50,7 @@ public class IdGenerator {
 
         if (canAccessSystemProps) {
             try {
-                hostName = InetAddress.getLocalHost().getHostName();
+                hostName = InetAddressUtil.getLocalHostName();
                 ServerSocket ss = new ServerSocket(0);
                 stub = "-" + ss.getLocalPort() + "-" + System.currentTimeMillis() + "-";
                 Thread.sleep(100);

Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/InetAddressUtil.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/InetAddressUtil.java?rev=1028143&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/InetAddressUtil.java
(added)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/InetAddressUtil.java
Wed Oct 27 23:56:40 2010
@@ -0,0 +1,41 @@
+package org.apache.activemq.util;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class InetAddressUtil {
+
+	/**
+	 * When using the {@link java.net.InetAddress#getHostName()} method in an 
+	 * environment where neither a proper DNS lookup nor an <tt>/etc/hosts</tt>

+	 * entry exists for a given host, the following exception will be thrown: 
+	 * <code>
+	 * java.net.UnknownHostException: &lt;hostname&gt;: &lt;hostname&gt;
+     *  at java.net.InetAddress.getLocalHost(InetAddress.java:1425)
+     *   ...
+	 * </code>
+	 * Instead of just throwing an UnknownHostException and giving up, this 
+	 * method grabs a suitable hostname from the exception and prevents the 
+	 * exception from being thrown. If a suitable hostname cannot be acquired
+	 * from the exception, only then is the <tt>UnknownHostException</tt> thrown.

+	 * 
+	 * @return The hostname 
+	 * @throws UnknownHostException
+	 * @see {@link java.net.InetAddress#getLocalHost()}
+	 * @see {@link java.net.InetAddress#getHostName()}
+	 */
+	public static String getLocalHostName() throws UnknownHostException {
+		try {
+			return (InetAddress.getLocalHost()).getHostName();
+		} catch (UnknownHostException uhe) {
+			String host = uhe.getMessage(); // host = "hostname: hostname"
+			if (host != null) {
+				int colon = host.indexOf(':');
+				if (colon > 0) {
+					return host.substring(0, colon);
+				}
+			}
+			throw uhe;
+		}
+	}
+}

Propchange: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/InetAddressUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/InetAddressUtil.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision



Mime
View raw message