Brooklyn

brooklyn.util.internal
[Groovy] Class Repeater

java.lang.Object
  brooklyn.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

See Also:
every(long, TimeUnit)

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

Repeater(java.util.Map flags = [:])


Repeater

Repeater(java.util.Map flags = [:], java.lang.String description)
Construct a new instance of Repeater.
Parameters:
flags: - period, timeout, description
description - a description of the operation that will appear in debug logs.


 
Method Detail

create

static Repeater create(java.util.Map flags = [:])


create

static Repeater create(java.util.Map flags = [:], java.lang.String description)


every

Repeater every(long period, java.util.concurrent.TimeUnit unit)
Set how long to wait between loop iterations.
Parameters:
period - how long to wait between loop iterations.
unit - the unit of measurement of the period.
Returns:
{@literal this} to aid coding in a fluent style.


every

Repeater every(groovy.time.Duration duration)
See Also:
every(long, TimeUnit)


every

Repeater every(long duration)
depreated:
specify unit
See Also:
every(long, TimeUnit)


limitIterationsTo

Repeater limitIterationsTo(int iterationLimit)
Set the maximum number of iterations. The loop will exit if the condition has not been satisfied after this number of iterations.
Parameters:
iterationLimit - the maximum number of iterations.
Returns:
{@literal this} to aid coding in a fluent style.


limitTimeTo

Repeater limitTimeTo(long deadline, java.util.concurrent.TimeUnit unit)
Set the amount of time to wait for the condition. The repeater will wait at least this long for the condition to be true, and will exit soon after even if the condition is false.
Parameters:
deadline - the time that the loop should wait.
unit - the unit of measurement of the period.
Returns:
{@literal this} to aid coding in a fluent style.


limitTimeTo

Repeater limitTimeTo(groovy.time.Duration duration)
See Also:
limitTimeTo(long, TimeUnit)


limitTimeTo

Repeater limitTimeTo(long duration)
deprecated:
will be deleted in 0.5. specify unit
See Also:
limitTimeTo(long, TimeUnit)


repeat

Repeater repeat(java.util.concurrent.Callable body = {})
Set the main body of the loop.
Parameters:
body - a closure or other Runnable that is executed in the main body of the loop.
Returns:
{@literal this} to aid coding in a fluent style.


rethrowException

Repeater rethrowException()
If the exit condition check throws an exception, it will be recorded and the last exception will be thrown on failure.
Returns:
{@literal this} to aid coding in a fluent style.


rethrowExceptionImmediately

Repeater rethrowExceptionImmediately()
If the repeated body or the exit condition check throws an exception, then propagate that exception immediately.
Returns:
{@literal this} to aid coding in a fluent style.


run

boolean run()
Run the loop.
Returns:
true if the exit condition was satisfied; false if the loop terminated for any other reason.


setFromFlags

void setFromFlags(java.util.Map flags)


suppressWarnings

Repeater suppressWarnings()


until

Repeater until(java.util.concurrent.Callable exitCondition)
Set code fragment that tests if the loop has completed.
Parameters:
exitCondition - a closure or other Callable that returns a boolean. If this code returns {@literal true} then the loop will stop executing.
Returns:
{@literal this} to aid coding in a fluent style.


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.