Class Waiter

java.lang.Object
cl.netswitch.lib.aio.Waiter

public final class Waiter extends Object
Blocks the current thread and waits until a condition occurs.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new Waiter instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Causes the current thread to wait until it is signalled or interrupted.
    long
    awaitNanos(long timeoutNS)
    Causes the current thread to wait until it is signalled or interrupted, or the specified waiting time elapses.
    void
    Clears this waiter and release resources.
    Returns the identification or null if none defined.
    Returns the value of this waiter or null if none available.
    boolean
    Returns true this waiter has an identification.
    void
    Initialize this waiter for a new wait operation.
    void
    Acquires the lock.
    void
    Changes the value of this waiter.
    void
    Wakes up one waiting thread.
    void
    Wakes up all waiting threads.
    void
    Attempts to release this lock.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Waiter

      public Waiter()
      Constructs a new Waiter instance.
  • Method Details

    • clear

      public void clear()
      Clears this waiter and release resources.
    • initialize

      public void initialize(String id)
      Initialize this waiter for a new wait operation.
      Parameters:
      id - the new identification of the waiter.
      Throws:
      NullPointerException - if id is null.
    • hasId

      public boolean hasId()
      Returns true this waiter has an identification.
      Returns:
      true this waiter has an identification.
    • getId

      public String getId()
      Returns the identification or null if none defined.
      Returns:
      the identification or null if none defined.
    • getValue

      public Object getValue()
      Returns the value of this waiter or null if none available.
      Returns:
      the value of this waiter or null if none available.
    • setValue

      public void setValue(Object value)
      Changes the value of this waiter.
      Parameters:
      value - the new value of this waiter.
      Throws:
      NullPointerException - if value is null.
    • lock

      public void lock()
      Acquires the lock.

      Acquires the lock if it is not held by another thread and returns immediately, setting the lock hold count to one.

      If the current thread already holds the lock then the hold count is incremented by one and the method returns immediately.

      If the lock is held by another thread then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired, at which time the lock hold count is set to one.

      See Also:
    • await

      public void await() throws InterruptedException
      Causes the current thread to wait until it is signalled or interrupted.
      Throws:
      InterruptedException - if the current thread is interrupted.
      See Also:
    • awaitNanos

      public long awaitNanos(long timeoutNS) throws InterruptedException
      Causes the current thread to wait until it is signalled or interrupted, or the specified waiting time elapses.
      Parameters:
      timeoutNS - the maximum time to wait (nanoseconds).
      Returns:
      an estimate of the timeoutNS value minus the time spent waiting upon return from this method. A positive value may be used as the argument to a subsequent call to this method to finish waiting out the desired time. A value less than or equal to zero indicates that no time remains.
      Throws:
      InterruptedException - if the current thread is interrupted.
      See Also:
    • signal

      public void signal()
      Wakes up one waiting thread.

      If any threads are waiting on this condition then one is selected for waking up. That thread must then re-acquire the lock before returning from awaitNanos.

      See Also:
    • signalAll

      public void signalAll()
      Wakes up all waiting threads.

      If any threads are waiting on this condition then they are all woken up. Each thread must re-acquire the lock before it can return from awaitNanos.

      See Also:
    • unlock

      public void unlock()
      Attempts to release this lock.

      If the current thread is the holder of this lock then the hold count is decremented. If the hold count is now zero then the lock is released. If the current thread is not the holder of this lock then IllegalMonitorStateException is thrown.

      Throws:
      IllegalMonitorStateException - if thread doesn't hold this lock.
      See Also: