Groovy Documentation

org.linkedin.groovy.util.concurrent
[Groovy] Class GroovyConcurrentUtils

java.lang.Object
  org.linkedin.util.concurrent.ConcurrentUtils
      org.linkedin.groovy.util.concurrent.GroovyConcurrentUtils

class GroovyConcurrentUtils
extends ConcurrentUtils

Authors:
ypujante@linkedin.com


Method Summary
static java.lang.Object awaitFor(java.lang.Object clock, java.lang.Object timeout, java.lang.Object lock, groovy.lang.Closure closure)

The closure is the condition to wait on: it should return false until the condition is met.

static void waitForCondition(java.lang.Object clock, java.lang.Object timeout, java.lang.Object heartbeat, groovy.lang.Closure condition)

This call will wait until the condition as provided by the closure is true.

static java.lang.Object waitForShutdownMultiple(java.lang.Object clock, java.lang.Object timeout, java.util.Collection shutdownables)

Handle the logic when you need to wait for shutdown with a timeout on multiple shutdownable...

static java.lang.Object waitMultiple(java.lang.Object clock, java.lang.Object timeout, java.lang.Object closures)

When multiple waits need to happen with a timeout the logic is a little bit complicated because the timeout applies as a whole, not as individual waits.

 

Method Detail

awaitFor

static java.lang.Object awaitFor(java.lang.Object clock, java.lang.Object timeout, java.lang.Object lock, groovy.lang.Closure closure)
The closure is the condition to wait on: it should return false until the condition is met. When met, it should return true.
Parameters:
lock - the lock to wait on. Note that the method will do a synchronized on it, so you don't have to...
timeout - can be null if you want to wait forever, otherwise you can provide a Timespan, a String (which has a format recognized by Timespan) or a number of milliseconds.


waitForCondition

static void waitForCondition(java.lang.Object clock, java.lang.Object timeout, java.lang.Object heartbeat, groovy.lang.Closure condition)
This call will wait until the condition as provided by the closure is true. Waits no longer than the timeout provided. Note that it is going to sleep as it is not a wait/notify pattern. The sleeping time will increase between each calls to the closure. Passing null for the timeout will block until the condition is true.
Parameters:
heartbeat - how long to sleep between each closure call


waitForShutdownMultiple

static java.lang.Object waitForShutdownMultiple(java.lang.Object clock, java.lang.Object timeout, java.util.Collection shutdownables)
Handle the logic when you need to wait for shutdown with a timeout on multiple shutdownable... the collective time must not be beyond the timeout


waitMultiple

static java.lang.Object waitMultiple(java.lang.Object clock, java.lang.Object timeout, java.lang.Object closures)
When multiple waits need to happen with a timeout the logic is a little bit complicated because the timeout applies as a whole, not as individual waits. This method takes care of it by calling each closure with the 'remaining' timeout.
Parameters:
timeout - can be null if you want to wait forever, otherwise you can provide a Timespan, a String (which has a format recognized by Timespan) or a number of milliseconds.


 

Groovy Documentation