Package EDU.oswego.cs.dl.util.concurrent
Class WaitableRef
java.lang.Object
EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
EDU.oswego.cs.dl.util.concurrent.SynchronizedRef
EDU.oswego.cs.dl.util.concurrent.WaitableRef
- All Implemented Interfaces:
Executor
A class useful for offloading synch for Object reference instance variables.
-
Field Summary
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedRef
value_
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
lock_
-
Constructor Summary
ConstructorsConstructorDescriptionWaitableRef
(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
Modifier and TypeMethodDescriptionboolean
Set value to newValue only if it is currently assumedValue.Set to newValue.void
Wait until value equals c, then run action if nonnull.void
whenNotEqual
(Object c, Runnable action) wait until value not equal to c, then run action if nonnull.void
whenNotNull
(Runnable action) wait until value is nonnull, then run action if nonnull.void
Wait until value is null, then run action if nonnull.Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedRef
get, swap
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
execute, getLock
-
Constructor Details
-
WaitableRef
Create a WaitableRef initially holding the given reference and using its own internal lock. -
WaitableRef
Make a new WaitableRef with the given initial value, and using the supplied lock.
-
-
Method Details
-
set
Description copied from class:SynchronizedRef
Set to newValue.- Overrides:
set
in classSynchronizedRef
- Returns:
- the old value
-
commit
Description copied from class:SynchronizedRef
Set value to newValue only if it is currently assumedValue.- Overrides:
commit
in classSynchronizedRef
- Returns:
- true if successful
-
whenNull
Wait until value is null, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenNotNull
wait until value is nonnull, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenEqual
Wait until value equals c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenNotEqual
wait until value not equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-