A generic waiter implemented as an abstract class. More...
Public Member Functions | |
void | wait (Object syncValue, Object checkValue) throws Exception |
Wait until "check" returns true, or timeout is elapsed. | |
Protected Member Functions | |
Waiter (long timeout) | |
abstract boolean | check (Object syncValue, Object checkValue) throws Exception |
Check to see if condition is met. | |
Protected Attributes | |
long | timeout |
A generic waiter implemented as an abstract class.
The generic waiter handles timeouts and deciding whether to continue waiting on spurious wakeup based on a condition. You can hand it an Object to synchronize on (syncValue) and an Object to check. Both are handed back to the abstract check method as the parameters "syncValue" and "checkValue". The wait ends when either check(syncValue, checkValue) returns true or the timeout expires.
A convenient way to use the waiter is to instantiate the abstract method in an anonymous class. So for example, if you wanted to wait 500 ms for a static Boolean foo to become true and synchronize on an Object named lock you could do it like this, instantiating "check" in the anonymous class to check the value of foo:
* Object lock = new Object(); * new Waiter(500) { * @Override * protected boolean check(Object syncValue, Object checkValue) throws Exception { * return (Boolean)checkValue; * } * }.wait(lock, foo); *
abstract boolean org.ccnx.ccn.impl.support.ConcurrencyUtils.Waiter.check | ( | Object | syncValue, | |
Object | checkValue | |||
) | throws Exception [protected, pure virtual] |
Check to see if condition is met.
syncValue | the lock object which could be part of the condition check | |
checkValue | value to check for end condition |
Exception |
void org.ccnx.ccn.impl.support.ConcurrencyUtils.Waiter.wait | ( | Object | syncValue, | |
Object | checkValue | |||
) | throws Exception |
Wait until "check" returns true, or timeout is elapsed.
Handles spurious wakeups by calling check in a loop.
syncValue | - wait under this lock, also passed to check routine | |
checkValue | - value to pass to check to allow subclass to test condition |
Exception |