EDU.oswego.cs.dl.util.concurrent

Class WaitableRef

public class WaitableRef extends SynchronizedRef

A class useful for offloading synch for Object reference instance variables.

[ Introduction to this package. ]

Constructor Summary
WaitableRef(Object initialValue)
Create a WaitableRef initially holding the given reference and using its own internal lock.
WaitableRef(Object initialValue, Object lock)
Make a new WaitableRef with the given initial value, and using the supplied lock.
Method Summary
booleancommit(Object assumedValue, Object newValue)
Objectset(Object newValue)
voidwhenEqual(Object c, Runnable action)
Wait until value equals c, then run action if nonnull.
voidwhenNotEqual(Object c, Runnable action)
wait until value not equal to c, then run action if nonnull.
voidwhenNotNull(Runnable action)
wait until value is nonnull, then run action if nonnull.
voidwhenNull(Runnable action)
Wait until value is null, then run action if nonnull.

Constructor Detail

WaitableRef

public WaitableRef(Object initialValue)
Create a WaitableRef initially holding the given reference and using its own internal lock.

WaitableRef

public WaitableRef(Object initialValue, Object lock)
Make a new WaitableRef with the given initial value, and using the supplied lock.

Method Detail

commit

public boolean commit(Object assumedValue, Object newValue)

set

public Object set(Object newValue)

whenEqual

public void whenEqual(Object c, Runnable action)
Wait until value equals c, then run action if nonnull. The action is run with the synchronization lock held.

whenNotEqual

public void whenNotEqual(Object c, Runnable action)
wait until value not equal to c, then run action if nonnull. The action is run with the synchronization lock held.

whenNotNull

public void whenNotNull(Runnable action)
wait until value is nonnull, then run action if nonnull. The action is run with the synchronization lock held.

whenNull

public void whenNull(Runnable action)
Wait until value is null, then run action if nonnull. The action is run with the synchronization lock held.