Interface YACBQueue<T>

Type Parameters:
T - the element type
All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
YACBDisruptorQueue, YACBLinkedQueue, YACBRingQueue

public interface YACBQueue<T> extends AutoCloseable

Yet Another Concurrent Blocking Queue.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the Queue.
    void
    A producer calls this method when there are no more items to add.
    boolean
    Tests if production has ended.
    boolean
    Tests if this Queue has been closed.
    Retrieves the first item at the head of the Queue without removing it.
    Retrieves the first item at the head of the Queue and removes it from the Queue.
    T[]
    pollMany(int n)
    A dandy bulk poll method.
    void
    put(T item)
    Add an item to the end of the Queue.
    default void
    Another dandy method.
    void
    putMany(T[] items)
    Another dandy method.
    int
    Gets the current number of items in the Queue.
  • Method Details

    • size

      int size()
      Gets the current number of items in the Queue.
      Returns:
      the number of items
    • peek

      T peek() throws InterruptedException
      Retrieves the first item at the head of the Queue without removing it. If no items are available, this method will block until one item is available or the prodcucer has completed its run.
      Returns:
      the first item
      Throws:
      InterruptedException - if thread has been interrupted
    • poll

      T poll() throws InterruptedException
      Retrieves the first item at the head of the Queue and removes it from the Queue. This method will block if no item is yet available.
      Returns:
      the first item
      Throws:
      InterruptedException - if thread has been interrupted
    • pollMany

      T[] pollMany(int n) throws InterruptedException
      A dandy bulk poll method. Retrieves and removes the goven amount of items. If n is larger than what is available, then fewer items may be returned. This method will block until at least one item is available.
      Parameters:
      n - the number of items to retrieve
      Returns:
      an array of the items
      Throws:
      InterruptedException - if thread has been interrupted
    • put

      void put(T item) throws InterruptedException
      Add an item to the end of the Queue.
      Parameters:
      item - an item to add
      Throws:
      InterruptedException - if thread has been interrupted
    • putMany

      void putMany(T[] items) throws InterruptedException
      Another dandy method. Adds the contents of an array to the queue.
      Parameters:
      items - an array of the items
      Throws:
      InterruptedException - if thread has been interrupted
    • putMany

      default void putMany(Collection<T> items) throws InterruptedException
      Another dandy method. Adds the contents of a Collection to the queue.
      Parameters:
      items - a Collection of items
      Throws:
      InterruptedException - if thread has been interrupted
    • endProduction

      void endProduction()
      A producer calls this method when there are no more items to add. It wakes up waiting consumers.
    • hasProductionEnded

      boolean hasProductionEnded()
      Tests if production has ended.
      Returns:
      true if production has ended, false otherwise
    • close

      void close()
      Closes the Queue.
      Specified by:
      close in interface AutoCloseable
    • isClosed

      boolean isClosed()
      Tests if this Queue has been closed.
      Returns:
      true if closed, false otherwise