activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject git commit: Fixes AMQ-4723: HTTP Discovery agent should only poll for broker URLs while attempting to connect a transport.
Date Thu, 12 Sep 2013 15:16:40 GMT
Updated Branches:
  refs/heads/trunk 8f8aa0f5e -> 272b846b0


Fixes AMQ-4723: HTTP Discovery agent should only poll for broker URLs while attempting to
connect a transport.


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

Branch: refs/heads/trunk
Commit: 272b846b0cc0e865aba1731a27e8eef5ea744639
Parents: 8f8aa0f
Author: Hiram Chirino <hiram@hiramchirino.com>
Authored: Thu Sep 12 11:16:18 2013 -0400
Committer: Hiram Chirino <hiram@hiramchirino.com>
Committed: Thu Sep 12 11:16:34 2013 -0400

----------------------------------------------------------------------
 .../transport/discovery/DiscoveryTransport.java | 24 ++++++++++++
 .../org/apache/activemq/util/Suspendable.java   | 27 ++++++++++++++
 .../discovery/http/HTTPDiscoveryAgent.java      | 39 +++++++++++++++++++-
 3 files changed, 88 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/272b846b/activemq-client/src/main/java/org/apache/activemq/transport/discovery/DiscoveryTransport.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/transport/discovery/DiscoveryTransport.java
b/activemq-client/src/main/java/org/apache/activemq/transport/discovery/DiscoveryTransport.java
index 48cba82..40bca47 100755
--- a/activemq-client/src/main/java/org/apache/activemq/transport/discovery/DiscoveryTransport.java
+++ b/activemq-client/src/main/java/org/apache/activemq/transport/discovery/DiscoveryTransport.java
@@ -24,6 +24,7 @@ import org.apache.activemq.command.DiscoveryEvent;
 import org.apache.activemq.transport.CompositeTransport;
 import org.apache.activemq.transport.TransportFilter;
 import org.apache.activemq.util.ServiceStopper;
+import org.apache.activemq.util.Suspendable;
 import org.apache.activemq.util.URISupport;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -103,4 +104,27 @@ public class DiscoveryTransport extends TransportFilter implements DiscoveryList
        this.parameters = parameters;      
     }
 
+    @Override
+    public void transportResumed() {
+        if( discoveryAgent instanceof Suspendable ) {
+            try {
+                ((Suspendable)discoveryAgent).suspend();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        super.transportResumed();
+    }
+
+    @Override
+    public void transportInterupted() {
+        if( discoveryAgent instanceof Suspendable ) {
+            try {
+                ((Suspendable)discoveryAgent).resume();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        super.transportInterupted();
+    }
 }

http://git-wip-us.apache.org/repos/asf/activemq/blob/272b846b/activemq-client/src/main/java/org/apache/activemq/util/Suspendable.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/util/Suspendable.java b/activemq-client/src/main/java/org/apache/activemq/util/Suspendable.java
new file mode 100644
index 0000000..aa2b9fd
--- /dev/null
+++ b/activemq-client/src/main/java/org/apache/activemq/util/Suspendable.java
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.util;
+
+/**
+ * Interface implemented by services that can be suspended and resumed.
+ */
+public interface Suspendable {
+
+    public void suspend() throws Exception;
+    public void resume() throws Exception;
+
+}

http://git-wip-us.apache.org/repos/asf/activemq/blob/272b846b/activemq-http/src/main/java/org/apache/activemq/transport/discovery/http/HTTPDiscoveryAgent.java
----------------------------------------------------------------------
diff --git a/activemq-http/src/main/java/org/apache/activemq/transport/discovery/http/HTTPDiscoveryAgent.java
b/activemq-http/src/main/java/org/apache/activemq/transport/discovery/http/HTTPDiscoveryAgent.java
index 9e8d4bd..cbce836 100644
--- a/activemq-http/src/main/java/org/apache/activemq/transport/discovery/http/HTTPDiscoveryAgent.java
+++ b/activemq-http/src/main/java/org/apache/activemq/transport/discovery/http/HTTPDiscoveryAgent.java
@@ -31,6 +31,7 @@ import org.apache.activemq.command.DiscoveryEvent;
 import org.apache.activemq.transport.discovery.DiscoveryAgent;
 import org.apache.activemq.transport.discovery.DiscoveryListener;
 import org.apache.activemq.util.IntrospectionSupport;
+import org.apache.activemq.util.Suspendable;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.ResponseHandler;
 import org.apache.http.client.methods.HttpDelete;
@@ -41,7 +42,13 @@ import org.apache.http.impl.client.DefaultHttpClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class HTTPDiscoveryAgent implements DiscoveryAgent {
+public class HTTPDiscoveryAgent implements DiscoveryAgent, Suspendable {
+
+    static enum UpdateState {
+        SUSPENDED,
+        RESUMING,
+        RESUMED
+    }
 
     private static final Logger LOG = LoggerFactory.getLogger(HTTPDiscoveryAgent.class);
 
@@ -65,6 +72,8 @@ public class HTTPDiscoveryAgent implements DiscoveryAgent {
     private boolean useExponentialBackOff = true;
     private int maxReconnectAttempts;
     private final Object sleepMutex = new Object();
+    private final Object updateMutex = new Object();
+    private UpdateState updateState = UpdateState.RESUMED;
     private long minConnectTime = 5000;
 
     class SimpleDiscoveryEvent extends DiscoveryEvent {
@@ -237,7 +246,15 @@ public class HTTPDiscoveryAgent implements DiscoveryAgent {
                     while (running.get()) {
                         try {
                             update();
-                            Thread.sleep(updateInterval);
+                            synchronized (updateMutex) {
+                                do {
+                                    if( updateState == UpdateState.RESUMING ) {
+                                        updateState = UpdateState.RESUMED;
+                                    } else {
+                                        updateMutex.wait(updateInterval);
+                                    }
+                                } while( updateState==UpdateState.SUSPENDED && running.get());
+                            }
                         } catch (InterruptedException e) {
                             return;
                         }
@@ -305,6 +322,7 @@ public class HTTPDiscoveryAgent implements DiscoveryAgent {
 
     public void stop() throws Exception {
         if (startCounter.decrementAndGet() == 0) {
+            resume();
             running.set(false);
             if (thread != null) {
                 thread.join(updateInterval * 3);
@@ -340,4 +358,21 @@ public class HTTPDiscoveryAgent implements DiscoveryAgent {
     public void setStartEmbeddRegistry(boolean startEmbeddRegistry) {
         this.startEmbeddRegistry = startEmbeddRegistry;
     }
+
+
+    @Override
+    public void suspend() throws Exception {
+        synchronized (updateMutex) {
+            updateState = UpdateState.SUSPENDED;
+        }
+    }
+
+    @Override
+    public void resume() throws Exception {
+        synchronized (updateMutex) {
+            updateState = UpdateState.RESUMING;
+            updateMutex.notify();
+        }
+    }
+
 }


Mime
View raw message