Package org.jppf.utils.concurrent
Interface QueueHandler<E>
- Type Parameters:
E- the type of the elements in the queue.
public interface QueueHandler<E>
Instances of this class handle an optionally bounded queue of elements.
It may, upon request, spawn one or more dequeuing threads that will process elements according to a processing function supplied by the consumer.
It also maintains basic statistics about the queue size, peak size, number of queued and rejected elements.
- Author:
- Laurent Cohen
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classBuilder class forQueueHandlerinstances.static interfaceAn operation applied to each element taken from the queue by the dequeuer thread(s).static interfaceCallback invoked when a new peak queue size is reached. -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> QueueHandler.Builder<E>builder()Create a builder to construct and configure aQueueHandler.voidclose()Close this queue handler.intGet the peak queue size.longGet the count elements that were sucessfully queued.longGet the count elements that were rejected.booleanisEmpty()Determine whether the queue is empty.booleanAdd the specified element to the tail of the queue.booleanofferToHead(E element) Add the specified element to the head of the queue.poll()Get the head element from the queue.voidAdd the specified element to the tail of the queue, waiting if necessary for available space in the queue.voidAdd the specified element to the head of the queue, waiting if necessary for available space in the queue.intsize()Get the size of the queue.take()Get the head element from the queue, waiting if necessary for an element to becomes available.
-
Method Details
-
offer
Add the specified element to the tail of the queue.- Parameters:
element- the element to add.- Returns:
trueif the element was successfully added,falseotherwise.
-
offerToHead
Add the specified element to the head of the queue.- Parameters:
element- the element to add.- Returns:
trueif the element was successfully added,falseotherwise.
-
put
Add the specified element to the tail of the queue, waiting if necessary for available space in the queue.- Parameters:
element- the element to add.- Throws:
Exception- if any error occurs.
-
putToHead
Add the specified element to the head of the queue, waiting if necessary for available space in the queue.- Parameters:
element- the element to add.- Throws:
Exception- if any error occurs.
-
poll
E poll()Get the head element from the queue.- Returns:
- the head element, or
nullif the queue is empty.
-
take
Get the head element from the queue, waiting if necessary for an element to becomes available.- Returns:
- the head element.
- Throws:
Exception- if any error occurs.
-
isEmpty
boolean isEmpty()Determine whether the queue is empty.- Returns:
trueif the queue is empty,falseotherwise.
-
size
int size()Get the size of the queue.- Returns:
- the queue size as an
int.
-
getPeakSize
int getPeakSize()Get the peak queue size.- Returns:
- the peak queue size as an int.
-
getQueuedElements
long getQueuedElements()Get the count elements that were sucessfully queued.- Returns:
- the count as a
longvalue.
-
getRejectedElements
long getRejectedElements()Get the count elements that were rejected.- Returns:
- the count as a
longvalue.
-
close
void close()Close this queue handler. -
builder
Create a builder to construct and configure aQueueHandler.- Type Parameters:
E- the type of elements in the queue.- Returns:
- A build object ot construct and configure a
QueueHandler.
-