activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject activemq git commit: https://issues.apache.org/jira/browse/AMQ-6235
Date Fri, 08 Apr 2016 16:28:40 GMT
Repository: activemq
Updated Branches:
  refs/heads/master c8d96c6e8 -> b1c55fdc7


https://issues.apache.org/jira/browse/AMQ-6235

Honor the initialReconnectDelay configuration in all cases.  

Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/b1c55fdc
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/b1c55fdc
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/b1c55fdc

Branch: refs/heads/master
Commit: b1c55fdc744987245c409af5835fd1a74bdc49ed
Parents: c8d96c6
Author: Timothy Bish <tabish121@gmail.com>
Authored: Fri Apr 8 12:28:19 2016 -0400
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Fri Apr 8 12:28:19 2016 -0400

----------------------------------------------------------------------
 .../discovery/simple/SimpleDiscoveryAgent.java  | 48 ++++++++++++--------
 1 file changed, 28 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/b1c55fdc/activemq-client/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java
b/activemq-client/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java
index 1d05273..d3cdf9e 100755
--- a/activemq-client/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java
+++ b/activemq-client/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java
@@ -51,7 +51,7 @@ public class SimpleDiscoveryAgent implements DiscoveryAgent {
     class SimpleDiscoveryEvent extends DiscoveryEvent {
 
         private int connectFailures;
-        private long reconnectDelay = initialReconnectDelay;
+        private long reconnectDelay = -1;
         private long connectTime = System.currentTimeMillis();
         private final AtomicBoolean failed = new AtomicBoolean(false);
 
@@ -142,32 +142,16 @@ public class SimpleDiscoveryAgent implements DiscoveryAgent {
                     // We detect a failed connection attempt because the service
                     // fails right away.
                     if (event.connectTime + minConnectTime > System.currentTimeMillis())
{
-                        LOG.debug("Failure occurred soon after the discovery event was generated.
 It will be classified as a connection failure: "+event);
+                        LOG.debug("Failure occurred soon after the discovery event was generated.
 It will be classified as a connection failure: {}", event);
 
                         event.connectFailures++;
 
                         if (maxReconnectAttempts > 0 && event.connectFailures
>= maxReconnectAttempts) {
-                            LOG.warn("Reconnect attempts exceeded "+maxReconnectAttempts+"
tries.  Reconnecting has been disabled for: " + event);
+                            LOG.warn("Reconnect attempts exceeded {} tries.  Reconnecting
has been disabled for: {}", maxReconnectAttempts, event);
                             return;
                         }
 
-                        synchronized (sleepMutex) {
-                            try {
-                                if (!running.get()) {
-                                    LOG.debug("Reconnecting disabled: stopped");
-                                    return;
-                                }
-
-                                LOG.debug("Waiting "+event.reconnectDelay+" ms before attempting
to reconnect.");
-                                sleepMutex.wait(event.reconnectDelay);
-                            } catch (InterruptedException ie) {
-                                LOG.debug("Reconnecting disabled: " + ie);
-                                Thread.currentThread().interrupt();
-                                return;
-                            }
-                        }
-
-                        if (!useExponentialBackOff) {
+                        if (!useExponentialBackOff || event.reconnectDelay == -1) {
                             event.reconnectDelay = initialReconnectDelay;
                         } else {
                             // Exponential increment of reconnect delay.
@@ -177,9 +161,15 @@ public class SimpleDiscoveryAgent implements DiscoveryAgent {
                             }
                         }
 
+                        doReconnectDelay(event);
+
                     } else {
+                        LOG.trace("Failure occurred to long after the discovery event was
generated.  " +
+                                  "It will not be classified as a connection failure: {}",
event);
                         event.connectFailures = 0;
                         event.reconnectDelay = initialReconnectDelay;
+
+                        doReconnectDelay(event);
                     }
 
                     if (!running.get()) {
@@ -195,6 +185,24 @@ public class SimpleDiscoveryAgent implements DiscoveryAgent {
         }
     }
 
+    protected void doReconnectDelay(SimpleDiscoveryEvent event) {
+        synchronized (sleepMutex) {
+            try {
+                if (!running.get()) {
+                    LOG.debug("Reconnecting disabled: stopped");
+                    return;
+                }
+
+                LOG.debug("Waiting {}ms before attempting to reconnect.", event.reconnectDelay);
+                sleepMutex.wait(event.reconnectDelay);
+            } catch (InterruptedException ie) {
+                LOG.debug("Reconnecting disabled: ", ie);
+                Thread.currentThread().interrupt();
+                return;
+            }
+        }
+    }
+
     public long getBackOffMultiplier() {
         return backOffMultiplier;
     }


Mime
View raw message