From 71e45856897dd96d403e01fdf1f912b1420444c8 Mon Sep 17 00:00:00 2001 From: rajdavies Date: Tue, 10 Dec 2013 09:09:21 +0000 Subject: [PATCH] Fix for https://issues.apache.org/jira/browse/AMQ-4825 --- .../broker/jmx/NetworkBridgeView.java | 5 ++ .../broker/jmx/NetworkBridgeViewMBean.java | 2 + .../DemandForwardingBridgeSupport.java | 5 ++ .../activemq/network/NetworkBridge.java | 5 ++ .../activemq/ActiveMQConnectionFactory.java | 60 ++++++++++++++++++- .../org/apache/activemq/bugs/AMQ4160Test.java | 5 ++ 6 files changed, 80 insertions(+), 2 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/NetworkBridgeView.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/NetworkBridgeView.java index 47f167a89d..c5577545e9 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/NetworkBridgeView.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/NetworkBridgeView.java @@ -51,6 +51,11 @@ public class NetworkBridgeView implements NetworkBridgeViewMBean { return bridge.getRemoteBrokerName(); } + + public String getRemoteBrokerId() { + return bridge.getRemoteBrokerId(); + } + public String getLocalBrokerName() { return bridge.getLocalBrokerName(); } diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/NetworkBridgeViewMBean.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/NetworkBridgeViewMBean.java index b8733d12a3..639a81aa4b 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/NetworkBridgeViewMBean.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/NetworkBridgeViewMBean.java @@ -26,6 +26,8 @@ public interface NetworkBridgeViewMBean extends Service { String getRemoteBrokerName(); + String getRemoteBrokerId(); + String getLocalBrokerName(); long getEnqueueCounter(); diff --git a/activemq-broker/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java b/activemq-broker/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java index 9fa38a4a9f..1126d22e5e 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java +++ b/activemq-broker/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java @@ -1498,6 +1498,11 @@ public abstract class DemandForwardingBridgeSupport implements NetworkBridge, Br return remoteBrokerInfo == null ? null : remoteBrokerInfo.getBrokerName(); } + @Override + public String getRemoteBrokerId() { + return (remoteBrokerInfo == null || remoteBrokerInfo.getBrokerId() ==null)? null : remoteBrokerInfo.getBrokerId().toString(); + } + @Override public String getLocalBrokerName() { return localBrokerInfo == null ? null : localBrokerInfo.getBrokerName(); diff --git a/activemq-broker/src/main/java/org/apache/activemq/network/NetworkBridge.java b/activemq-broker/src/main/java/org/apache/activemq/network/NetworkBridge.java index 95d04772b3..4ed03dcd79 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/network/NetworkBridge.java +++ b/activemq-broker/src/main/java/org/apache/activemq/network/NetworkBridge.java @@ -53,6 +53,11 @@ public interface NetworkBridge extends Service { */ String getRemoteBrokerName(); + /** + * @return the id of the remote broker this bridge is connected to. + */ + String getRemoteBrokerId(); + /** * @return the network address of the local broker connection. */ diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java index 58fee6e7e7..8495d84f99 100755 --- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java +++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java @@ -18,6 +18,8 @@ package org.apache.activemq; import java.net.URI; import java.net.URISyntaxException; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -32,7 +34,6 @@ import javax.jms.QueueConnectionFactory; import javax.jms.TopicConnection; import javax.jms.TopicConnectionFactory; import javax.naming.Context; - import org.apache.activemq.blob.BlobTransferPolicy; import org.apache.activemq.broker.region.policy.RedeliveryPolicyMap; import org.apache.activemq.jndi.JNDIBaseStorable; @@ -48,6 +49,8 @@ import org.apache.activemq.util.IntrospectionSupport; import org.apache.activemq.util.JMSExceptionSupport; import org.apache.activemq.util.URISupport; import org.apache.activemq.util.URISupport.CompositeData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A ConnectionFactory is an an Administered object, and is used for creating @@ -59,8 +62,61 @@ import org.apache.activemq.util.URISupport.CompositeData; * @see javax.jms.ConnectionFactory */ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory, StatsCapable, Cloneable { + private static final Logger LOG = LoggerFactory.getLogger(ActiveMQConnectionFactory.class); + private static final String DEFAULT_BROKER_HOST; + private static final int DEFAULT_BROKER_PORT; + static{ + String host = null; + String port = null; + try { + host = AccessController.doPrivileged(new PrivilegedAction() { + @Override + public String run() { + String result = System.getProperty("org.apache.activemq.AMQ_HOST"); + result = (result==null||result.isEmpty()) ? System.getProperty("AMQ_HOST","localhost") : result; + return result; + } + }); + port = AccessController.doPrivileged(new PrivilegedAction() { + @Override + public String run() { + String result = System.getProperty("org.apache.activemq.AMQ_PORT"); + result = (result==null||result.isEmpty()) ? System.getProperty("AMQ_PORT","61616") : result; + return result; + } + }); + }catch(Throwable e){ + LOG.debug("Failed to look up System properties for host and port",e); + } + host = (host == null || host.isEmpty()) ? "localhost" : host; + port = (port == null || port.isEmpty()) ? "61616" : port; + DEFAULT_BROKER_HOST = host; + DEFAULT_BROKER_PORT = Integer.parseInt(port); + } + + + public static final String DEFAULT_BROKER_BIND_URL; + + static{ + final String defaultURL = "tcp://" + DEFAULT_BROKER_HOST + ":" + DEFAULT_BROKER_PORT; + String bindURL = null; + + try { + bindURL = AccessController.doPrivileged(new PrivilegedAction() { + @Override + public String run() { + String result = System.getProperty("org.apache.activemq.BROKER_BIND_URL"); + result = (result==null||result.isEmpty()) ? System.getProperty("BROKER_BIND_URL",defaultURL) : result; + return result; + } + }); + }catch(Throwable e){ + LOG.debug("Failed to look up System properties for host and port",e); + } + bindURL = (bindURL == null || bindURL.isEmpty()) ? defaultURL : bindURL; + DEFAULT_BROKER_BIND_URL = bindURL; + } - public static final String DEFAULT_BROKER_BIND_URL = "tcp://localhost:61616"; public static final String DEFAULT_BROKER_URL = "failover://"+DEFAULT_BROKER_BIND_URL; public static final String DEFAULT_USER = null; public static final String DEFAULT_PASSWORD = null; diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4160Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4160Test.java index 34bff2d068..4867f28c6e 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4160Test.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4160Test.java @@ -302,6 +302,11 @@ public class AMQ4160Test extends JmsMultipleBrokersTestSupport { return next.getRemoteBrokerName(); } + @Override + public String getRemoteBrokerId() { + return next.getRemoteBrokerId(); + } + @Override public String getLocalAddress() { return next.getLocalAddress();