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 BCE10200C17 for ; Thu, 26 Jan 2017 17:45:49 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id BB6E4160B4C; Thu, 26 Jan 2017 16:45:49 +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 117C1160B50 for ; Thu, 26 Jan 2017 17:45:48 +0100 (CET) Received: (qmail 59033 invoked by uid 500); 26 Jan 2017 16:45:48 -0000 Mailing-List: contact dev-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 dev@brooklyn.apache.org Received: (qmail 58949 invoked by uid 99); 26 Jan 2017 16:45:47 -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; Thu, 26 Jan 2017 16:45:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9CAC3DFC47; Thu, 26 Jan 2017 16:45:47 +0000 (UTC) From: neykov To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #493: Make the Repeater class use a threads to ... Content-Type: text/plain Message-Id: <20170126164547.9CAC3DFC47@git1-us-west.apache.org> Date: Thu, 26 Jan 2017 16:45:47 +0000 (UTC) archived-at: Thu, 26 Jan 2017 16:45:49 -0000 Github user neykov commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/493#discussion_r98035839 --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/repeat/Repeater.java --- @@ -301,89 +332,96 @@ public Repeater limitTimeTo(Duration duration) { public boolean run() { return runKeepingError().getWithoutError(); } - + public void runRequiringTrue() { Stopwatch timer = Stopwatch.createStarted(); ReferenceWithError result = runKeepingError(); result.checkNoError(); - if (!result.get()) + if (!result.get()) { throw new IllegalStateException(description+" unsatisfied after "+Duration.of(timer)); + } } - + public ReferenceWithError runKeepingError() { - Preconditions.checkState(body != null, "repeat() method has not been called to set the body"); - Preconditions.checkState(exitCondition != null, "until() method has not been called to set the exit condition"); - Preconditions.checkState(delayOnIteration != null, "every() method (or other delaySupplier() / backoff() method) has not been called to set the loop delay"); + 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"); boolean hasLoggedTransientException = false; Throwable lastError = null; int iterations = 0; CountdownTimer timer = timeLimit!=null ? CountdownTimer.newInstanceStarted(timeLimit) : CountdownTimer.newInstancePaused(Duration.PRACTICALLY_FOREVER); - while (true) { - Duration delayThisIteration = delayOnIteration.apply(iterations); - iterations++; - - try { - body.call(); - } catch (Throwable e) { - log.warn(description, e); - if (rethrowImmediatelyCondition.apply(e)) throw Exceptions.propagate(e); - } - - boolean done = false; - try { - lastError = null; - done = exitCondition.call(); - hasLoggedTransientException = false; - } catch (Throwable e) { - if (hasLoggedTransientException) { - if (log.isDebugEnabled()) log.debug(description + " (repeated failure; excluding stacktrace): " + e); - } else { - if (log.isDebugEnabled()) log.debug(description, e); - hasLoggedTransientException = true; + try { + while (true) { + Duration delayThisIteration = delayOnIteration.apply(iterations); + iterations++; + + Future call = executor.submit(body); + try { + call.get(delayThisIteration.toMilliseconds(), TimeUnit.MILLISECONDS); --- End diff -- I think a separate time out is needed here, especially when used with `backoff`, but happy to go with this. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---