Class WaitableByte

All Implemented Interfaces:
Executor, Cloneable, Comparable

public class WaitableByte extends SynchronizedByte
A class useful for offloading waiting and signalling operations on single byte variables.

[ Introduction to this package. ]

  • Field Summary

    Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedByte

    value_

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

    lock_
  • Constructor Summary

    Constructors
    Constructor
    Description
    WaitableByte(byte initialValue)
    Make a new WaitableByte with the given initial value, and using its own internal lock.
    WaitableByte(byte initialValue, Object lock)
    Make a new WaitableByte with the given initial value, and using the supplied lock.
  • Method Summary

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

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

    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

    • WaitableByte

      public WaitableByte(byte initialValue)
      Make a new WaitableByte with the given initial value, and using its own internal lock.
    • WaitableByte

      public WaitableByte(byte initialValue, Object lock)
      Make a new WaitableByte with the given initial value, and using the supplied lock.
  • Method Details

    • set

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

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

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

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

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

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

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

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

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

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

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

      public byte xor(byte b)
      Set value to value ^ b.
      Overrides:
      xor in class SynchronizedByte
      Returns:
      the new value
    • whenEqual

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