brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/3] incubator-brooklyn git commit: Add timeout to attributeWhenReady if entity is in destructive state
Date Thu, 17 Dec 2015 12:08:43 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 08b814117 -> 1c80fb4d1


Add timeout to attributeWhenReady if entity is in destructive state


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

Branch: refs/heads/master
Commit: a6c2ae960381f05678f2508a91a6fe8f8a2627d5
Parents: 89440c3
Author: Mike Zaccardo <mike.zaccardo@cloudsoftcorp.com>
Authored: Fri Dec 4 19:27:03 2015 -0800
Committer: Mike Zaccardo <mike.zaccardo@cloudsoftcorp.com>
Committed: Fri Dec 4 19:27:03 2015 -0800

----------------------------------------------------------------------
 .../core/sensor/DependentConfiguration.java       | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a6c2ae96/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
b/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
index 6c251a7..98cedb0 100644
--- a/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
+++ b/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
@@ -635,10 +635,12 @@ public class DependentConfiguration {
     public static class ProtoBuilder {
         /**
          * Will wait for the attribute on the given entity.
-         * If that entity reports {@link Lifecycle#ON_FIRE} for its {@link Attributes#SERVICE_STATE}
then it will abort. 
+         * If that entity reports {@link Lifecycle#ON_FIRE} for its {@link Attributes#SERVICE_STATE}
then it will abort.
+         * If that entity reports {@link Lifecycle#STOPPING}, {@link Lifecycle#STOPPED},
or {@link Lifecycle#DESTROYED}
+         * then it will timeout after 1 minute.
          */
         public <T2> Builder<T2,T2> attributeWhenReady(Entity source, AttributeSensor<T2>
sensor) {
-            return new Builder<T2,T2>(source, sensor).abortIfOnFire();
+            return new Builder<T2,T2>(source, sensor).abortIfOnFireOrTimeoutIfNecessary();
         }
 
         /**
@@ -722,6 +724,13 @@ public class DependentConfiguration {
             abortIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.ON_FIRE));
             return this;
         }
+        public Builder<T,V> abortIfOnFireOrTimeoutIfNecessary() {
+            abortIfOnFire();
+            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.STOPPING),
Duration.ONE_MINUTE);
+            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.STOPPED),
Duration.ONE_MINUTE);
+            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.DESTROYED),
Duration.ONE_MINUTE);
+            return this;
+        }
         public Builder<T,V> blockingDetails(String val) {
             blockingDetails = val;
             return this;
@@ -731,6 +740,11 @@ public class DependentConfiguration {
             timeout = val;
             return this;
         }
+        /** specifies the supplied timeout if the condition is met */
+        public <T2> Builder<T,V> timeoutIf(Entity source, AttributeSensor<T2>
sensor, Predicate<? super T2> predicate, Duration val) {
+            if (predicate.apply(source.sensors().get(sensor))) timeout(val);
+            return this;
+        }
         public Builder<T,V> onTimeoutReturn(V val) {
             onTimeout = Maybe.of(val);
             return this;


Mime
View raw message