org.ccnx.ccn.impl.support.ConcurrencyUtils.Waiter Class Reference

A generic waiter implemented as an abstract class. More...

List of all members.

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


Detailed Description

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);
	 * 

Member Function Documentation

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.

Parameters:
syncValue - wait under this lock, also passed to check routine
checkValue - value to pass to check to allow subclass to test condition
Exceptions:
Exception 

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.

Parameters:
syncValue the lock object which could be part of the condition check
checkValue value to check for end condition
Returns:
true if condition is met (and we should stop waiting)
Exceptions:
Exception 


The documentation for this class was generated from the following file:

Generated on Thu Feb 16 00:45:00 2012 for Content-Centric Networking in Java by  doxygen 1.5.6