-
- All Implemented Interfaces:
-
java.lang.Iterable,java.util.Collection,java.util.Queue,java.util.concurrent.BlockingQueue
public class ArrayBlockingQueueWithShutdown<E> extends AbstractQueue<E> implements BlockingQueue<E>
Like ArrayBlockingQueue but with additional shutdown and start methods. Will throw InterruptedException if Queue has been shutdown on take and poll.
Based on ArrayBlockingQueue of OpenJDK by Doug Lea (who released ArrayBlockingQueue as public domain). Imported from Smack Core 4.2.4.
-
-
Field Summary
Fields Modifier and Type Field Description private volatile booleanisShutdown
-
Constructor Summary
Constructors Constructor Description ArrayBlockingQueueWithShutdown(int capacity)ArrayBlockingQueueWithShutdown(int capacity, boolean fair)
-
Method Summary
Modifier and Type Method Description booleanisShutdown()Returns true if the queue is currently shut down. voidshutdown()Shutdown the Queue. voidstart()Start the queue. Epoll()Epeek()booleanoffer(E e)voidput(E e)Inserts the specified element into this queue, waiting if necessaryfor space to become available. booleanoffer(E e, long timeout, TimeUnit unit)Etake()Epoll(long timeout, TimeUnit unit)intremainingCapacity()intdrainTo(Collection<out Object> c)intdrainTo(Collection<out Object> c, int maxElements)intsize()Iterator<E>iterator()-
Methods inherited from class java.util.AbstractQueue
add, addAll, clear, element, remove -
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString -
Methods inherited from class java.util.Collection
parallelStream, removeIf, spliterator, stream -
Methods inherited from class java.lang.Iterable
forEach, iterator, spliterator -
Methods inherited from class java.util.Queue
offer, peek, poll -
Methods inherited from class java.util.concurrent.BlockingQueue
drainTo, put, remainingCapacity, take -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
isShutdown
boolean isShutdown()
Returns true if the queue is currently shut down.
-
shutdown
void shutdown()
Shutdown the Queue. Will method currently waiting for a not full/empty condition will unblock(and usually throw a InterruptedException).
-
start
void start()
Start the queue. Newly created instances will be started automatically, thus this only needsto be called after shutdown.
-
put
void put(E e)
Inserts the specified element into this queue, waiting if necessaryfor space to become available.
This may throw an InterruptedException in two cases
- If the queue was shut down.
- If the thread was was interrupted.
- Parameters:
e- the element to add.
-
remainingCapacity
int remainingCapacity()
-
drainTo
int drainTo(Collection<out Object> c)
-
drainTo
int drainTo(Collection<out Object> c, int maxElements)
-
size
int size()
-
-
-
-