brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahgittin <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Date Wed, 29 Oct 2014 07:37:00 GMT
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19523015
  
    --- Diff: core/src/main/java/brooklyn/util/task/Tasks.java ---
    @@ -421,5 +423,38 @@ public static boolean isInterrupted() {
             if (t==null) return false;
             return t.isCancelled();
         }
    +
    +    private static class WaitForRepeaterCallable implements Callable<Boolean> {
    +        protected Repeater repeater;
    +        protected boolean requireTrue;
    +
    +        public WaitForRepeaterCallable(Repeater repeater, boolean requireTrue) {
    +            this.repeater = repeater;
    +            this.requireTrue = requireTrue;
    +        }
    +
    +        @Override
    +        public Boolean call() {
    +            ReferenceWithError<Boolean> result = repeater.runKeepingError();
    +            if (Boolean.TRUE.equals(result.getWithoutError()))
    +                return true;
    +            if (result.hasError()) 
    +                throw Exceptions.propagate(result.getError());
    +            if (requireTrue)
    +                throw new IllegalStateException("timeout - "+repeater.getDescription());
    +            return false;
    +        }
    +    }
         
    +    /** creates an (unsubmitted) task which waits for the given repeater, optionally
failing if it does not complete with success */
    +    public static TaskAdaptable<Boolean> awaiting(Repeater repeater, boolean requireTrue)
{
    +        return awaitingBuilder(repeater, requireTrue).build();
    +    }
    +
    +    /** creates a partially instantiated builder which waits for the given repeater,
optionally failing if it does not complete with success,
    +     * for further task customization and then {@link TaskBuilder#build()} */
    +    public static TaskBuilder<Boolean> awaitingBuilder(Repeater repeater, boolean
requireTrue) {
    --- End diff --
    
    agree - have refactored, actually preferring to return a builder.  putting `body(Repeater)`
on the builder feels to specialized so instead there are now methods in `Tasks` which generate
a builder from a `Repeater`.


---
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.
---

Mime
View raw message