Class YACBRingQueue<T>
java.lang.Object
net.okapia.osid.torrefacto.queue.YACBRingQueue<T>
- Type Parameters:
T- the element type
- All Implemented Interfaces:
AutoCloseable, YACBQueue<T>
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newYACBRingQueuewith the default capacity.YACBRingQueue(int capacity) Constructs a newYACBRingQueuewith the given capacity. -
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.voidAnother dandy method.intsize()Gets the current number of items in the Queue.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface YACBQueue
putManyModifier and TypeMethodDescriptiondefault voidputMany(Collection<T> items) Another dandy method.
-
Constructor Details
-
YACBRingQueue
public YACBRingQueue()Constructs a newYACBRingQueuewith the default capacity. -
YACBRingQueue
public YACBRingQueue(int capacity) Constructs a newYACBRingQueuewith the given capacity.- Parameters:
capacity- the queue capacity
-
-
Method Details
-
size
-
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 producer has completed its run.- Specified by:
peekin interfaceYACBQueue<T>- 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.- Specified by:
pollin interfaceYACBQueue<T>- Returns:
- the first item
- Throws:
InterruptedException- if thread has been interrupted
-
pollMany
A dandy bulk poll method. Retrieves and removes the given 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.- Specified by:
pollManyin interfaceYACBQueue<T>- 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.- Specified by:
putin interfaceYACBQueue<T>- 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. All items are enqueued under a single lock acquisition, waiting onnotFullif the queue fills mid-batch.- Specified by:
putManyin interfaceYACBQueue<T>- Parameters:
items- an array of items to add- Throws:
InterruptedException- if thread has been interrupted
-
endProduction
public void endProduction()A producer calls this method when there are no more items to add. It wakes up waiting consumers.- Specified by:
endProductionin interfaceYACBQueue<T>
-
close
public void close()Closes the Queue.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceYACBQueue<T>
-
hasProductionEnded
public boolean hasProductionEnded()Tests if production has ended.- Specified by:
hasProductionEndedin interfaceYACBQueue<T>- Returns:
trueif production has ended,falseotherwise
-
isClosed
-