activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r758268 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Date Wed, 25 Mar 2009 14:30:54 GMT
Author: gtully
Date: Wed Mar 25 14:30:50 2009
New Revision: 758268

URL: http://svn.apache.org/viewvc?rev=758268&view=rev
Log:
add waitUntilStarted to broker service so it is possible to wait till recovery is complete

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.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=758268&r1=758267&r2=758268&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 Mar 25 14:30:50 2009
@@ -29,6 +29,7 @@
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import javax.management.MBeanServer;
 import javax.management.MalformedObjectNameException;
@@ -161,6 +162,7 @@
     private int persistenceThreadPriority = Thread.MAX_PRIORITY;
     private boolean useLocalHostBrokerName;
     private CountDownLatch stoppedLatch = new CountDownLatch(1);
+    private CountDownLatch startedLatch = new CountDownLatch(1);
     private boolean supportFailOver;
     private Broker regionBroker;
     private int producerSystemUsagePortion = 60;
@@ -481,6 +483,7 @@
             brokerId = broker.getBrokerId();
             LOG.info("ActiveMQ JMS Message Broker (" + getBrokerName() + ", " + brokerId
+ ") started");
             getBroker().brokerServiceStarted();
+            startedLatch.countDown();
         } catch (Exception e) {
             LOG.error("Failed to start ActiveMQ JMS Message Broker. Reason: " + e, e);
             try{
@@ -553,7 +556,7 @@
      * stopped
      */
     public void waitUntilStopped() {
-        while (!stopped.get()) {
+        while (isStarted() && !stopped.get()) {
             try {
                 stoppedLatch.await();
             } catch (InterruptedException e) {
@@ -562,6 +565,21 @@
         }
     }
 
+    
+    /**
+     * A helper method to block the caller thread until the broker has been
+     * started
+     */
+    public void waitUntilStarted() {
+        boolean waitSucceeded = false;
+        while (isStarted() && !stopped.get() && !waitSucceeded) {
+            try {
+                waitSucceeded = startedLatch.await(100L, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException ignore) {
+            }
+        }
+    }
+
     // Properties
     // -------------------------------------------------------------------------
 



Mime
View raw message