Interface YACBQueue<T>
- Type Parameters:
T- the element type
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
YACBDisruptorQueue, YACBLinkedQueue, YACBRingQueue
Yet Another Concurrent Blocking Queue.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the Queue.voidA producer calls this method when there are no more items to add.booleanTests if production has ended.booleanisClosed()Tests if this Queue has been closed.peek()Retrieves the first item at the head of the Queue without removing it.poll()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.voidAdd an item to the end of the Queue.default voidputMany(Collection<T> items) Another dandy method.voidAnother dandy method.intsize()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
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
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
A dandy bulk poll method. Retrieves and removes the goven amount of items. Ifnis 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
Add an item to the end of the Queue.- Parameters:
item- an item to add- Throws:
InterruptedException- if thread has been interrupted
-
putMany
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
Another dandy method. Adds the contents of aCollectionto 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:
trueif production has ended,falseotherwise
-
close
-
isClosed
boolean isClosed()Tests if this Queue has been closed.- Returns:
trueif closed,falseotherwise
-