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

[5/9] incubator-brooklyn git commit: Make Repeater implement Callable

Make Repeater implement Callable


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

Branch: refs/heads/master
Commit: 3129a12c6ab77728308cc0093134838490935087
Parents: 7ca2781
Author: Andrew Kennedy <gr...@apache.org>
Authored: Wed Sep 16 04:13:07 2015 +0100
Committer: Andrew Kennedy <gr...@apache.org>
Committed: Wed Sep 16 04:13:07 2015 +0100

----------------------------------------------------------------------
 .../apache/brooklyn/util/repeat/Repeater.java   | 49 ++++++++------------
 1 file changed, 20 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3129a12c/utils/common/src/main/java/org/apache/brooklyn/util/repeat/Repeater.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/repeat/Repeater.java b/utils/common/src/main/java/org/apache/brooklyn/util/repeat/Repeater.java
index d8ac013..b1df990 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/repeat/Repeater.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/repeat/Repeater.java
@@ -32,6 +32,7 @@ import org.apache.brooklyn.util.repeat.Repeater;
 import org.apache.brooklyn.util.time.CountdownTimer;
 import org.apache.brooklyn.util.time.Duration;
 import org.apache.brooklyn.util.time.Time;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,31 +44,15 @@ import com.google.common.base.Stopwatch;
 import com.google.common.util.concurrent.Callables;
 
 /**
- * Simple DSL to repeat a fragment of code periodically until a condition is satisfied.
- *
- * In its simplest case, it is passed two {@link groovy.lang.Closure}s / {@link Callable} - 
- * the first is executed, then the second. If the second closure returns false, the loop
- * is repeated; if true, it finishes. Further customization can be applied to set the period 
- * between loops and place a maximum limit on how long the loop should run for.
+ * Simple mechanism to repeat an operation periodically until a condition is satisfied.
  * <p>
- * It is configured in a <em>fluent</em> manner. For example, in Groovy:
- * <pre>
- * {@code
- * Repeater.create("Wait until the Frobnitzer is ready")
- *     .repeat {
- *         status = frobnitzer.getStatus()
- *     }
- *     .until {
- *         status == "Ready" || status == "Failed"
- *     }
- *     .limitIterationsTo(30)
- *     .run()
- * }
- * </pre>
- * 
- * Or in Java:
- * <pre>
- * {@code
+ * In its simplest case it is passed two {@link Callable} objects, the <em>operation</em>
+ * and the <em>condition</em> which are executed in that order. This execution is repeated
+ * until the <em>condition</em> returns {@code true}, when the loop finishes. Further customization
+ * can be applied to set the period between loops and place a maximum limit on how long the
+ * loop should run for, as well as other timing and delay properties.
+ * <p>
+ * <pre>{@code
  * Repeater.create("Wait until the Frobnitzer is ready")
  *     .until(new Callable<Boolean>() {
  *              public Boolean call() {
@@ -76,10 +61,11 @@ import com.google.common.util.concurrent.Callables;
  *              }})
  *     .limitIterationsTo(30)
  *     .run()
- * }
- * </pre>
+ * }</pre>
+ * <p>
+ * The 
  */
-public class Repeater {
+public class Repeater implements Callable<Boolean> {
 
     private static final Logger log = LoggerFactory.getLogger(Repeater.class);
 
@@ -389,7 +375,7 @@ public class Repeater {
             Time.sleep(delayThisIteration);
         }
     }
-    
+
     public String getDescription() {
         return description;
     }
@@ -397,5 +383,10 @@ public class Repeater {
     public Duration getTimeLimit() {
         return timeLimit;
     }
-    
+
+    @Override
+    public Boolean call() throws Exception {
+        return run();
+    }
+
 }