You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2015/12/17 13:08:45 UTC

[3/3] incubator-brooklyn git commit: tidy of dependent configuration methods

tidy of dependent configuration methods


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

Branch: refs/heads/master
Commit: 1c80fb4d1a8dc06138246d2558c30c6dff41db68
Parents: 9df3f2b
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Dec 17 12:08:17 2015 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Dec 17 12:08:17 2015 +0000

----------------------------------------------------------------------
 .../core/sensor/DependentConfiguration.java     | 23 +++++++++++---------
 1 file changed, 13 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1c80fb4d/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 98cedb0..ac4bef5 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
@@ -35,7 +35,6 @@ import java.util.concurrent.TimeUnit;
 import javax.annotation.Nullable;
 
 import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntityLocal;
 import org.apache.brooklyn.api.mgmt.ExecutionContext;
 import org.apache.brooklyn.api.mgmt.SubscriptionHandle;
 import org.apache.brooklyn.api.mgmt.Task;
@@ -504,6 +503,7 @@ public class DependentConfiguration {
         );
     }
 
+    @SuppressWarnings("unchecked")
     private static List<TaskAdaptable<Object>> getTaskAdaptable(Object... args){
         List<TaskAdaptable<Object>> taskArgs = Lists.newArrayList();
         for (Object arg: args) {
@@ -634,13 +634,13 @@ public class DependentConfiguration {
     @Beta
     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#STOPPING}, {@link Lifecycle#STOPPED}, or {@link Lifecycle#DESTROYED}
+         * Will wait for the attribute on the given entity, with default behaviour:
+         * If that entity reports {@link Lifecycle#ON_FIRE} for its {@link Attributes#SERVICE_STATE} then it will abort;
+         * If that entity is stopping or destroyed (see {@link Builder#timeoutIfStoppingOrDestroyed(Duration)}),
          * 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).abortIfOnFireOrTimeoutIfNecessary();
+            return new Builder<T2,T2>(source, sensor).abortIfOnFire().timeoutIfStoppingOrDestroyed(Duration.ONE_MINUTE);
         }
 
         /**
@@ -720,15 +720,18 @@ public class DependentConfiguration {
             abortSensorConditions.add(new AttributeAndSensorCondition<T2>(source, sensor, predicate));
             return this;
         }
+        /** Causes the depender to abort immediately if {@link Attributes#SERVICE_STATE_ACTUAL}
+         * is {@link Lifecycle#ON_FIRE}. */
         public Builder<T,V> abortIfOnFire() {
             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);
+        /** Causes the depender to timeout after the given time if {@link Attributes#SERVICE_STATE_ACTUAL}
+         * is one of {@link Lifecycle#STOPPING}, {@link Lifecycle#STOPPED}, or {@link Lifecycle#DESTROYED}. */
+        public Builder<T,V> timeoutIfStoppingOrDestroyed(Duration time) {
+            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.STOPPING), time);
+            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.STOPPED), time);
+            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.DESTROYED), time);
             return this;
         }
         public Builder<T,V> blockingDetails(String val) {