mirror of https://github.com/apache/activemq.git
add waitUntilStarted to broker service so it is possible to wait till recovery is complete
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@758268 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fb9a292be1
commit
31c7e620c2
|
@ -29,6 +29,7 @@ import java.util.Map;
|
|||
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 @@ public class BrokerService implements Service {
|
|||
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 @@ public class BrokerService implements Service {
|
|||
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 @@ public class BrokerService implements Service {
|
|||
* stopped
|
||||
*/
|
||||
public void waitUntilStopped() {
|
||||
while (!stopped.get()) {
|
||||
while (isStarted() && !stopped.get()) {
|
||||
try {
|
||||
stoppedLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -562,6 +565,21 @@ public class BrokerService implements Service {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue