|
Brooklyn | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbrooklyn.util.internal.Repeater
public class Repeater
Simple DSL to repeat a fragment of code periodically until a condition is satisfied. In its simplest case, it is passed two groovy.lang.Closures / java.util.concurrent.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.
It is configured in a fluent manner. For example, in Groovy:
Repeater.create("Wait until the Frobnitzer is ready") .repeat { status = frobnitzer.getStatus() .until { status == "Ready" || status == "Failed" } .limitIterationsTo(30) .run() }Or in Java:
Repeater.create("Wait until the Frobnitzer is ready") .until(new Callable() { public Boolean call() { String status = frobnitzer.getStatus() return "Ready".equals(status) || "Failed".equals(status); }) .limitIterationsTo(30) .run() }
Constructor Summary | |
Repeater()
|
|
Repeater(java.util.Map flags)
|
|
Repeater(java.lang.String description)
|
|
Repeater(java.util.Map flags, java.lang.String description)
Construct a new instance of Repeater. |
Method Summary | |
---|---|
static Repeater
|
create()
|
static Repeater
|
create(java.util.Map flags)
|
static Repeater
|
create(java.lang.String description)
|
static Repeater
|
create(java.util.Map flags, java.lang.String description)
|
Repeater
|
every(long period, java.util.concurrent.TimeUnit unit)
Set how long to wait between loop iterations. |
Repeater
|
every(groovy.time.Duration duration)
@see #every(long, TimeUnit) |
Repeater
|
every(long duration)
@depreated specify unit
|
Repeater
|
limitIterationsTo(int iterationLimit)
Set the maximum number of iterations. |
Repeater
|
limitTimeTo(long deadline, java.util.concurrent.TimeUnit unit)
Set the amount of time to wait for the condition. |
Repeater
|
limitTimeTo(groovy.time.Duration duration)
@see #limitTimeTo(long, TimeUnit) |
Repeater
|
repeat()
Set the main body of the loop. |
Repeater
|
repeat(java.lang.Runnable body)
|
Repeater
|
repeat(java.util.concurrent.Callable body)
|
Repeater
|
rethrowException()
If the exit condition check throws an exception, it will be recorded and the last exception will be thrown on failure. |
Repeater
|
rethrowExceptionImmediately()
If the repeated body or the exit condition check throws an exception, then propagate that exception immediately. |
boolean
|
run()
Run the loop. |
void
|
setFromFlags(java.util.Map flags)
|
Repeater
|
suppressWarnings()
|
Repeater
|
until(java.util.concurrent.Callable exitCondition)
Set code fragment that tests if the loop has completed. |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Constructor Detail |
---|
public Repeater()
public Repeater(java.util.Map flags)
public Repeater(java.lang.String description)
public Repeater(java.util.Map flags, java.lang.String description)
flags:
- period, timeout, descriptiondescription
- a description of the operation that will appear in debug logs.
Method Detail |
---|
public static Repeater create()
public static Repeater create(java.util.Map flags)
public static Repeater create(java.lang.String description)
public static Repeater create(java.util.Map flags, java.lang.String description)
public Repeater every(long period, java.util.concurrent.TimeUnit unit)
period
- how long to wait between loop iterations.unit
- the unit of measurement of the period.
public Repeater every(groovy.time.Duration duration)
public Repeater every(long duration)
public Repeater limitIterationsTo(int iterationLimit)
iterationLimit
- the maximum number of iterations.
public Repeater limitTimeTo(long deadline, java.util.concurrent.TimeUnit unit)
deadline
- the time that the loop should wait.unit
- the unit of measurement of the period.
public Repeater limitTimeTo(groovy.time.Duration duration)
public Repeater repeat()
body
- a closure or other Runnable that is executed in the main body of the loop.
public Repeater repeat(java.lang.Runnable body)
public Repeater repeat(java.util.concurrent.Callable body)
public Repeater rethrowException()
public Repeater rethrowExceptionImmediately()
public boolean run()
public void setFromFlags(java.util.Map flags)
public Repeater suppressWarnings()
public Repeater until(java.util.concurrent.Callable exitCondition)
exitCondition
- a closure or other Callable that returns a boolean. If this code returns {@literal true} then the
loop will stop executing.
Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.