Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C3E63200C38 for ; Tue, 7 Feb 2017 17:33:40 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id C2A03160B32; Tue, 7 Feb 2017 16:33:40 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BDFB3160B6D for ; Tue, 7 Feb 2017 17:33:39 +0100 (CET) Received: (qmail 37121 invoked by uid 500); 7 Feb 2017 16:33:39 -0000 Mailing-List: contact commits-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list commits@brooklyn.apache.org Received: (qmail 36977 invoked by uid 99); 7 Feb 2017 16:33:38 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Feb 2017 16:33:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AEE5ADFE46; Tue, 7 Feb 2017 16:33:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: svet@apache.org To: commits@brooklyn.apache.org Date: Tue, 07 Feb 2017 16:33:40 -0000 Message-Id: <6aa0a6f8162541e79dfba4ec958b6210@git.apache.org> In-Reply-To: <1ff0859418e642f8afaf36248d03ffeb@git.apache.org> References: <1ff0859418e642f8afaf36248d03ffeb@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/6] brooklyn-server git commit: Only shut down the SingleThreadExecutor we control in the repeater archived-at: Tue, 07 Feb 2017 16:33:40 -0000 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 Authored: Tue Jan 31 16:04:22 2017 +0000 Committer: Andrew Donald Kennedy 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 { private boolean rethrowException = false; private Predicate 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 { */ 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 { } public ReferenceWithError 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 { } return ReferenceWithError.newInstanceMaskingError(false, lastError); } - + Time.sleep(delayThisIteration); } } finally { - executor.shutdownNow(); + if (shutdown) { + executor.shutdownNow(); + } } }