E
- E should implement the Importance interface.public class MultiPriorityBlockingQueue<E>
extends java.util.AbstractQueue<E>
implements java.util.concurrent.BlockingQueue<E>
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 and Description |
---|
MultiPriorityBlockingQueue(java.util.List<InternalQueue<E>> queues,
boolean isFixedQueues,
NextQueueAlgorithm<E> algorithm)
Create a queue with the given queues.
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
contains(java.lang.Object o) |
int |
drainTo(java.util.Collection<? super E> c)
We always give high priority to highest priority elements.
|
int |
drainTo(java.util.Collection<? super E> c,
int maxElements)
We always give high priority to highest priotiry elements.
|
NextQueueAlgorithm<E> |
getNextQueueAlgorithm() |
java.util.List<InternalQueue<E>> |
getQueues() |
boolean |
isEmpty() |
boolean |
isFixedSizeQueues() |
java.util.Iterator<E> |
iterator() |
boolean |
offer(E e)
Add the element if space available in the internal queue corresponding to the
priority of the object.
|
boolean |
offer(E e,
long timeout,
java.util.concurrent.TimeUnit unit)
Try to add the element within the given time period.
|
E |
peek() |
E |
poll()
Block indefinitely until a object is available for retrieval.
|
E |
poll(long timeout,
java.util.concurrent.TimeUnit unit)
Get the element from the top of the queue.
|
void |
put(E e)
Put the specified value in to the queue.
|
int |
remainingCapacity() |
boolean |
remove(java.lang.Object o) |
int |
size() |
E |
take()
Get an element.
|
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public MultiPriorityBlockingQueue(java.util.List<InternalQueue<E>> queues, boolean isFixedQueues, NextQueueAlgorithm<E> algorithm)
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.
queues
- list of InternalQueue to be usedisFixedQueues
- weather fixed size queues are usedalgorithm
- algorithm for calculating next queuepublic void put(E e) throws java.lang.InterruptedException
put
in interface java.util.concurrent.BlockingQueue<E>
e
- object that implements the Importance interfacejava.lang.InterruptedException
public boolean offer(E e)
public boolean offer(E e, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
offer
in interface java.util.concurrent.BlockingQueue<E>
e
- element to be addedtimeout
- time to wait if space not availableunit
- time unitjava.lang.InterruptedException
- if the thread is interruptedpublic E take() throws java.lang.InterruptedException
take
in interface java.util.concurrent.BlockingQueue<E>
java.lang.InterruptedException
- if the thread is interruptedpublic E poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
poll
in interface java.util.concurrent.BlockingQueue<E>
timeout
- waiting time for element to be availableunit
- time unitjava.lang.InterruptedException
public int drainTo(java.util.Collection<? super E> c)
drainTo
in interface java.util.concurrent.BlockingQueue<E>
c
- collection to drain the itemspublic int drainTo(java.util.Collection<? super E> c, int maxElements)
drainTo
in interface java.util.concurrent.BlockingQueue<E>
c
- collection to drain the itemdmaxElements
- maximum elements to copypublic E poll()
poll
in interface java.util.Queue<E>
public int remainingCapacity()
remainingCapacity
in interface java.util.concurrent.BlockingQueue<E>
public java.util.Iterator<E> iterator()
public int size()
public boolean isEmpty()
public boolean remove(java.lang.Object o)
public boolean contains(java.lang.Object o)
public java.lang.String toString()
toString
in class java.util.AbstractCollection<E>
public void clear()
public <T> T[] toArray(T[] a)
public java.lang.Object[] toArray()
public java.util.List<InternalQueue<E>> getQueues()
public NextQueueAlgorithm<E> getNextQueueAlgorithm()
public boolean isFixedSizeQueues()
Copyright © 2005-2020 Apache Software Foundation. All Rights Reserved.