Package EDU.oswego.cs.dl.util.concurrent
Class WaitableByte
- java.lang.Object
-
- EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
-
- EDU.oswego.cs.dl.util.concurrent.SynchronizedByte
-
- EDU.oswego.cs.dl.util.concurrent.WaitableByte
-
- All Implemented Interfaces:
Executor,Cloneable,Comparable
public class WaitableByte extends SynchronizedByte
A class useful for offloading waiting and signalling operations on single byte variables.
-
-
Field Summary
-
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedByte
value_
-
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
lock_
-
-
Constructor Summary
Constructors Constructor Description WaitableByte(byte initialValue)Make a new WaitableByte with the given initial value, and using its own internal lock.WaitableByte(byte initialValue, Object lock)Make a new WaitableByte with the given initial value, and using the supplied lock.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byteadd(byte amount)Add amount to value (i.e., set value += amount)byteand(byte b)Set value to value & b.booleancommit(byte assumedValue, byte newValue)Set value to newValue only if it is currently assumedValue.bytecomplement()Set the value to its complementbytedecrement()Decrement the value.bytedivide(byte factor)Divide value by factor (i.e., set value /= factor)byteincrement()Increment the value.bytemultiply(byte factor)Multiply value by factor (i.e., set value *= factor)byteor(byte b)Set value to value | b.byteset(byte newValue)Set to newValue.bytesubtract(byte amount)Subtract amount from value (i.e., set value -= amount)voidwhenEqual(byte c, Runnable action)Wait until value equals c, then run action if nonnull.voidwhenGreater(byte c, Runnable action)wait until value greater than c, then run action if nonnull.voidwhenGreaterEqual(byte c, Runnable action)wait until value greater than or equal to c, then run action if nonnull.voidwhenLess(byte c, Runnable action)wait until value less than c, then run action if nonnull.voidwhenLessEqual(byte c, Runnable action)wait until value less than or equal to c, then run action if nonnull.voidwhenNotEqual(byte c, Runnable action)wait until value not equal to c, then run action if nonnull.bytexor(byte b)Set value to value ^ b.-
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedByte
compareTo, compareTo, compareTo, equals, get, hashCode, negate, swap, toString
-
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
execute, getLock
-
-
-
-
Constructor Detail
-
WaitableByte
public WaitableByte(byte initialValue)
Make a new WaitableByte with the given initial value, and using its own internal lock.
-
WaitableByte
public WaitableByte(byte initialValue, Object lock)Make a new WaitableByte with the given initial value, and using the supplied lock.
-
-
Method Detail
-
set
public byte set(byte newValue)
Description copied from class:SynchronizedByteSet to newValue.- Overrides:
setin classSynchronizedByte- Returns:
- the old value
-
commit
public boolean commit(byte assumedValue, byte newValue)Description copied from class:SynchronizedByteSet value to newValue only if it is currently assumedValue.- Overrides:
commitin classSynchronizedByte- Returns:
- true if successful
-
increment
public byte increment()
Description copied from class:SynchronizedByteIncrement the value.- Overrides:
incrementin classSynchronizedByte- Returns:
- the new value
-
decrement
public byte decrement()
Description copied from class:SynchronizedByteDecrement the value.- Overrides:
decrementin classSynchronizedByte- Returns:
- the new value
-
add
public byte add(byte amount)
Description copied from class:SynchronizedByteAdd amount to value (i.e., set value += amount)- Overrides:
addin classSynchronizedByte- Returns:
- the new value
-
subtract
public byte subtract(byte amount)
Description copied from class:SynchronizedByteSubtract amount from value (i.e., set value -= amount)- Overrides:
subtractin classSynchronizedByte- Returns:
- the new value
-
multiply
public byte multiply(byte factor)
Description copied from class:SynchronizedByteMultiply value by factor (i.e., set value *= factor)- Overrides:
multiplyin classSynchronizedByte- Returns:
- the new value
-
divide
public byte divide(byte factor)
Description copied from class:SynchronizedByteDivide value by factor (i.e., set value /= factor)- Overrides:
dividein classSynchronizedByte- Returns:
- the new value
-
complement
public byte complement()
Set the value to its complement- Overrides:
complementin classSynchronizedByte- Returns:
- the new value
-
and
public byte and(byte b)
Set value to value & b.- Overrides:
andin classSynchronizedByte- Returns:
- the new value
-
or
public byte or(byte b)
Set value to value | b.- Overrides:
orin classSynchronizedByte- Returns:
- the new value
-
xor
public byte xor(byte b)
Set value to value ^ b.- Overrides:
xorin classSynchronizedByte- Returns:
- the new value
-
whenEqual
public void whenEqual(byte c, Runnable action) throws InterruptedExceptionWait until value equals c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenNotEqual
public void whenNotEqual(byte c, Runnable action) throws InterruptedExceptionwait until value not equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenLessEqual
public void whenLessEqual(byte c, Runnable action) throws InterruptedExceptionwait until value less than or equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenLess
public void whenLess(byte c, Runnable action) throws InterruptedExceptionwait until value less than c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenGreaterEqual
public void whenGreaterEqual(byte c, Runnable action) throws InterruptedExceptionwait until value greater than or equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenGreater
public void whenGreater(byte c, Runnable action) throws InterruptedExceptionwait until value greater than c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
-