E
- element type.public class BlockingFetchQueues<E> extends Object
ArrayDeque
s, ordered by priority. Elements are
put(Object, int, boolean)
with a priority and added to one of the
queues, accordingly. take()
returns an element from the highest
priority non-empty queue. Furthermore, there is a prefetch deque of bounded
size to provides elements when all the queues are exhausted. clearToPrefetch()
empties all queues, and moves the removed elements to the prefetch queue.
Locking is adapted from ArrayBlockingQueue
.
BlockingFetchQueues
is constructed with the number of priority levels
n. Priorities are consecutive integers 0 ... n-1, where 0
is the highest priority. Priorities of enqueued
entries are clamped to the range 0 ... n-1.
Constructor and Description |
---|
BlockingFetchQueues(int numPriorities,
int numConsumers) |
BlockingFetchQueues(int numPriorities,
int numConsumers,
int prefetchCapacity) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Atomically removes all of the elements from this queue.
|
void |
clearToPrefetch()
Atomically removes all of the elements from this queue.
|
long |
getCurrentFrame() |
int |
getNumPriorities() |
void |
pause()
Pause the queue.
|
void |
put_unsafe(E element,
int priority,
boolean enqueuToFront)
Equivalent to
put(Object, int, boolean) , but priorities are not
clamped to the allowed range. |
void |
put(E element,
int priority,
boolean enqueuToFront)
Add element to the queue of the specified priority.
|
void |
resume() |
E |
take()
Remove and return an element from the highest priority non-empty queue.
|
public BlockingFetchQueues(int numPriorities, int numConsumers)
public BlockingFetchQueues(int numPriorities, int numConsumers, int prefetchCapacity)
public void put(E element, int priority, boolean enqueuToFront)
element
- the element to enqueuepriority
- lower values mean higher priorityenqueuToFront
- if true, enqueue element at the front (LIFO). if false,
enqueue element at the back (FIFO)public void put_unsafe(E element, int priority, boolean enqueuToFront)
put(Object, int, boolean)
, but priorities are not
clamped to the allowed range. Will throw an
ArrayIndexOutOfBoundsException
if priority < 0
or
priority >= numPriorities
.
Add element to the queue of the specified priority. The element can be added to the front or back of the queue.
element
- the element to enqueuepriority
- lower values mean higher priorityenqueuToFront
- if true, enqueue element at the front (LIFO). if false,
enqueue element at the back (FIFO)public E take() throws InterruptedException
InterruptedException
public void pause() throws InterruptedException
take()
. The pause()
method itself blocks until all (of
the pre-defined number of) consumer threads have arrived in
take()
.
While the queue is paused, all calls to take()
block. (Calls to
put()
are not affected.)
InterruptedException
public void resume() throws InterruptedException
InterruptedException
public void clearToPrefetch()
prefetch
deque.public void clear()
prefetch
deque, will be empty after this call
returns.public int getNumPriorities()
public long getCurrentFrame()
Copyright © 2015–2022 ImgLib2. All rights reserved.