You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ha...@apache.org on 2014/12/16 23:09:52 UTC

[04/16] activemq git commit: AMQ-5086. Fix the timeout arithmetic

AMQ-5086. Fix the timeout arithmetic


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

Branch: refs/heads/activemq-5.10.x
Commit: 59109a669fe7de89ad833d3369e6fb68f3d93fc9
Parents: 4298966
Author: Hadrian Zbarcea <ha...@apache.org>
Authored: Thu Jul 3 14:53:30 2014 -0400
Committer: Hadrian Zbarcea <ha...@apache.org>
Committed: Mon Dec 15 19:00:06 2014 -0500

----------------------------------------------------------------------
 .../apache/activemq/broker/BrokerService.java    | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/59109a66/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java b/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java
index 3c542ce..00d4abd 100644
--- a/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java
@@ -137,6 +137,7 @@ public class BrokerService implements Service {
     public static final String BROKER_VERSION;
     public static final String DEFAULT_BROKER_NAME = "localhost";
     public static final int DEFAULT_MAX_FILE_LENGTH = 1024 * 1024 * 32;
+    public static final long DEFAULT_START_TIMEOUT = 600000L;
 
     private static final Logger LOG = LoggerFactory.getLogger(BrokerService.class);
 
@@ -156,7 +157,7 @@ public class BrokerService implements Service {
     private boolean shutdownOnMasterFailure;
     private boolean shutdownOnSlaveFailure;
     private boolean waitForSlave;
-    private long waitForSlaveTimeout = 600000L;
+    private long waitForSlaveTimeout = DEFAULT_START_TIMEOUT;
     private boolean passiveSlave;
     private String brokerName = DEFAULT_BROKER_NAME;
     private File dataDirectoryFile;
@@ -248,7 +249,6 @@ public class BrokerService implements Service {
     private boolean restartRequested = false;
 
     private int storeOpenWireVersion = OpenWireFormat.DEFAULT_VERSION;
-    private String configurationUrl;
 
     static {
 
@@ -914,8 +914,21 @@ public class BrokerService implements Service {
      * @return boolean true if wait succeeded false if broker was not started or was stopped
      */
     public boolean waitUntilStarted() {
+        return waitUntilStarted(DEFAULT_START_TIMEOUT);
+    }
+
+    /**
+     * A helper method to block the caller thread until the broker has fully started
+     *
+     * @param timeout
+     *        the amount of time to wait before giving up and returning false.
+     *
+     * @return boolean true if wait succeeded false if broker was not started or was stopped
+     */
+    public boolean waitUntilStarted(long timeout) {
         boolean waitSucceeded = isStarted();
-        while (!isStarted() && !stopped.get() && !waitSucceeded) {
+        long expiration = Math.max(0, timeout + System.currentTimeMillis());
+        while (!isStarted() && !stopped.get() && !waitSucceeded && expiration > System.currentTimeMillis()) {
             try {
                 if (startException != null) {
                     return waitSucceeded;