org.eclipse.jetty.util

## Class BlockingArrayQueue<E>

- java.lang.Object
- - java.util.AbstractCollection<E>
  - - java.util.AbstractList<E>
    - - org.eclipse.jetty.util.BlockingArrayQueue<E>

- Type Parameters:
    `E` - The element type
  All Implemented Interfaces:
    Iterable<E>, Collection<E>, BlockingQueue<E>, List<E>, Queue<E>

      public class BlockingArrayQueue<E>
      extends AbstractList<E>
      implements BlockingQueue<E>

  Queue backed by a circular array. This queue is uses a variant of the two lock queue algorithm to provide an efficient queue or list backed by a growable circular array. This queue also has a partial implementation of `BlockingQueue`, specifically the `take()` and `poll(long, TimeUnit)` methods. Unlike `ArrayBlockingQueue`, this class is able to grow and provides a blocking put call.

  The queue has both a capacity (the size of the array currently allocated) and a limit (the maximum size that may be allocated), which defaults to `Integer.MAX_VALUE`.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `int` | `DEFAULT_CAPACITY`
    `int` | `DEFAULT_GROWTH`

    - ### Fields inherited from class java.util.AbstractList

      `modCount`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BlockingArrayQueue()` Create a growing partially blocking Queue
    `BlockingArrayQueue(int limit)` Create a fixed size partially blocking Queue
    `BlockingArrayQueue(int capacity, int growBy)` Create a growing partially blocking Queue.
    `BlockingArrayQueue(int capacity, int growBy, int limit)` Create a growing limited partially blocking Queue.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `add(E e)`
    `void` | `add(int index, E e)`
    `void` | `clear()`
    `int` | `drainTo(Collection<? super E> c)`
    `int` | `drainTo(Collection<? super E> c, int maxElements)`
    `E` | `element()`
    `E` | `get(int index)`
    `int` | `getCapacity()`
    `int` | `getLimit()`
    `boolean` | `isEmpty()`
    `boolean` | `offer(E e)`
    `boolean` | `offer(E o, long timeout, TimeUnit unit)`
    `E` | `peek()`
    `E` | `poll()`
    `E` | `poll(long time, TimeUnit unit)` Retrieves and removes the head of this queue, waiting if necessary up to the specified wait time if no elements are present on this queue.
    `void` | `put(E o)`
    `int` | `remainingCapacity()`
    `E` | `remove()`
    `E` | `remove(int index)`
    `E` | `set(int index, E e)`
    `int` | `size()`
    `E` | `take()` Retrieves and removes the head of this queue, waiting if no elements are present on this queue.

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

      `addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList`

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

      `addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString`

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

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

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

      `contains, remove`

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

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

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

      `addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray`

- - ### Field Detail

    - #### DEFAULT_CAPACITY

          public final int DEFAULT_CAPACITY

      See Also:
        Constant Field Values

    - #### DEFAULT_GROWTH

          public final int DEFAULT_GROWTH

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### BlockingArrayQueue

          public BlockingArrayQueue()

      Create a growing partially blocking Queue

    - #### BlockingArrayQueue

          public BlockingArrayQueue(int limit)

      Create a fixed size partially blocking Queue
      Parameters:
        `limit` - The initial capacity and the limit.

    - #### BlockingArrayQueue

          public BlockingArrayQueue(int capacity,
                            int growBy)

      Create a growing partially blocking Queue.
      Parameters:
        `capacity` - Initial capacity
        `growBy` - Incremental capacity.

    - #### BlockingArrayQueue

          public BlockingArrayQueue(int capacity,
                            int growBy,
                            int limit)

      Create a growing limited partially blocking Queue.
      Parameters:
        `capacity` - Initial capacity
        `growBy` - Incremental capacity.
        `limit` - maximum capacity.

  - ### Method Detail

    - #### getCapacity

          public int getCapacity()

    - #### getLimit

          public int getLimit()

    - #### add

          public boolean add(E e)

      Specified by:
        `add` in interface `Collection<E>`
      Specified by:
        `add` in interface `BlockingQueue<E>`
      Specified by:
        `add` in interface `List<E>`
      Specified by:
        `add` in interface `Queue<E>`
      Overrides:
        `add` in class `AbstractList<E>`

    - #### element

          public E element()

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

    - #### peek

          public E peek()

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

    - #### offer

          public boolean offer(E e)

      Specified by:
        `offer` in interface `BlockingQueue<E>`
      Specified by:
        `offer` in interface `Queue<E>`

    - #### poll

          public E poll()

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

    - #### take

          public E take()
                 throws InterruptedException

      Retrieves and removes the head of this queue, waiting if no elements are present on this queue.
      Specified by:
        `take` in interface `BlockingQueue<E>`
      Returns:
        the head of this queue
      Throws:
        `InterruptedException` - if interrupted while waiting.

    - #### poll

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

      Retrieves and removes the head of this queue, waiting if necessary up to the specified wait time if no elements are present on this queue.
      Specified by:
        `poll` in interface `BlockingQueue<E>`
      Parameters:
        `time` - how long to wait before giving up, in units of `unit`
        `unit` - a `TimeUnit` determining how to interpret the `timeout` parameter
      Returns:
        the head of this queue, or `null` if the specified waiting time elapses before an element is present.
      Throws:
        `InterruptedException` - if interrupted while waiting.

    - #### remove

          public E remove()

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

    - #### clear

          public void clear()

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

    - #### isEmpty

          public boolean isEmpty()

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

    - #### size

          public int size()

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

    - #### get

          public E get(int index)

      Specified by:
        `get` in interface `List<E>`
      Specified by:
        `get` in class `AbstractList<E>`

    - #### remove

          public E remove(int index)

      Specified by:
        `remove` in interface `List<E>`
      Overrides:
        `remove` in class `AbstractList<E>`

    - #### set

          public E set(int index,
              E e)

      Specified by:
        `set` in interface `List<E>`
      Overrides:
        `set` in class `AbstractList<E>`

    - #### add

          public void add(int index,
                 E e)

      Specified by:
        `add` in interface `List<E>`
      Overrides:
        `add` in class `AbstractList<E>`

    - #### drainTo

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

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

    - #### drainTo

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

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

    - #### offer

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

      Specified by:
        `offer` in interface `BlockingQueue<E>`
      Throws:
        `InterruptedException`

    - #### put

          public void put(E o)
                   throws InterruptedException

      Specified by:
        `put` in interface `BlockingQueue<E>`
      Throws:
        `InterruptedException`

    - #### remainingCapacity

          public int remainingCapacity()

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

Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.