Github user alasdairhodge commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/584#discussion_r104919958
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/entity/Entities.java 
---
    @@ -1237,25 +1239,32 @@ public static void warnOnIgnoringConfig(Entity 
entity, ConfigKey<?> key) {
                 log.warn("Ignoring "+key+" set on "+entity+" 
("+entity.getConfig(key)+")");
         }
     
    -    /** Waits until {@link Startable#SERVICE_UP} returns true. */
    -    public static void waitForServiceUp(final Entity entity, Duration 
timeout) {
    -        String description = "Waiting for SERVICE_UP on "+entity;
    -        Tasks.setBlockingDetails(description);
    +    /** Waits until the passed entity satisfies the supplied predicate. */
    +    public static void waitFor(Entity entity, Predicate<Entity> condition, 
Duration timeout) {
             try {
    -            if (!Repeater.create(description).limitTimeTo(timeout)
    -                    .rethrowException().backoffTo(Duration.ONE_SECOND)
    -                    .until(new Callable<Boolean>() {
    -                        @Override
    -                        public Boolean call() {
    -                            return 
Boolean.TRUE.equals(entity.getAttribute(Startable.SERVICE_UP));
    -                        }})
    -                    .run()) {
    -                throw new IllegalStateException("Timeout waiting for 
SERVICE_UP from "+entity);
    +            String description = "Waiting for " + condition + " on " + 
entity;
    +            Tasks.setBlockingDetails(description);
    +
    +            Repeater repeater = Repeater.create(description)
    +                .until(isSatisfied(entity, condition))
    +                .limitTimeTo(timeout)
    +                .backoffTo(Duration.ONE_SECOND)
    +                .rethrowException();
    +
    +            if (!repeater.run()) {
    +                throw new IllegalStateException("Timeout waiting for " + 
condition + " on " + entity);
                 }
    +
             } finally {
                 Tasks.resetBlockingDetails();
             }
    -        log.debug("Detected SERVICE_UP for software {}", entity);
    +
    +        log.debug("Detected {} for {}", condition, entity);
    +    }
    +
    +    /** Waits until {@link Startable#SERVICE_UP} returns true. */
    +    public static void waitForServiceUp(final Entity entity, Duration 
timeout) {
    +        waitFor(entity, attributeEqualTo(Startable.SERVICE_UP, true), 
timeout);
    --- End diff --
    
    Excellent idea.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to