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:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.concurrent.BlockingQueue<E>, java.util.Queue<E>

      public class MultiPriorityBlockingQueue<E>
      extends java.util.AbstractQueue<E>
      implements java.util.concurrent.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(java.util.List<InternalQueue<E>> queues, boolean isFixedQueues, NextQueueAlgorithm<E> algorithm)` Create a queue with the given queues.

  - ### Method Summary

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

    - ### 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, parallelStream, removeAll, removeIf, retainAll, spliterator, stream`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach`

- - ### Constructor Detail

    - #### MultiPriorityBlockingQueue

          public MultiPriorityBlockingQueue(java.util.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 java.lang.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 `java.util.concurrent.BlockingQueue<E>`
      Parameters:
        `e` - object that implements the Importance interface
      Throws:
        `java.lang.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 `java.util.concurrent.BlockingQueue<E>`
      Specified by:
        `offer` in interface `java.util.Queue<E>`
      Parameters:
        `e` - element to be added
      Returns:
        true if element is added

    - #### offer

          public boolean offer(E e,
                               long timeout,
                               java.util.concurrent.TimeUnit unit)
                        throws java.lang.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 `java.util.concurrent.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:
        `java.lang.InterruptedException` - if the thread is interrupted

    - #### take

          public E take()
                 throws java.lang.InterruptedException

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

    - #### poll

          public E poll(long timeout,
                        java.util.concurrent.TimeUnit unit)
                 throws java.lang.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 `java.util.concurrent.BlockingQueue<E>`
      Parameters:
        `timeout` - waiting time for element to be available
        `unit` - time unit
      Returns:
        an object
      Throws:
        `java.lang.InterruptedException`

    - #### drainTo

          public int drainTo(java.util.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 `java.util.concurrent.BlockingQueue<E>`
      Parameters:
        `c` - collection to drain the items
      Returns:
        number of elements copied

    - #### drainTo

          public int drainTo(java.util.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 `java.util.concurrent.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 `java.util.Queue<E>`
      Returns:
        an object

    - #### remainingCapacity

          public int remainingCapacity()

      Specified by:
        `remainingCapacity` in interface `java.util.concurrent.BlockingQueue<E>`

    - #### peek

          public E peek()

      Specified by:
        `peek` in interface `java.util.Queue<E>`

    - #### iterator

          public java.util.Iterator<E> iterator()

      Specified by:
        `iterator` in interface `java.lang.Iterable<E>`
      Specified by:
        `iterator` in interface `java.util.Collection<E>`
      Specified by:
        `iterator` in class `java.util.AbstractCollection<E>`

    - #### size

          public int size()

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

    - #### isEmpty

          public boolean isEmpty()

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

    - #### remove

          public boolean remove(java.lang.Object o)

      Specified by:
        `remove` in interface `java.util.Collection<E>`
      Specified by:
        `remove` in interface `java.util.concurrent.BlockingQueue<E>`
      Overrides:
        `remove` in class `java.util.AbstractCollection<E>`

    - #### contains

          public boolean contains(java.lang.Object o)

      Specified by:
        `contains` in interface `java.util.Collection<E>`
      Specified by:
        `contains` in interface `java.util.concurrent.BlockingQueue<E>`
      Overrides:
        `contains` in class `java.util.AbstractCollection<E>`

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.util.AbstractCollection<E>`

    - #### clear

          public void clear()

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

    - #### toArray

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

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

    - #### toArray

          public java.lang.Object[] toArray()

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

    - #### getQueues

          public java.util.List<InternalQueue<E>> getQueues()

    - #### getNextQueueAlgorithm

          public NextQueueAlgorithm<E> getNextQueueAlgorithm()

    - #### isFixedSizeQueues

          public boolean isFixedSizeQueues()

Copyright © 2005-2020 Apache Software Foundation. All Rights Reserved.