Class BlockingQueue

java.lang.Object
org.jpos.util.BlockingQueue

public class BlockingQueue extends Object
implements a blocking queue
Since:
1.1
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Thrown by queue operations after the queue has been closed.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty, open queue.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the queue and wakes all waiting consumers, who will then receive BlockingQueue.Closed.
    int
    Returns the number of consumers currently waiting on this queue.
    int
    Returns the difference between queued items and waiting consumers.
    Removes and returns the head of the queue, blocking until an object is available.
    dequeue(long timeout)
    Removes and returns the head of the queue, blocking up to timeout ms.
    void
    Appends an object to the tail of the queue and wakes one waiter.
    Returns the underlying list backing this queue.
    int
    Returns the number of items currently in the queue.
    boolean
    Indicates whether the queue is open for new operations.
    void
    Inserts an object at the head of the queue and wakes one waiter.
    void
    Replaces the underlying list backing this queue.

    Methods inherited from class Object

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

    • BlockingQueue

      public BlockingQueue()
      Creates an empty, open queue.
  • Method Details

    • enqueue

      public void enqueue(Object o) throws BlockingQueue.Closed
      Appends an object to the tail of the queue and wakes one waiter.
      Parameters:
      o - the object to enqueue
      Throws:
      BlockingQueue.Closed - if the queue has been closed
    • requeue

      public void requeue(Object o) throws BlockingQueue.Closed
      Inserts an object at the head of the queue and wakes one waiter.
      Parameters:
      o - the object to requeue
      Throws:
      BlockingQueue.Closed - if the queue has been closed
    • dequeue

      Removes and returns the head of the queue, blocking until an object is available.
      Returns:
      the object at the head of the queue
      Throws:
      InterruptedException - if the thread is interrupted while waiting
      BlockingQueue.Closed - if the queue is closed while waiting
    • dequeue

      Removes and returns the head of the queue, blocking up to timeout ms.
      Parameters:
      timeout - maximum wait in milliseconds; 0 blocks indefinitely
      Returns:
      the object at the head of the queue, or null if the wait elapsed
      Throws:
      InterruptedException - if the thread is interrupted while waiting
      BlockingQueue.Closed - if the queue is closed while waiting
    • close

      public void close()
      Closes the queue and wakes all waiting consumers, who will then receive BlockingQueue.Closed.
    • consumerCount

      public int consumerCount()
      Returns the number of consumers currently waiting on this queue.
      Returns:
      the live consumer count
    • consumerDeficit

      public int consumerDeficit()
      Returns the difference between queued items and waiting consumers.
      Returns:
      queue size minus consumer count (negative when consumers exceed items)
    • ready

      public boolean ready()
      Indicates whether the queue is open for new operations.
      Returns:
      true if the queue has not been closed
    • pending

      public int pending()
      Returns the number of items currently in the queue.
      Returns:
      the queue size
    • getQueue

      public LinkedList getQueue()
      Returns the underlying list backing this queue.
      Returns:
      the internal list (live reference, not a copy)
    • setQueue

      public void setQueue(LinkedList queue)
      Replaces the underlying list backing this queue.
      Parameters:
      queue - the list to use as the new backing store