EDU.oswego.cs.dl.util.concurrent

Class WaitableInt

Implemented Interfaces:
Cloneable, Comparable, Executor

public class WaitableInt
extends SynchronizedInt

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

[ Introduction to this package. ]

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

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

int
add(int amount)
Add amount to value (i.e., set value += amount)
int
and(int b)
Set value to value & b.
boolean
commit(int assumedValue, int newValue)
Set value to newValue only if it is currently assumedValue.
int
complement()
Set the value to its complement
int
decrement()
Decrement the value.
int
divide(int factor)
Divide value by factor (i.e., set value /= factor)
int
increment()
Increment the value.
int
multiply(int factor)
Multiply value by factor (i.e., set value *= factor)
int
or(int b)
Set value to value | b.
int
set(int newValue)
Set to newValue.
int
subtract(int amount)
Subtract amount from value (i.e., set value -= amount)
void
whenEqual(int c, Runnable action)
Wait until value equals c, then run action if nonnull.
void
whenGreater(int c, Runnable action)
wait until value greater than c, then run action if nonnull.
void
whenGreaterEqual(int c, Runnable action)
wait until value greater than or equal to c, then run action if nonnull.
void
whenLess(int c, Runnable action)
wait until value less than c, then run action if nonnull.
void
whenLessEqual(int c, Runnable action)
wait until value less than or equal to c, then run action if nonnull.
void
whenNotEqual(int c, Runnable action)
wait until value not equal to c, then run action if nonnull.
int
xor(int b)
Set value to value ^ b.

Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedInt

add, and, commit, compareTo, compareTo, compareTo, complement, decrement, divide, equals, get, hashCode, increment, multiply, negate, or, set, subtract, swap, toString, xor

Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable

execute, getLock

Constructor Details

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 Details

add

public int add(int amount)
Add amount to value (i.e., set value += amount)
Overrides:
add in interface SynchronizedInt
Returns:
the new value

and

public int and(int b)
Set value to value & b.
Overrides:
and in interface SynchronizedInt
Returns:
the new value

commit

public boolean commit(int assumedValue,
                      int newValue)
Set value to newValue only if it is currently assumedValue.
Overrides:
commit in interface SynchronizedInt
Returns:
true if successful

complement

public int complement()
Set the value to its complement
Overrides:
complement in interface SynchronizedInt
Returns:
the new value

decrement

public int decrement()
Decrement the value.
Overrides:
decrement in interface SynchronizedInt
Returns:
the new value

divide

public int divide(int factor)
Divide value by factor (i.e., set value /= factor)
Overrides:
divide in interface SynchronizedInt
Returns:
the new value

increment

public int increment()
Increment the value.
Overrides:
increment in interface SynchronizedInt
Returns:
the new value

multiply

public int multiply(int factor)
Multiply value by factor (i.e., set value *= factor)
Overrides:
multiply in interface SynchronizedInt
Returns:
the new value

or

public int or(int b)
Set value to value | b.
Overrides:
or in interface SynchronizedInt
Returns:
the new value

set

public int set(int newValue)
Set to newValue.
Overrides:
set in interface SynchronizedInt
Returns:
the old value

subtract

public int subtract(int amount)
Subtract amount from value (i.e., set value -= amount)
Overrides:
subtract in interface SynchronizedInt
Returns:
the new value

whenEqual

public void whenEqual(int c,
                      Runnable action)
            throws InterruptedException
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)
            throws InterruptedException
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)
            throws InterruptedException
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)
            throws InterruptedException
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)
            throws InterruptedException
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)
            throws InterruptedException
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.
Overrides:
xor in interface SynchronizedInt
Returns:
the new value