Package com.pnfsoftware.jeb.util.collect
Class AsyncEventQueue<E>
java.lang.Object
com.pnfsoftware.jeb.util.collect.AsyncEventQueue<E>
- Type Parameters:
E- queued element type
- Direct Known Subclasses:
DexDecompilerEventQueue
Highly efficient, loosely bounded concurrent pseudo-queue for single-reader/multiple-writers
scenarios. The implementation relies on
ConcurrentLinkedQueue.
If the bound is reached, newest elements are dropped. To achieve high write efficiency and avoid
locking, the queue is loosely bounded: under certain conditions, elements may be dropped although
the queue did not reach its capacity; conversely, elements may be added although the queue
reached its capacity. To lift this uncertainty, use a bound of Integer.MAX_VALUE. The
writers should never never pull elements. Null elements are illegal.
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an unbounded queue.AsyncEventQueue(int capacity) Create a queue, optionally bounded. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd to the tail of the queue.voidclear()Remove all queued elements.booleanisEmpty()Determine whether the queue is empty.pull()Pull the head, unless the queue is empty, in which case null is returned.pullAll()Pull all elements.readAll()Read all elements without clearing the queue.intsize()Get the approximate queue size.toString()
-
Constructor Details
-
AsyncEventQueue
public AsyncEventQueue()Create an unbounded queue. -
AsyncEventQueue
public AsyncEventQueue(int capacity) Create a queue, optionally bounded.- Parameters:
capacity- maximum queue capacity
-
-
Method Details
-
add
Add to the tail of the queue.- Parameters:
e- non-null entry to be enqueued- Returns:
- true if the element was added, false if it was dropped
-
pull
Pull the head, unless the queue is empty, in which case null is returned.Implementation note: this method must not be used by producers; its use is reserved for the single consumer.
- Returns:
- the head or null
-
pullAll
Pull all elements.- Returns:
- pulled elements
-
readAll
Read all elements without clearing the queue.- Returns:
- copy of queued elements
-
size
public int size()Get the approximate queue size.- Returns:
- current queue size
-
isEmpty
public boolean isEmpty()Determine whether the queue is empty.- Returns:
- true if the queue is empty
-
clear
public void clear()Remove all queued elements. -
toString
-