EDU.oswego.cs.dl.util.concurrent

Class WaitableInt

public class WaitableInt extends SynchronizedInt

A class useful for offloading waiting and signalling operations on single int variables.

[ Introduction to this package. ]

Constructor Summary
WaitableInt(int initialValue)
Make a new WaitableInt with the given initial value, and using its own internal lock.
WaitableInt(int initialValue, Object lock)
Make a new WaitableInt with the given initial value, and using the supplied lock.
Method Summary
intadd(int amount)
intand(int b)
Set value to value & b.
booleancommit(int assumedValue, int newValue)
intcomplement()
Set the value to its complement
intdecrement()
intdivide(int factor)
intincrement()
intmultiply(int factor)
intor(int b)
Set value to value | b.
intset(int newValue)
intsubtract(int amount)
voidwhenEqual(int c, Runnable action)
Wait until value equals c, then run action if nonnull.
voidwhenGreater(int c, Runnable action)
wait until value greater than c, then run action if nonnull.
voidwhenGreaterEqual(int c, Runnable action)
wait until value greater than or equal to c, then run action if nonnull.
voidwhenLess(int c, Runnable action)
wait until value less than c, then run action if nonnull.
voidwhenLessEqual(int c, Runnable action)
wait until value less than or equal to c, then run action if nonnull.
voidwhenNotEqual(int c, Runnable action)
wait until value not equal to c, then run action if nonnull.
intxor(int b)
Set value to value ^ b.

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, Object lock)
Make a new WaitableInt with the given initial value, and using the supplied lock.

Method Detail

add

public int add(int amount)

and

public int and(int b)
Set value to value & b.

Returns: the new value

commit

public boolean commit(int assumedValue, int newValue)

complement

public int complement()
Set the value to its complement

Returns: the new value

decrement

public int decrement()

divide

public int divide(int factor)

increment

public int increment()

multiply

public int multiply(int factor)

or

public int or(int b)
Set value to value | b.

Returns: the new value

set

public int set(int newValue)

subtract

public int subtract(int amount)

whenEqual

public void whenEqual(int c, Runnable action)
Wait until value equals c, then run action if nonnull. The action is run with the synchronization lock held.

whenGreater

public void whenGreater(int c, Runnable action)
wait until value greater than c, then run action if nonnull. The action is run with the synchronization lock held.

whenGreaterEqual

public void whenGreaterEqual(int c, Runnable action)
wait until value greater than or equal to c, then run action if nonnull. The action is run with the synchronization lock held.

whenLess

public void whenLess(int c, Runnable action)
wait until value less than c, then run action if nonnull. The action is run with the synchronization lock held.

whenLessEqual

public void whenLessEqual(int c, Runnable action)
wait until value less than or equal to c, then run action if nonnull. The action is run with the synchronization lock held.

whenNotEqual

public void whenNotEqual(int c, Runnable action)
wait until value not equal to c, then run action if nonnull. The action is run with the synchronization lock held.

xor

public int xor(int b)
Set value to value ^ b.

Returns: the new value