brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [3/6] brooklyn-server git commit: Only shut down the SingleThreadExecutor we control in the repeater
Date Tue, 07 Feb 2017 16:33:40 GMT
Only shut down the SingleThreadExecutor we control in the repeater


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/68664b83
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/68664b83
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/68664b83

Branch: refs/heads/master
Commit: 68664b8382da6daab7fbcad36f8a40c43a6844b4
Parents: a9b945e
Author: Andrew Donald Kennedy <andrew.kennedy@cloudsoftcorp.com>
Authored: Tue Jan 31 16:04:22 2017 +0000
Committer: Andrew Donald Kennedy <andrew.kennedy@cloudsoftcorp.com>
Committed: Tue Jan 31 16:04:22 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/brooklyn/util/repeat/Repeater.java   | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/68664b83/utils/common/src/main/java/org/apache/brooklyn/util/repeat/Repeater.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/repeat/Repeater.java b/utils/common/src/main/java/org/apache/brooklyn/util/repeat/Repeater.java
index 946f0ba..4f371de 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/repeat/Repeater.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/repeat/Repeater.java
@@ -89,6 +89,7 @@ public class Repeater implements Callable<Boolean> {
     private boolean rethrowException = false;
     private Predicate<? super Throwable> rethrowImmediatelyCondition = Exceptions.isFatalPredicate();
     private boolean warnOnUnRethrownException = true;
+    private boolean shutdown = false;
     private ExecutorService executor = MoreExecutors.sameThreadExecutor();
 
     public Repeater() {
@@ -153,12 +154,13 @@ public class Repeater implements Callable<Boolean> {
      */
     public Repeater threaded() {
         this.executor = Executors.newSingleThreadExecutor();
+        this.shutdown = true;
         return this;
     }
 
     /**
      * @see #threaded()
-     * @param executor an {@link ExecutorService} to use when creating threads.
+     * @param executor an externally managed {@link ExecutorService} to use when creating
threads.
      * @return {@literal this} to aid coding in a fluent style.
      */
     public Repeater threaded(ExecutorService executor) {
@@ -343,6 +345,7 @@ public class Repeater implements Callable<Boolean> {
     }
 
     public ReferenceWithError<Boolean> runKeepingError() {
+        Preconditions.checkNotNull(body, "repeat() method has not been called to set the
body");
         Preconditions.checkNotNull(exitCondition, "until() method has not been called to
set the exit condition");
         Preconditions.checkNotNull(delayOnIteration, "every() method (or other delaySupplier()
/ backoff() method) has not been called to set the loop delay");
 
@@ -417,11 +420,13 @@ public class Repeater implements Callable<Boolean> {
                     }
                     return ReferenceWithError.newInstanceMaskingError(false, lastError);
                 }
-    
+
                 Time.sleep(delayThisIteration);
             }
         } finally {
-           executor.shutdownNow();
+            if (shutdown) {
+                executor.shutdownNow();
+            }
         }
     }
 


Mime
View raw message