Class BatchedArrayBlockingQueue<T>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractQueue<T>
-
- org.apache.bookkeeper.common.collections.BatchedArrayBlockingQueue<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.concurrent.BlockingQueue<T>
,java.util.Queue<T>
,BatchedBlockingQueue<T>
public class BatchedArrayBlockingQueue<T> extends java.util.AbstractQueue<T> implements java.util.concurrent.BlockingQueue<T>, BatchedBlockingQueue<T>
This implements aBlockingQueue
backed by an array with fixed capacity.This queue only allows 1 consumer thread to dequeue items and multiple producer threads.
-
-
Constructor Summary
Constructors Constructor Description BatchedArrayBlockingQueue(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
int
drainTo(java.util.Collection<? super T> c)
int
drainTo(java.util.Collection<? super T> c, int maxElements)
java.util.Iterator<T>
iterator()
boolean
offer(T e)
boolean
offer(T e, long timeout, java.util.concurrent.TimeUnit unit)
T
peek()
T
poll()
T
poll(long timeout, java.util.concurrent.TimeUnit unit)
int
pollAll(T[] array, long timeout, java.util.concurrent.TimeUnit unit)
Removes multiple items from the queue.void
put(T e)
int
putAll(java.util.List<T> c)
void
putAll(T[] a, int offset, int len)
int
remainingCapacity()
int
size()
T
take()
int
takeAll(T[] array)
Drain the queue into an array.-
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
offer
public boolean offer(T e)
-
put
public void put(T e) throws java.lang.InterruptedException
- Specified by:
put
in interfacejava.util.concurrent.BlockingQueue<T>
- Throws:
java.lang.InterruptedException
-
putAll
public int putAll(java.util.List<T> c) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
putAll
public void putAll(T[] a, int offset, int len) throws java.lang.InterruptedException
- Specified by:
putAll
in interfaceBatchedBlockingQueue<T>
- Throws:
java.lang.InterruptedException
-
offer
public boolean offer(T e, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
offer
in interfacejava.util.concurrent.BlockingQueue<T>
- Throws:
java.lang.InterruptedException
-
take
public T take() throws java.lang.InterruptedException
- Specified by:
take
in interfacejava.util.concurrent.BlockingQueue<T>
- Throws:
java.lang.InterruptedException
-
poll
public T poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
poll
in interfacejava.util.concurrent.BlockingQueue<T>
- Throws:
java.lang.InterruptedException
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacity
in interfacejava.util.concurrent.BlockingQueue<T>
-
drainTo
public int drainTo(java.util.Collection<? super T> c)
- Specified by:
drainTo
in interfacejava.util.concurrent.BlockingQueue<T>
-
drainTo
public int drainTo(java.util.Collection<? super T> c, int maxElements)
- Specified by:
drainTo
in interfacejava.util.concurrent.BlockingQueue<T>
-
takeAll
public int takeAll(T[] array) throws java.lang.InterruptedException
Description copied from interface:BatchedBlockingQueue
Drain the queue into an array. Wait if there are no items in the queue.- Specified by:
takeAll
in interfaceBatchedBlockingQueue<T>
- Returns:
- Throws:
java.lang.InterruptedException
-
pollAll
public int pollAll(T[] array, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Description copied from interface:BatchedBlockingQueue
Removes multiple items from the queue. The method returns when either: 1. At least one item is available 2. The timeout expires- Specified by:
pollAll
in interfaceBatchedBlockingQueue<T>
- Returns:
- Throws:
java.lang.InterruptedException
-
clear
public void clear()
-
size
public int size()
-
-