Package com.attivio.concurrent
Class WaitableBoolean
- java.lang.Object
-
- com.attivio.concurrent.SynchronizedVariable
-
- com.attivio.concurrent.SynchronizedBoolean
-
- com.attivio.concurrent.WaitableBoolean
-
- All Implemented Interfaces:
java.lang.Comparable<SynchronizedBoolean>
,java.util.concurrent.Executor
public class WaitableBoolean extends SynchronizedBoolean
A class useful for offloading synch for boolean instance variables.
-
-
Field Summary
-
Fields inherited from class com.attivio.concurrent.SynchronizedBoolean
value
-
Fields inherited from class com.attivio.concurrent.SynchronizedVariable
lock
-
-
Constructor Summary
Constructors Constructor Description WaitableBoolean(boolean initialValue)
Make a new WaitableBoolean with the given initial value *WaitableBoolean(boolean initialValue, java.util.concurrent.locks.ReadWriteLock 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 boolean
and(boolean b)
Set value to value & b.boolean
commit(boolean assumedValue, boolean newValue)
Set value to newValue only if it is currently assumedValue.boolean
complement()
Set the value to its complementboolean
equals(java.lang.Object other)
int
hashCode()
boolean
or(boolean b)
Set value to value | b.boolean
set(boolean newValue)
Set to newValue.void
waitForChange()
Waits for the value to change for up to 5secs.void
whenEqual(boolean c, java.lang.Runnable action)
Wait until value equals c, then run action if nonnull.void
whenFalse(java.lang.Runnable action)
Wait until value is false, then run action if nonnull.void
whenNotEqual(boolean c, java.lang.Runnable action)
wait until value not equal to c, then run action if nonnull.void
whenTrue(java.lang.Runnable action)
wait until value is true, then run action if nonnull.boolean
xor(boolean b)
Set value to value ^ b.-
Methods inherited from class com.attivio.concurrent.SynchronizedBoolean
compareTo, compareTo, get, swap, toString
-
Methods inherited from class com.attivio.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.util.concurrent.locks.ReadWriteLock lock)
Make a new WaitableBoolean with the given initial value, and using the supplied lock.
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classSynchronizedBoolean
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classSynchronizedBoolean
-
set
public boolean set(boolean newValue)
Description copied from class:SynchronizedBoolean
Set to newValue.- Overrides:
set
in classSynchronizedBoolean
- Returns:
- the old value
-
commit
public boolean commit(boolean assumedValue, boolean newValue)
Description copied from class:SynchronizedBoolean
Set value to newValue only if it is currently assumedValue.- Overrides:
commit
in classSynchronizedBoolean
- Returns:
- true if successful
-
complement
public boolean complement()
Description copied from class:SynchronizedBoolean
Set the value to its complement- Overrides:
complement
in classSynchronizedBoolean
- Returns:
- the new value
-
and
public boolean and(boolean b)
Description copied from class:SynchronizedBoolean
Set value to value & b.- Overrides:
and
in classSynchronizedBoolean
- Returns:
- the new value
-
or
public boolean or(boolean b)
Description copied from class:SynchronizedBoolean
Set value to value | b.- Overrides:
or
in classSynchronizedBoolean
- Returns:
- the new value
-
xor
public boolean xor(boolean b)
Description copied from class:SynchronizedBoolean
Set value to value ^ b.- Overrides:
xor
in classSynchronizedBoolean
- Returns:
- the new value
-
whenFalse
public void whenFalse(java.lang.Runnable action) throws java.lang.InterruptedException
Wait 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.InterruptedException
wait 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.InterruptedException
Wait 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.InterruptedException
wait until value not equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
java.lang.InterruptedException
-
waitForChange
public void waitForChange() throws java.lang.InterruptedException
Waits for the value to change for up to 5secs. State must be re-checked after this method returns.- Throws:
java.lang.InterruptedException
-
-