Groovy Documentation

org.linkedin.glu.agent.api
[Groovy] Interface Timers


interface Timers

This interface is available from any GLU script using timers property

 class MyScript
 {
   def timer1 = {
     log.info "hello world"
   }

   def install = {
     timers.schedule(timer: timer1, repeatFrequency: '1m') // property
     // timers.schedule(timer: 'timer1', repeatFrequency: '1m') // also valid (name of the property)
     // timers.schedule(timer: { println 'hello world'}, repeatFrequency: '1m') // invalid (anonymous closure)
   }

   def uninstall = {
     timers.cancel(timer: timer1)
   }
 }
 
Authors:
ypujante@linkedin.com


Method Summary
boolean cancel(java.lang.Object args)

@param args.timer timer

FutureExecution schedule(java.lang.Object args)

Schedule a timer.

 

Method Detail

cancel

boolean cancel(java.lang.Object args)
Parameters:
args.timer - timer
Returns:
false if the execution could not be cancelled, typically because it has already completed normally; true otherwise


schedule

FutureExecution schedule(java.lang.Object args)
Schedule a timer. Because of the fact that a timer needs to survive an agent restart, it needs to be defined as a property of the GLU script and not an anonymous Closure.
Parameters:
args.timer - there can only be one timer with a given name (note that the timer needs to be a pointer to a Closure, so it can either be the name of the property holding the Closure or directly the property itself)
args.initialFrequency - how long to wait the first time (optional)
args.repeatFrequency - how long to wait after the first time
Returns:
a future execution (asynchronous execution, cancellable...)


 

Groovy Documentation