Package EDU.oswego.cs.dl.util.concurrent
Class WaitableLong
- java.lang.Object
-
- EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
-
- EDU.oswego.cs.dl.util.concurrent.SynchronizedLong
-
- EDU.oswego.cs.dl.util.concurrent.WaitableLong
-
- All Implemented Interfaces:
Executor,java.lang.Cloneable,java.lang.Comparable
public class WaitableLong extends SynchronizedLong
A class useful for offloading waiting and signalling operations on single long variables.
-
-
Field Summary
-
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedLong
value_
-
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
lock_
-
-
Constructor Summary
Constructors Constructor Description WaitableLong(long initialValue)Make a new WaitableLong with the given initial value, and using its own internal lock.WaitableLong(long initialValue, java.lang.Object lock)Make a new WaitableLong with the given initial value, and using the supplied lock.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longadd(long amount)Add amount to value (i.e., set value += amount)longand(long b)Set value to value & b.booleancommit(long assumedValue, long newValue)Set value to newValue only if it is currently assumedValue.longcomplement()Set the value to its complementlongdecrement()Decrement the value.longdivide(long factor)Divide value by factor (i.e., set value /= factor)longincrement()Increment the value.longmultiply(long factor)Multiply value by factor (i.e., set value *= factor)longor(long b)Set value to value | b.longset(long newValue)Set to newValue.longsubtract(long amount)Subtract amount from value (i.e., set value -= amount)voidwhenEqual(long c, java.lang.Runnable action)Wait until value equals c, then run action if nonnull.voidwhenGreater(long c, java.lang.Runnable action)wait until value greater than c, then run action if nonnull.voidwhenGreaterEqual(long c, java.lang.Runnable action)wait until value greater than or equal to c, then run action if nonnull.voidwhenLess(long c, java.lang.Runnable action)wait until value less than c, then run action if nonnull.voidwhenLessEqual(long c, java.lang.Runnable action)wait until value less than or equal to c, then run action if nonnull.voidwhenNotEqual(long c, java.lang.Runnable action)wait until value not equal to c, then run action if nonnull.longxor(long b)Set value to value ^ b.-
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedLong
compareTo, compareTo, compareTo, equals, get, hashCode, negate, swap, toString
-
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
execute, getLock
-
-
-
-
Constructor Detail
-
WaitableLong
public WaitableLong(long initialValue)
Make a new WaitableLong with the given initial value, and using its own internal lock.
-
WaitableLong
public WaitableLong(long initialValue, java.lang.Object lock)Make a new WaitableLong with the given initial value, and using the supplied lock.
-
-
Method Detail
-
set
public long set(long newValue)
Description copied from class:SynchronizedLongSet to newValue.- Overrides:
setin classSynchronizedLong- Returns:
- the old value
-
commit
public boolean commit(long assumedValue, long newValue)Description copied from class:SynchronizedLongSet value to newValue only if it is currently assumedValue.- Overrides:
commitin classSynchronizedLong- Returns:
- true if successful
-
increment
public long increment()
Description copied from class:SynchronizedLongIncrement the value.- Overrides:
incrementin classSynchronizedLong- Returns:
- the new value
-
decrement
public long decrement()
Description copied from class:SynchronizedLongDecrement the value.- Overrides:
decrementin classSynchronizedLong- Returns:
- the new value
-
add
public long add(long amount)
Description copied from class:SynchronizedLongAdd amount to value (i.e., set value += amount)- Overrides:
addin classSynchronizedLong- Returns:
- the new value
-
subtract
public long subtract(long amount)
Description copied from class:SynchronizedLongSubtract amount from value (i.e., set value -= amount)- Overrides:
subtractin classSynchronizedLong- Returns:
- the new value
-
multiply
public long multiply(long factor)
Description copied from class:SynchronizedLongMultiply value by factor (i.e., set value *= factor)- Overrides:
multiplyin classSynchronizedLong- Returns:
- the new value
-
divide
public long divide(long factor)
Description copied from class:SynchronizedLongDivide value by factor (i.e., set value /= factor)- Overrides:
dividein classSynchronizedLong- Returns:
- the new value
-
complement
public long complement()
Set the value to its complement- Overrides:
complementin classSynchronizedLong- Returns:
- the new value
-
and
public long and(long b)
Set value to value & b.- Overrides:
andin classSynchronizedLong- Returns:
- the new value
-
or
public long or(long b)
Set value to value | b.- Overrides:
orin classSynchronizedLong- Returns:
- the new value
-
xor
public long xor(long b)
Set value to value ^ b.- Overrides:
xorin classSynchronizedLong- Returns:
- the new value
-
whenEqual
public void whenEqual(long 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(long 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
-
whenLessEqual
public void whenLessEqual(long c, java.lang.Runnable action) throws java.lang.InterruptedExceptionwait 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(long c, java.lang.Runnable action) throws java.lang.InterruptedExceptionwait 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(long c, java.lang.Runnable action) throws java.lang.InterruptedExceptionwait 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(long c, java.lang.Runnable action) throws java.lang.InterruptedExceptionwait until value greater than c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
java.lang.InterruptedException
-
-