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
Default class of the queues. Queues are channels 1-1 between nodes of type SPSC and FIFO
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean
(package private) LinkedBlockingQueue<T>
(package private) boolean
(package private) boolean
(package private) ConcurrentLinkedQueue<T>
private static final long
private static final long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
getEOS()
check if EOS is in the queue (virtually)boolean
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 fullboolean
Inserts the specified element at the tail of this queue, waiting if necessary up to the specified wait time for space to become available.poll()
Retrieves and removes the head of this queue if available.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
preload()
void
Inserts the specified element at the tail of this queue, waiting if necessary for space to become available (if bounded)void
setEOS()
tell the Queue the end of stream reachedint
size()
return size of the elements in the queuestatic void
sleepNanos
(long nanoDuration) function to replace Thread.sleep that is inefficient, timewaster and unprecisetake()
Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.
-
Field Details
-
blocking_queue
LinkedBlockingQueue<T> blocking_queue -
nonblocking_queue
ConcurrentLinkedQueue<T> nonblocking_queue -
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 = falsebounded
- BOUNDED = true / UNBOUNDED = falsebufferSize
- 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
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
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
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
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
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
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 inserttimeout
- time to waittimeunit
- 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
function to replace Thread.sleep that is inefficient, timewaster and unprecise- Parameters:
nanoDuration
- nanoseconds to wait- Throws:
InterruptedException
-