Package 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>
A BlockingQueue backed by a circular array capable or growing.
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.
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 max capacity (the maximum size that may be allocated), which defaults to
Integer.MAX_VALUE
.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Default initial capacity, 128.static final int
Default growth factor, 64.Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorDescriptionCreates an unboundedBlockingArrayQueue
with default initial capacity and grow factor.BlockingArrayQueue
(int maxCapacity) Creates a boundedBlockingArrayQueue
that does not grow.BlockingArrayQueue
(int capacity, int growBy) Creates an unboundedBlockingArrayQueue
that grows by the given parameter.BlockingArrayQueue
(int capacity, int growBy, int maxCapacity) Create a boundedBlockingArrayQueue
that grows by the given parameter. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
void
clear()
int
drainTo
(Collection<? super E> c) int
drainTo
(Collection<? super E> c, int maxElements) element()
get
(int index) int
Get the current capacity of this queue.int
Get the max capacity of this queue, or -1 if this queue is unbounded.iterator()
listIterator
(int index) boolean
boolean
peek()
poll()
void
int
remove()
remove
(int index) boolean
int
size()
take()
Methods inherited from class java.util.AbstractList
addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subList
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, 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
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Field Details
-
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITYDefault initial capacity, 128.- See Also:
-
DEFAULT_GROWTH
public static final int DEFAULT_GROWTHDefault growth factor, 64.- See Also:
-
-
Constructor Details
-
BlockingArrayQueue
public BlockingArrayQueue()Creates an unboundedBlockingArrayQueue
with default initial capacity and grow factor.- See Also:
-
BlockingArrayQueue
public BlockingArrayQueue(int maxCapacity) Creates a boundedBlockingArrayQueue
that does not grow. The capacity of the queue is fixed and equal to the given parameter.- Parameters:
maxCapacity
- the maximum capacity
-
BlockingArrayQueue
public BlockingArrayQueue(int capacity, int growBy) Creates an unboundedBlockingArrayQueue
that grows by the given parameter.- Parameters:
capacity
- the initial capacitygrowBy
- the growth factor
-
BlockingArrayQueue
public BlockingArrayQueue(int capacity, int growBy, int maxCapacity) Create a boundedBlockingArrayQueue
that grows by the given parameter.- Parameters:
capacity
- the initial capacitygrowBy
- the growth factormaxCapacity
- the maximum capacity
-
-
Method Details
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceList<E>
- Overrides:
clear
in classAbstractList<E>
-
size
public int size()- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceList<E>
- Specified by:
size
in classAbstractCollection<E>
-
iterator
-
poll
-
poll
- Specified by:
poll
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
peek
-
remove
-
remove
-
remove
- Specified by:
remove
in interfaceBlockingQueue<E>
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classAbstractCollection<E>
-
element
-
offer
-
offer
- Specified by:
offer
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
add
- Specified by:
add
in interfaceBlockingQueue<E>
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceList<E>
- Specified by:
add
in interfaceQueue<E>
- Overrides:
add
in classAbstractList<E>
-
add
-
put
- Specified by:
put
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
take
- Specified by:
take
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
remainingCapacity
public int remainingCapacity()- Specified by:
remainingCapacity
in interfaceBlockingQueue<E>
-
drainTo
- Specified by:
drainTo
in interfaceBlockingQueue<E>
-
drainTo
- Specified by:
drainTo
in interfaceBlockingQueue<E>
-
get
-
set
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
- Overrides:
listIterator
in classAbstractList<E>
-
getCapacity
public int getCapacity()Get the current capacity of this queue.- Returns:
- the current capacity of this queue
-
getMaxCapacity
public int getMaxCapacity()Get the max capacity of this queue, or -1 if this queue is unbounded.- Returns:
- the max capacity of this queue, or -1 if this queue is unbounded
-