Package bbflow

Class ff_queue<T>

java.lang.Object
bbflow.ff_queue<T>
Type Parameters:
T - Type of the queue elements
Direct Known Subclasses:
ff_queue_TCP

public class ff_queue<T> extends Object
Default class of the queues. Queues are channels 1-1 between nodes of type SPSC and FIFO
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) boolean
     
    (package private) LinkedBlockingQueue<T>
     
    (package private) boolean
     
    (package private) boolean
     
    (package private) squeue<T>
     
    (package private) ConcurrentLinkedQueue<T>
     
    private static final long
     
    private static final long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    ff_queue(boolean blocking)
     
    ff_queue(boolean blocking, boolean bounded, int bufferSize)
    Default constructor of the queue.
    ff_queue(int bufferSize)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    check if EOS is in the queue (virtually)
    boolean
    offer(T i)
    Inserts the specified element at the tail of this queue if it is possible to do so immediately without exceeding the queue's capacity, returning true upon success and false if this queue is full
    boolean
    offer(T i, long timeout, TimeUnit timeunit)
    Inserts the specified element at the tail of this queue, waiting if necessary up to the specified wait time for space to become available.
    Retrieves and removes the head of this queue if available.
    poll(long timeout, TimeUnit timeunit)
    Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.
    static void
     
    void
    put(T i)
    Inserts the specified element at the tail of this queue, waiting if necessary for space to become available (if bounded)
    void
    tell the Queue the end of stream reached
    int
    return size of the elements in the queue
    static void
    sleepNanos(long nanoDuration)
    function to replace Thread.sleep that is inefficient, timewaster and unprecise
    Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.

    Methods inherited from class java.lang.Object

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

    • blocking_queue

      LinkedBlockingQueue<T> blocking_queue
    • nonblocking_queue

      ConcurrentLinkedQueue<T> nonblocking_queue
    • nonblocking_bounded_queue

      squeue<T> nonblocking_bounded_queue
    • EOS

      boolean EOS
    • blocking

      boolean blocking
    • bounded

      boolean bounded
    • SLEEP_PRECISION

      private static final long SLEEP_PRECISION
    • SPIN_YIELD_PRECISION

      private static final long SPIN_YIELD_PRECISION
  • Constructor Details

    • ff_queue

      public ff_queue(boolean blocking, boolean bounded, int bufferSize)
      Default constructor of the queue. Types available are 4: BLOCKING / BOUNDED BLOCKING / UNBOUNDED NON BLOCKING / BOUNDED NON BLOCKING / UNBOUNDED
      Parameters:
      blocking - BLOCKING = true / NONBLOCKING = false
      bounded - BOUNDED = true / UNBOUNDED = false
      bufferSize - size of the queue in case it's BOUNDED
    • ff_queue

      public ff_queue()
    • ff_queue

      public ff_queue(boolean blocking)
    • ff_queue

      public ff_queue(int bufferSize)
  • Method Details

    • preload

      public static void preload()
    • put

      public void put(T i)
      Inserts the specified element at the tail of this queue, waiting if necessary for space to become available (if bounded)
      Parameters:
      i - Element to insert
    • setEOS

      public void setEOS()
      tell the Queue the end of stream reached
    • getEOS

      public boolean getEOS()
      check if EOS is in the queue (virtually)
    • take

      public T take() throws InterruptedException
      Retrieves and removes the head of this queue, waiting if necessary until an element becomes available. If EOS true and Queue empty, null is returned
      Returns:
      Element retrieved or null
      Throws:
      InterruptedException
    • poll

      public T poll(long timeout, TimeUnit timeunit) throws InterruptedException
      Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available. if EOS reached, call take() function returning the element or null (if queue empty)
      Parameters:
      timeout -
      timeunit -
      Returns:
      the element or null. Null if EOS is true, means EOS reached. Null with EOS false means poll timedout
      Throws:
      InterruptedException
    • poll

      public T poll() throws InterruptedException
      Retrieves and removes the head of this queue if available. Return null if not available if EOS reached, call take() function returning the element or null (if queue empty)
      Returns:
      the element or null. Null if EOS is true, means EOS reached.
      Throws:
      InterruptedException
    • offer

      public boolean offer(T i)
      Inserts the specified element at the tail of this queue if it is possible to do so immediately without exceeding the queue's capacity, returning true upon success and false if this queue is full
      Parameters:
      i - element to insert
      Returns:
      true or false
    • offer

      public boolean offer(T i, long timeout, TimeUnit timeunit) throws InterruptedException
      Inserts the specified element at the tail of this queue, waiting if necessary up to the specified wait time for space to become available.
      Parameters:
      i - element to insert
      timeout - time to wait
      timeunit - unit of the time to wait
      Returns:
      true or false
      Throws:
      InterruptedException
    • size

      public int size()
      return size of the elements in the queue
      Returns:
      size
    • sleepNanos

      public static void sleepNanos(long nanoDuration) throws InterruptedException
      function to replace Thread.sleep that is inefficient, timewaster and unprecise
      Parameters:
      nanoDuration - nanoseconds to wait
      Throws:
      InterruptedException