Class ArrayBlockingQueue<T>

java.lang.Object
jadex.collection.ArrayBlockingQueue<T>
All Implemented Interfaces:
IBlockingQueue<T>

public class ArrayBlockingQueue<T> extends Object implements IBlockingQueue<T>
Blocking queue implemented as array. The array is expanded automatically when the queue grows.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface jadex.collection.IBlockingQueue

    IBlockingQueue.ClosedException
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    The queue state.
    protected Object[]
    The elements in the queue.
    protected int
    Insert position for the next element.
    protected Object
    The monitor.
    protected int
    The size (cached for speed).
    protected int
    Pointer to the first element.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new blocking queue.
  • Method Summary

    Modifier and Type
    Method
    Description
    Remove an object from the queue (blocks until an element is available).
    dequeue(long timeout)
    Dequeue an element.
    void
    Add an element to the end of the queue.
    boolean
    Check if the queue is closed.
    Peek the topmost element without dequeuing it.
    setClosed(boolean closed)
    Open/close the queue.
    int
    Get the number of elements in the queue.
    Create a string representation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • elements

      protected Object[] elements
      The elements in the queue.
    • start

      protected int start
      Pointer to the first element.
    • end

      protected int end
      Insert position for the next element.
    • size

      protected int size
      The size (cached for speed).
    • monitor

      protected Object monitor
      The monitor.
    • closed

      protected boolean closed
      The queue state.
  • Constructor Details

    • ArrayBlockingQueue

      public ArrayBlockingQueue()
      Create a new blocking queue.
  • Method Details

    • size

      public int size()
      Get the number of elements in the queue.
      Specified by:
      size in interface IBlockingQueue<T>
      Returns:
      The size.
    • enqueue

      public void enqueue(Object o)
      Add an element to the end of the queue.
      Specified by:
      enqueue in interface IBlockingQueue<T>
      Parameters:
      o - The element.
    • dequeue

      public T dequeue(long timeout) throws IBlockingQueue.ClosedException, jadex.common.TimeoutException
      Dequeue an element.
      Specified by:
      dequeue in interface IBlockingQueue<T>
      Parameters:
      timeout - the time to wait (in millis) or -1 for no timeout.
      Returns:
      The element. When queue is empty the methods blocks until an element is added or the timeout occurs.
      Throws:
      IBlockingQueue.ClosedException
      jadex.common.TimeoutException
    • peek

      public T peek() throws IBlockingQueue.ClosedException
      Peek the topmost element without dequeuing it.
      Specified by:
      peek in interface IBlockingQueue<T>
      Returns:
      The element. When queue is empty the methods blocks until an element is added.
      Throws:
      IBlockingQueue.ClosedException
    • dequeue

      public T dequeue()
      Remove an object from the queue (blocks until an element is available).
      Specified by:
      dequeue in interface IBlockingQueue<T>
      Returns:
      The element. When queue is empty the methods blocks until an element is added.
    • setClosed

      public List<T> setClosed(boolean closed)
      Open/close the queue.
      Specified by:
      setClosed in interface IBlockingQueue<T>
      Parameters:
      closed - The closed state.
      Returns:
      The remaining elements after the queue has been closed.
    • isClosed

      public boolean isClosed()
      Check if the queue is closed.
      Specified by:
      isClosed in interface IBlockingQueue<T>
    • toString

      public String toString()
      Create a string representation.
      Overrides:
      toString in class Object