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
,java.lang.Cloneable
,java.lang.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, java.lang.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 byte
add(byte amount)
Add amount to value (i.e., set value += amount)byte
and(byte b)
Set value to value & b.boolean
commit(byte assumedValue, byte newValue)
Set value to newValue only if it is currently assumedValue.byte
complement()
Set the value to its complementbyte
decrement()
Decrement the value.byte
divide(byte factor)
Divide value by factor (i.e., set value /= factor)byte
increment()
Increment the value.byte
multiply(byte factor)
Multiply value by factor (i.e., set value *= factor)byte
or(byte b)
Set value to value | b.byte
set(byte newValue)
Set to newValue.byte
subtract(byte amount)
Subtract amount from value (i.e., set value -= amount)void
whenEqual(byte c, java.lang.Runnable action)
Wait until value equals c, then run action if nonnull.void
whenGreater(byte c, java.lang.Runnable action)
wait until value greater than c, then run action if nonnull.void
whenGreaterEqual(byte c, java.lang.Runnable action)
wait until value greater than or equal to c, then run action if nonnull.void
whenLess(byte c, java.lang.Runnable action)
wait until value less than c, then run action if nonnull.void
whenLessEqual(byte c, java.lang.Runnable action)
wait until value less than or equal to c, then run action if nonnull.void
whenNotEqual(byte c, java.lang.Runnable action)
wait until value not equal to c, then run action if nonnull.byte
xor(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, java.lang.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:SynchronizedByte
Set to newValue.- Overrides:
set
in classSynchronizedByte
- Returns:
- the old value
-
commit
public boolean commit(byte assumedValue, byte newValue)
Description copied from class:SynchronizedByte
Set value to newValue only if it is currently assumedValue.- Overrides:
commit
in classSynchronizedByte
- Returns:
- true if successful
-
increment
public byte increment()
Description copied from class:SynchronizedByte
Increment the value.- Overrides:
increment
in classSynchronizedByte
- Returns:
- the new value
-
decrement
public byte decrement()
Description copied from class:SynchronizedByte
Decrement the value.- Overrides:
decrement
in classSynchronizedByte
- Returns:
- the new value
-
add
public byte add(byte amount)
Description copied from class:SynchronizedByte
Add amount to value (i.e., set value += amount)- Overrides:
add
in classSynchronizedByte
- Returns:
- the new value
-
subtract
public byte subtract(byte amount)
Description copied from class:SynchronizedByte
Subtract amount from value (i.e., set value -= amount)- Overrides:
subtract
in classSynchronizedByte
- Returns:
- the new value
-
multiply
public byte multiply(byte factor)
Description copied from class:SynchronizedByte
Multiply value by factor (i.e., set value *= factor)- Overrides:
multiply
in classSynchronizedByte
- Returns:
- the new value
-
divide
public byte divide(byte factor)
Description copied from class:SynchronizedByte
Divide value by factor (i.e., set value /= factor)- Overrides:
divide
in classSynchronizedByte
- Returns:
- the new value
-
complement
public byte complement()
Set the value to its complement- Overrides:
complement
in classSynchronizedByte
- Returns:
- the new value
-
and
public byte and(byte b)
Set value to value & b.- Overrides:
and
in classSynchronizedByte
- Returns:
- the new value
-
or
public byte or(byte b)
Set value to value | b.- Overrides:
or
in classSynchronizedByte
- Returns:
- the new value
-
xor
public byte xor(byte b)
Set value to value ^ b.- Overrides:
xor
in classSynchronizedByte
- Returns:
- the new value
-
whenEqual
public void whenEqual(byte 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(byte 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
-
whenLessEqual
public void whenLessEqual(byte c, java.lang.Runnable action) throws java.lang.InterruptedException
wait until value less than or equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
java.lang.InterruptedException
-
whenLess
public void whenLess(byte c, java.lang.Runnable action) throws java.lang.InterruptedException
wait until value less than c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
java.lang.InterruptedException
-
whenGreaterEqual
public void whenGreaterEqual(byte c, java.lang.Runnable action) throws java.lang.InterruptedException
wait until value greater than or equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
java.lang.InterruptedException
-
whenGreater
public void whenGreater(byte c, java.lang.Runnable action) throws java.lang.InterruptedException
wait until value greater than c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
java.lang.InterruptedException
-
-