E
- E should implement the Importance interface.public class MultiPriorityBlockingQueue<E> extends AbstractQueue<E> implements 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(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(Object o) |
int |
drainTo(Collection<? super E> c)
We always give high priority to highest priority elements.
|
int |
drainTo(Collection<? super E> c,
int maxElements)
We always give high priority to highest priotiry elements.
|
NextQueueAlgorithm<E> |
getNextQueueAlgorithm() |
List<InternalQueue<E>> |
getQueues() |
boolean |
isEmpty() |
boolean |
isFixedSizeQueues() |
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,
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,
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(Object o) |
int |
size() |
E |
take()
Get an element.
|
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
String |
toString() |
add, addAll, element, remove
containsAll, removeAll, retainAll
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
add
addAll, containsAll, equals, hashCode, parallelStream, removeAll, removeIf, retainAll, spliterator, stream
public MultiPriorityBlockingQueue(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 InterruptedException
put
in interface BlockingQueue<E>
e
- object that implements the Importance interfaceInterruptedException
public boolean offer(E e)
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException
offer
in interface BlockingQueue<E>
e
- element to be addedtimeout
- time to wait if space not availableunit
- time unitInterruptedException
- if the thread is interruptedpublic E take() throws InterruptedException
take
in interface BlockingQueue<E>
InterruptedException
- if the thread is interruptedpublic E poll(long timeout, TimeUnit unit) throws InterruptedException
poll
in interface BlockingQueue<E>
timeout
- waiting time for element to be availableunit
- time unitInterruptedException
public int drainTo(Collection<? super E> c)
drainTo
in interface BlockingQueue<E>
c
- collection to drain the itemspublic int drainTo(Collection<? super E> c, int maxElements)
drainTo
in interface BlockingQueue<E>
c
- collection to drain the itemdmaxElements
- maximum elements to copypublic E poll()
public int remainingCapacity()
remainingCapacity
in interface BlockingQueue<E>
public Iterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in class AbstractCollection<E>
public int size()
size
in interface Collection<E>
size
in class AbstractCollection<E>
public boolean isEmpty()
isEmpty
in interface Collection<E>
isEmpty
in class AbstractCollection<E>
public boolean remove(Object o)
remove
in interface Collection<E>
remove
in interface BlockingQueue<E>
remove
in class AbstractCollection<E>
public boolean contains(Object o)
contains
in interface Collection<E>
contains
in interface BlockingQueue<E>
contains
in class AbstractCollection<E>
public String toString()
toString
in class AbstractCollection<E>
public void clear()
clear
in interface Collection<E>
clear
in class AbstractQueue<E>
public <T> T[] toArray(T[] a)
toArray
in interface Collection<E>
toArray
in class AbstractCollection<E>
public Object[] toArray()
toArray
in interface Collection<E>
toArray
in class AbstractCollection<E>
public List<InternalQueue<E>> getQueues()
public NextQueueAlgorithm<E> getNextQueueAlgorithm()
public boolean isFixedSizeQueues()
Copyright © 2005-2017 Apache Software Foundation. All Rights Reserved.