Package EDU.oswego.cs.dl.util.concurrent
Class WaitableInt
- java.lang.Object
-
- EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
-
- EDU.oswego.cs.dl.util.concurrent.SynchronizedInt
-
- EDU.oswego.cs.dl.util.concurrent.WaitableInt
-
- All Implemented Interfaces:
Executor,java.lang.Cloneable,java.lang.Comparable
public class WaitableInt extends SynchronizedInt
A class useful for offloading waiting and signalling operations on single int variables.
-
-
Field Summary
-
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedInt
value_
-
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
lock_
-
-
Constructor Summary
Constructors Constructor Description WaitableInt(int initialValue)Make a new WaitableInt with the given initial value, and using its own internal lock.WaitableInt(int initialValue, java.lang.Object lock)Make a new WaitableInt with the given initial value, and using the supplied lock.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intadd(int amount)Add amount to value (i.e., set value += amount)intand(int b)Set value to value & b.booleancommit(int assumedValue, int newValue)Set value to newValue only if it is currently assumedValue.intcomplement()Set the value to its complementintdecrement()Decrement the value.intdivide(int factor)Divide value by factor (i.e., set value /= factor)intincrement()Increment the value.intmultiply(int factor)Multiply value by factor (i.e., set value *= factor)intor(int b)Set value to value | b.intset(int newValue)Set to newValue.intsubtract(int amount)Subtract amount from value (i.e., set value -= amount)voidwhenEqual(int c, java.lang.Runnable action)Wait until value equals c, then run action if nonnull.voidwhenGreater(int c, java.lang.Runnable action)wait until value greater than c, then run action if nonnull.voidwhenGreaterEqual(int c, java.lang.Runnable action)wait until value greater than or equal to c, then run action if nonnull.voidwhenLess(int c, java.lang.Runnable action)wait until value less than c, then run action if nonnull.voidwhenLessEqual(int c, java.lang.Runnable action)wait until value less than or equal to c, then run action if nonnull.voidwhenNotEqual(int c, java.lang.Runnable action)wait until value not equal to c, then run action if nonnull.intxor(int b)Set value to value ^ b.-
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedInt
compareTo, compareTo, compareTo, equals, get, hashCode, negate, swap, toString
-
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
execute, getLock
-
-
-
-
Constructor Detail
-
WaitableInt
public WaitableInt(int initialValue)
Make a new WaitableInt with the given initial value, and using its own internal lock.
-
WaitableInt
public WaitableInt(int initialValue, java.lang.Object lock)Make a new WaitableInt with the given initial value, and using the supplied lock.
-
-
Method Detail
-
set
public int set(int newValue)
Description copied from class:SynchronizedIntSet to newValue.- Overrides:
setin classSynchronizedInt- Returns:
- the old value
-
commit
public boolean commit(int assumedValue, int newValue)Description copied from class:SynchronizedIntSet value to newValue only if it is currently assumedValue.- Overrides:
commitin classSynchronizedInt- Returns:
- true if successful
-
increment
public int increment()
Description copied from class:SynchronizedIntIncrement the value.- Overrides:
incrementin classSynchronizedInt- Returns:
- the new value
-
decrement
public int decrement()
Description copied from class:SynchronizedIntDecrement the value.- Overrides:
decrementin classSynchronizedInt- Returns:
- the new value
-
add
public int add(int amount)
Description copied from class:SynchronizedIntAdd amount to value (i.e., set value += amount)- Overrides:
addin classSynchronizedInt- Returns:
- the new value
-
subtract
public int subtract(int amount)
Description copied from class:SynchronizedIntSubtract amount from value (i.e., set value -= amount)- Overrides:
subtractin classSynchronizedInt- Returns:
- the new value
-
multiply
public int multiply(int factor)
Description copied from class:SynchronizedIntMultiply value by factor (i.e., set value *= factor)- Overrides:
multiplyin classSynchronizedInt- Returns:
- the new value
-
divide
public int divide(int factor)
Description copied from class:SynchronizedIntDivide value by factor (i.e., set value /= factor)- Overrides:
dividein classSynchronizedInt- Returns:
- the new value
-
complement
public int complement()
Set the value to its complement- Overrides:
complementin classSynchronizedInt- Returns:
- the new value
-
and
public int and(int b)
Set value to value & b.- Overrides:
andin classSynchronizedInt- Returns:
- the new value
-
or
public int or(int b)
Set value to value | b.- Overrides:
orin classSynchronizedInt- Returns:
- the new value
-
xor
public int xor(int b)
Set value to value ^ b.- Overrides:
xorin classSynchronizedInt- Returns:
- the new value
-
whenEqual
public void whenEqual(int 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(int 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(int 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(int 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(int 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(int 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
-
-