|
Brooklyn | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbrooklyn.util.internal.Repeater
class Repeater
Simple DSL to repeat a fragment of code periodically until a condition is satisfied. In its simplest case, it is passed two closures - 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:
Repeater.create("Wait until the Frobnitzer is ready") .repeat { status = frobnitzer.getStatus() } .until { status == "Ready" || status == "Failed" } .limitIterationsTo(30) .run()
Constructor Summary | |
Repeater(java.util.Map flags = [:])
|
|
Repeater(java.util.Map flags = [:], java.lang.String description)
Construct a new instance of Repeater. |
Method Summary | |
---|---|
static Repeater
|
create(java.util.Map flags = [:])
|
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
|
limitTimeTo(long duration)
@see #limitTimeTo(long, TimeUnit) |
Repeater
|
repeat(java.util.concurrent.Callable body = {})
Set the main body of the loop. |
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 |
---|
Repeater(java.util.Map flags = [:])
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 |
---|
static Repeater create(java.util.Map flags = [:])
static Repeater create(java.util.Map flags = [:], java.lang.String description)
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.
Repeater every(groovy.time.Duration duration)
Repeater every(long duration)
Repeater limitIterationsTo(int iterationLimit)
iterationLimit
- the maximum number of iterations.
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.
Repeater limitTimeTo(groovy.time.Duration duration)
Repeater limitTimeTo(long duration)
Repeater repeat(java.util.concurrent.Callable body = {})
body
- a closure or other Runnable that is executed in the main body of the loop.
Repeater rethrowException()
Repeater rethrowExceptionImmediately()
boolean run()
void setFromFlags(java.util.Map flags)
Repeater suppressWarnings()
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.