EDU.oswego.cs.dl.util.concurrent

Class WaitableLong

Implemented Interfaces:
Cloneable, Comparable, Executor

public class WaitableLong
extends SynchronizedLong

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

[ Introduction to this package. ]

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

WaitableLong(long initialValue)
Make a new WaitableLong with the given initial value, and using its own internal lock.
WaitableLong(long initialValue, Object lock)
Make a new WaitableLong with the given initial value, and using the supplied lock.

Method Summary

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

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

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

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

Method Details

add

public long add(long amount)
Add amount to value (i.e., set value += amount)
Overrides:
add in interface SynchronizedLong

Returns:
the new value


commit

public boolean commit(long assumedValue,
                      long newValue)
Set value to newValue only if it is currently assumedValue.
Overrides:
commit in interface SynchronizedLong

Returns:
true if successful


decrement

public long decrement()
Decrement the value.
Overrides:
decrement in interface SynchronizedLong

Returns:
the new value


divide

public long divide(long factor)
Divide value by factor (i.e., set value /= factor)
Overrides:
divide in interface SynchronizedLong

Returns:
the new value


increment

public long increment()
Increment the value.
Overrides:
increment in interface SynchronizedLong

Returns:
the new value


multiply

public long multiply(long factor)
Multiply value by factor (i.e., set value *= factor)
Overrides:
multiply in interface SynchronizedLong

Returns:
the new value


set

public long set(long newValue)
Set to newValue.
Overrides:
set in interface SynchronizedLong

Returns:
the old value


subtract

public long subtract(long amount)
Subtract amount from value (i.e., set value -= amount)
Overrides:
subtract in interface SynchronizedLong

Returns:
the new value


whenEqual

public void whenEqual(long 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(long 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(long 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(long 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(long 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(long 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.