From a3060e79d969fcf1f769be010c31e098a98a10e2 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Tue, 14 Feb 2012 21:36:04 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-3706 Don't send a URI to the client that equals "null" when the BrokerInfo has no set Broker URI, that sends the failover transport into an infinite reconnect cycle. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1244221 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/broker/TransportConnector.java | 33 +++++++------ .../transport/failover/FailoverTransport.java | 48 +++++++++---------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java b/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java index 3c09d6bb8a..53296ddbe8 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java @@ -16,6 +16,19 @@ */ package org.apache.activemq.broker; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.Random; +import java.util.StringTokenizer; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.regex.Pattern; + +import javax.management.ObjectName; + import org.apache.activemq.broker.jmx.ManagedTransportConnector; import org.apache.activemq.broker.jmx.ManagementContext; import org.apache.activemq.broker.region.ConnectorStatistics; @@ -35,18 +48,6 @@ import org.apache.activemq.util.ServiceSupport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.management.ObjectName; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.Random; -import java.util.StringTokenizer; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.regex.Pattern; - /** * @org.apache.xbean.XBean * @@ -262,7 +263,7 @@ public class TransportConnector implements Connector, BrokerServiceAware { LOG.info("Connector " + getName() + " Started"); } - + public String getPublishableConnectString() throws Exception { return getPublishableConnectString(getConnectUri()); } @@ -413,7 +414,9 @@ public class TransportConnector implements Connector, BrokerServiceAware { uris.add(brokerService.getDefaultSocketURIString()); for (BrokerInfo info: broker.getPeerBrokerInfos()) { if (isMatchesClusterFilter(info.getBrokerName())) { - uris.add(info.getBrokerURL()); + if (info.getBrokerURL() != null) { + uris.add(info.getBrokerURL()); + } } } if (rebalance) { @@ -423,7 +426,7 @@ public class TransportConnector implements Connector, BrokerServiceAware { connectedBrokers += separator + uri; separator = ","; } - + } ConnectionControl control = new ConnectionControl(); control.setConnectedBrokers(connectedBrokers); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java index ff39876cee..5cb16ba063 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java @@ -16,6 +16,26 @@ */ package org.apache.activemq.transport.failover; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.InterruptedIOException; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicReference; + import org.apache.activemq.broker.SslContext; import org.apache.activemq.command.Command; import org.apache.activemq.command.ConnectionControl; @@ -39,26 +59,6 @@ import org.apache.activemq.util.ServiceSupport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.InterruptedIOException; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicReference; - /** * A Transport that is made reliable by being able to fail over to another * transport when a transport failure is detected. @@ -711,7 +711,7 @@ public class FailoverTransport implements CompositeTransport { if (removed) { updated.add(failedConnectTransportURI); } - } + } return updated; } ArrayList l = new ArrayList(uris); @@ -889,7 +889,7 @@ public class FailoverTransport implements CompositeTransport { // If we have a backup already waiting lets try it. synchronized (backupMutex) { if ((priorityBackup || backup) && !backups.isEmpty()) { - ArrayList l = new ArrayList(backups); + ArrayList l = new ArrayList(backups); if (randomize) { Collections.shuffle(l); } @@ -1134,7 +1134,7 @@ public class FailoverTransport implements CompositeTransport { } return false; } - + protected boolean isPriority(URI uri) { if (!priorityList.isEmpty()) { return priorityList.contains(uri); @@ -1180,7 +1180,7 @@ public class FailoverTransport implements CompositeTransport { updated.add(uri); } } - if (!(copy.isEmpty() && updated.isEmpty()) && !copy.equals(new HashSet(updated))) { + if (!(copy.isEmpty() && updated.isEmpty()) && !copy.equals(new HashSet(updated))) { buildBackups(); synchronized (reconnectMutex) { reconnect(rebalance);