org.apache.synapse.commons.executors

## 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>

      public class MultiPriorityBlockingQueue<E>
      extends AbstractQueue<E>
      implements BlockingQueue<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

    Constructors
    Constructor and Description
    `MultiPriorityBlockingQueue(List<InternalQueue<E>> queues, boolean isFixedQueues, NextQueueAlgorithm<E> algorithm)` Create a queue with the given queues.

  - ### Method Summary

    Methods
    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()`

    - ### Methods inherited from class java.util.AbstractQueue

      `add, addAll, element, remove`

    - ### Methods inherited from class java.util.AbstractCollection

      `containsAll, removeAll, retainAll`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.concurrent.BlockingQueue

      `add`

    - ### Methods inherited from interface java.util.Queue

      `element, remove`

    - ### Methods inherited from interface java.util.Collection

      `addAll, containsAll, equals, hashCode, removeAll, retainAll`

- - ### Constructor Detail

    - #### 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 used
        `isFixedQueues` - weather fixed size queues are used
        `algorithm` - algorithm for calculating next queue

  - ### Method Detail

    - #### put

          public void put(E e)
                   throws InterruptedException

      Put the specified value in to the queue. The put will block until space available in the corresponding internal queue.
      Specified by:
        `put` in interface `BlockingQueue<E>`
      Parameters:
        `e` - object that implements the Importance interface
      Throws:
        `InterruptedException`

    - #### offer

          public boolean offer(E e)

      Add the element if space available in the internal queue corresponding to the priority of the object.
      Specified by:
        `offer` in interface `BlockingQueue<E>`
      Specified by:
        `offer` in interface `Queue<E>`
      Parameters:
        `e` - element to be added
      Returns:
        true if element is added

    - #### offer

          public boolean offer(E e,
                      long timeout,
                      TimeUnit unit)
                        throws InterruptedException

      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:
        `offer` in interface `BlockingQueue<E>`
      Parameters:
        `e` - element to be added
        `timeout` - time to wait if space not available
        `unit` - time unit
      Returns:
        true if the element is added
      Throws:
        `InterruptedException` - if the thread is interrupted

    - #### take

          public E take()
                 throws InterruptedException

      Get an element. Block until an element is available
      Specified by:
        `take` in interface `BlockingQueue<E>`
      Returns:
        an element
      Throws:
        `InterruptedException` - if the thread is interrupted

    - #### poll

          public E poll(long timeout,
               TimeUnit unit)
                 throws InterruptedException

      Get the element from the top of the queue. If an element is not available wait the specified timeout.
      Specified by:
        `poll` in interface `BlockingQueue<E>`
      Parameters:
        `timeout` - waiting time for element to be available
        `unit` - time unit
      Returns:
        an object
      Throws:
        `InterruptedException`

    - #### drainTo

          public int drainTo(Collection<? super E> c)

      We always give high priority to highest priority elements. We try to drain all the high priority items first.
      Specified by:
        `drainTo` in interface `BlockingQueue<E>`
      Parameters:
        `c` - collection to drain the items
      Returns:
        number of elements copied

    - #### drainTo

          public int drainTo(Collection<? super E> c,
                    int maxElements)

      We always give high priority to highest priotiry elements. We try to drain all the high priority items first.
      Specified by:
        `drainTo` in interface `BlockingQueue<E>`
      Parameters:
        `c` - collection to drain the itemd
        `maxElements` - maximum elements to copy
      Returns:
        number of elements copied

    - #### poll

          public E poll()

      Block indefinitely until a object is available for retrieval.
      Specified by:
        `poll` in interface `Queue<E>`
      Returns:
        an object

    - #### remainingCapacity

          public int remainingCapacity()

      Specified by:
        `remainingCapacity` in interface `BlockingQueue<E>`

    - #### peek

          public E peek()

      Specified by:
        `peek` in interface `Queue<E>`

    - #### iterator

          public Iterator<E> iterator()

      Specified by:
        `iterator` in interface `Iterable<E>`
      Specified by:
        `iterator` in interface `Collection<E>`
      Specified by:
        `iterator` in class `AbstractCollection<E>`

    - #### size

          public int size()

      Specified by:
        `size` in interface `Collection<E>`
      Specified by:
        `size` in class `AbstractCollection<E>`

    - #### isEmpty

          public boolean isEmpty()

      Specified by:
        `isEmpty` in interface `Collection<E>`
      Overrides:
        `isEmpty` in class `AbstractCollection<E>`

    - #### remove

          public boolean remove(Object o)

      Specified by:
        `remove` in interface `Collection<E>`
      Specified by:
        `remove` in interface `BlockingQueue<E>`
      Overrides:
        `remove` in class `AbstractCollection<E>`

    - #### contains

          public boolean contains(Object o)

      Specified by:
        `contains` in interface `Collection<E>`
      Specified by:
        `contains` in interface `BlockingQueue<E>`
      Overrides:
        `contains` in class `AbstractCollection<E>`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `AbstractCollection<E>`

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `Collection<E>`
      Overrides:
        `clear` in class `AbstractQueue<E>`

    - #### toArray

          public <T> T[] toArray(T[] a)

      Specified by:
        `toArray` in interface `Collection<E>`
      Overrides:
        `toArray` in class `AbstractCollection<E>`

    - #### toArray

          public Object[] toArray()

      Specified by:
        `toArray` in interface `Collection<E>`
      Overrides:
        `toArray` in class `AbstractCollection<E>`

    - #### getQueues

          public List<InternalQueue<E>> getQueues()

    - #### getNextQueueAlgorithm

          public NextQueueAlgorithm<E> getNextQueueAlgorithm()

    - #### isFixedSizeQueues

          public boolean isFixedSizeQueues()

Copyright © 2005–2017 Apache Software Foundation. All rights reserved.