Class WaitableInt

All Implemented Interfaces:
Executor, Cloneable, Comparable

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

    Constructors
    Constructor
    Description
    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

    Modifier and Type
    Method
    Description
    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
    Set the value to its complement
    int
    Decrement the value.
    int
    divide(int factor)
    Divide value by factor (i.e., set value /= factor)
    int
    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

    compareTo, compareTo, compareTo, equals, get, hashCode, negate, swap, toString

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

    execute, getLock

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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

    • set

      public int set(int newValue)
      Description copied from class: SynchronizedInt
      Set to newValue.
      Overrides:
      set in class SynchronizedInt
      Returns:
      the old value
    • commit

      public boolean commit(int assumedValue, int newValue)
      Description copied from class: SynchronizedInt
      Set value to newValue only if it is currently assumedValue.
      Overrides:
      commit in class SynchronizedInt
      Returns:
      true if successful
    • increment

      public int increment()
      Description copied from class: SynchronizedInt
      Increment the value.
      Overrides:
      increment in class SynchronizedInt
      Returns:
      the new value
    • decrement

      public int decrement()
      Description copied from class: SynchronizedInt
      Decrement the value.
      Overrides:
      decrement in class SynchronizedInt
      Returns:
      the new value
    • add

      public int add(int amount)
      Description copied from class: SynchronizedInt
      Add amount to value (i.e., set value += amount)
      Overrides:
      add in class SynchronizedInt
      Returns:
      the new value
    • subtract

      public int subtract(int amount)
      Description copied from class: SynchronizedInt
      Subtract amount from value (i.e., set value -= amount)
      Overrides:
      subtract in class SynchronizedInt
      Returns:
      the new value
    • multiply

      public int multiply(int factor)
      Description copied from class: SynchronizedInt
      Multiply value by factor (i.e., set value *= factor)
      Overrides:
      multiply in class SynchronizedInt
      Returns:
      the new value
    • divide

      public int divide(int factor)
      Description copied from class: SynchronizedInt
      Divide value by factor (i.e., set value /= factor)
      Overrides:
      divide in class SynchronizedInt
      Returns:
      the new value
    • complement

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

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

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

      public int xor(int b)
      Set value to value ^ b.
      Overrides:
      xor in class 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.
      Throws:
      InterruptedException
    • 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.
      Throws:
      InterruptedException
    • 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.
      Throws:
      InterruptedException
    • 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.
      Throws:
      InterruptedException
    • 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.
      Throws:
      InterruptedException
    • 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.
      Throws:
      InterruptedException