Class MultiPriorityBlockingQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
org.apache.synapse.commons.executors.MultiPriorityBlockingQueue<E>
- Type Parameters:
E- E should implement the Importance interface.
- All Implemented Interfaces:
Iterable<E>,Collection<E>,BlockingQueue<E>,Queue<E>
This queue implements the BlockingQueue interface. The element should implement the
Importance interface.
Internally Queue is implemented as a set of multiple queues corresponding to some fixed priorities. When inserting an element, it will be put in to one of these queues depending on its importance.
-
Constructor Summary
ConstructorsConstructorDescriptionMultiPriorityBlockingQueue(List<InternalQueue<E>> queues, boolean isFixedQueues, NextQueueAlgorithm<E> algorithm) Create a queue with the given queues. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleanintdrainTo(Collection<? super E> c) We always give high priority to highest priority elements.intdrainTo(Collection<? super E> c, int maxElements) We always give high priority to highest priotiry elements.booleanisEmpty()booleaniterator()booleanAdd the element if space available in the internal queue corresponding to the priority of the object.booleanTry to add the element within the given time period.peek()poll()Block indefinitely until a object is available for retrieval.Get the element from the top of the queue.voidPut the specified value in to the queue.intbooleanintsize()take()Get an element.Object[]toArray()<T> T[]toArray(T[] a) toString()Methods inherited from class java.util.AbstractQueue
add, addAll, element, removeMethods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAllMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.BlockingQueue
addMethods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray
-
Constructor Details
-
MultiPriorityBlockingQueue
public MultiPriorityBlockingQueue(List<InternalQueue<E>> queues, boolean isFixedQueues, NextQueueAlgorithm<E> algorithm) Create a queue with the given queues.This method will create a Queue that accepts objects with only the priorities specified. If a object is submitted with a different priority it will result in an IllegalArgumentException. If the algorithm is null, this queue will use the PRRNextQueueAlgorithm.
- Parameters:
queues- list of InternalQueue to be usedisFixedQueues- weather fixed size queues are usedalgorithm- algorithm for calculating next queue
-
-
Method Details
-
put
Put the specified value in to the queue. The put will block until space available in the corresponding internal queue.- Specified by:
putin interfaceBlockingQueue<E>- Parameters:
e- object that implements the Importance interface- Throws:
InterruptedException
-
offer
Add the element if space available in the internal queue corresponding to the priority of the object. -
offer
Try to add the element within the given time period. Wait the specified time for space to be available. This method will put the object in to the internal queue with the corresponding priority. This method blocks only if that internal queue is full.- Specified by:
offerin interfaceBlockingQueue<E>- Parameters:
e- element to be addedtimeout- time to wait if space not availableunit- time unit- Returns:
- true if the element is added
- Throws:
InterruptedException- if the thread is interrupted
-
take
Get an element. Block until an element is available- Specified by:
takein interfaceBlockingQueue<E>- Returns:
- an element
- Throws:
InterruptedException- if the thread is interrupted
-
poll
Get the element from the top of the queue. If an element is not available wait the specified timeout.- Specified by:
pollin interfaceBlockingQueue<E>- Parameters:
timeout- waiting time for element to be availableunit- time unit- Returns:
- an object
- Throws:
InterruptedException
-
drainTo
We always give high priority to highest priority elements. We try to drain all the high priority items first.- Specified by:
drainToin interfaceBlockingQueue<E>- Parameters:
c- collection to drain the items- Returns:
- number of elements copied
-
drainTo
We always give high priority to highest priotiry elements. We try to drain all the high priority items first.- Specified by:
drainToin interfaceBlockingQueue<E>- Parameters:
c- collection to drain the itemdmaxElements- maximum elements to copy- Returns:
- number of elements copied
-
poll
Block indefinitely until a object is available for retrieval. -
remainingCapacity
public int remainingCapacity()- Specified by:
remainingCapacityin interfaceBlockingQueue<E>
-
peek
-
iterator
- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin classAbstractCollection<E>
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
remove
- Specified by:
removein interfaceBlockingQueue<E>- Specified by:
removein interfaceCollection<E>- Overrides:
removein classAbstractCollection<E>
-
contains
- Specified by:
containsin interfaceBlockingQueue<E>- Specified by:
containsin interfaceCollection<E>- Overrides:
containsin classAbstractCollection<E>
-
toString
- Overrides:
toStringin classAbstractCollection<E>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Overrides:
clearin classAbstractQueue<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<E>- Overrides:
toArrayin classAbstractCollection<E>
-
toArray
- Specified by:
toArrayin interfaceCollection<E>- Overrides:
toArrayin classAbstractCollection<E>
-
getQueues
-
getNextQueueAlgorithm
-
isFixedSizeQueues
public boolean isFixedSizeQueues()
-