Package EDU.oswego.cs.dl.util.concurrent
Class WaitableBoolean
- java.lang.Object
-
- EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
-
- EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean
-
- EDU.oswego.cs.dl.util.concurrent.WaitableBoolean
-
- All Implemented Interfaces:
Executor,java.lang.Cloneable,java.lang.Comparable
public class WaitableBoolean extends SynchronizedBoolean
A class useful for offloading synch for boolean instance variables.
-
-
Field Summary
-
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean
value_
-
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
lock_
-
-
Constructor Summary
Constructors Constructor Description WaitableBoolean(boolean initialValue)Make a new WaitableBoolean with the given initial valueWaitableBoolean(boolean initialValue, java.lang.Object lock)Make a new WaitableBoolean with the given initial value, and using the supplied lock.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanand(boolean b)Set value to value & b.booleancommit(boolean assumedValue, boolean newValue)Set value to newValue only if it is currently assumedValue.booleancomplement()Set the value to its complementbooleanor(boolean b)Set value to value | b.booleanset(boolean newValue)Set to newValue.voidwhenEqual(boolean c, java.lang.Runnable action)Wait until value equals c, then run action if nonnull.voidwhenFalse(java.lang.Runnable action)Wait until value is false, then run action if nonnull.voidwhenNotEqual(boolean c, java.lang.Runnable action)wait until value not equal to c, then run action if nonnull.voidwhenTrue(java.lang.Runnable action)wait until value is true, then run action if nonnull.booleanxor(boolean b)Set value to value ^ b.-
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean
compareTo, compareTo, compareTo, equals, get, hashCode, swap, toString
-
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
execute, getLock
-
-
-
-
Constructor Detail
-
WaitableBoolean
public WaitableBoolean(boolean initialValue)
Make a new WaitableBoolean with the given initial value
-
WaitableBoolean
public WaitableBoolean(boolean initialValue, java.lang.Object lock)Make a new WaitableBoolean with the given initial value, and using the supplied lock.
-
-
Method Detail
-
set
public boolean set(boolean newValue)
Description copied from class:SynchronizedBooleanSet to newValue.- Overrides:
setin classSynchronizedBoolean- Returns:
- the old value
-
commit
public boolean commit(boolean assumedValue, boolean newValue)Description copied from class:SynchronizedBooleanSet value to newValue only if it is currently assumedValue.- Overrides:
commitin classSynchronizedBoolean- Returns:
- true if successful
-
complement
public boolean complement()
Description copied from class:SynchronizedBooleanSet the value to its complement- Overrides:
complementin classSynchronizedBoolean- Returns:
- the new value
-
and
public boolean and(boolean b)
Description copied from class:SynchronizedBooleanSet value to value & b.- Overrides:
andin classSynchronizedBoolean- Returns:
- the new value
-
or
public boolean or(boolean b)
Description copied from class:SynchronizedBooleanSet value to value | b.- Overrides:
orin classSynchronizedBoolean- Returns:
- the new value
-
xor
public boolean xor(boolean b)
Description copied from class:SynchronizedBooleanSet value to value ^ b.- Overrides:
xorin classSynchronizedBoolean- Returns:
- the new value
-
whenFalse
public void whenFalse(java.lang.Runnable action) throws java.lang.InterruptedExceptionWait until value is false, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
java.lang.InterruptedException
-
whenTrue
public void whenTrue(java.lang.Runnable action) throws java.lang.InterruptedExceptionwait until value is true, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
java.lang.InterruptedException
-
whenEqual
public void whenEqual(boolean c, java.lang.Runnable action) throws java.lang.InterruptedExceptionWait until value equals c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
java.lang.InterruptedException
-
whenNotEqual
public void whenNotEqual(boolean c, java.lang.Runnable action) throws java.lang.InterruptedExceptionwait until value not equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
java.lang.InterruptedException
-
-