Package org.jivesoftware.smack.util
Class ArrayBlockingQueueWithShutdown<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
org.jivesoftware.smack.util.ArrayBlockingQueueWithShutdown<E>
- Type Parameters:
E- the type of elements held in this collection
- All Implemented Interfaces:
Iterable<E>,Collection<E>,BlockingQueue<E>,Queue<E>
Like ArrayBlockingQueue but with additional
shutdown() and start() methods. Will
throw InterruptedException if Queue has been shutdown on take() and
poll(long, TimeUnit).
Based on ArrayBlockingQueue of OpenJDK by Doug Lea (who released ArrayBlockingQueue as public domain).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic final classstatic enum -
Constructor Summary
ConstructorsConstructorDescriptionArrayBlockingQueueWithShutdown(int capacity) ArrayBlockingQueueWithShutdown(int capacity, boolean fair) -
Method Summary
Modifier and TypeMethodDescriptionintdrainTo(Collection<? super E> c) intdrainTo(Collection<? super E> c, int maxElements) booleanReturns true if the queue is currently shut down.iterator()booleanbooleanbooleanpeek()poll()voidInserts the specified element into this queue, waiting if necessary for space to become available.voidputAll(Collection<? extends E> elements) booleanPut if the queue has not been shutdown yet.intvoidshutdown()Shutdown the Queue.intsize()booleanstart()Start the queue.take()tryTake()Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.BlockingQueue
add, contains, removeMethods inherited from interface java.util.Collection
addAll, clear, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
-
Constructor Details
-
ArrayBlockingQueueWithShutdown
public ArrayBlockingQueueWithShutdown(int capacity) -
ArrayBlockingQueueWithShutdown
public ArrayBlockingQueueWithShutdown(int capacity, boolean fair)
-
-
Method Details
-
shutdown
public void shutdown()Shutdown the Queue. Will method currently waiting for a not full/empty condition will unblock (and usually throw a InterruptedException). -
start
public boolean start()Start the queue. Newly created instances will be started automatically, thus this only needs to be called aftershutdown().- Returns:
trueif the queues was shutdown before,falseif not.
-
isShutdown
public boolean isShutdown()Returns true if the queue is currently shut down.- Returns:
- true if the queue is shut down.
-
poll
-
peek
-
offer
-
offerAndShutdown
-
put
Inserts the specified element into this queue, waiting if necessary for space to become available.This may throw an
InterruptedExceptionin two cases- If the queue was shut down.
- If the thread was was interrupted.
isShutdown().- Specified by:
putin interfaceBlockingQueue<E>- Parameters:
e- the element to add.- Throws:
InterruptedException- if interrupted while waiting or if the queue was shut down.
-
putIfNotShutdown
Put if the queue has not been shutdown yet.- Parameters:
e- the element to put into the queue.- Returns:
trueif the element has been put into the queue,falseif the queue was shutdown.- Throws:
InterruptedException- if the calling thread was interrupted.- Since:
- 4.4
-
putAll
- Throws:
InterruptedException
-
tryPut
-
offer
- Specified by:
offerin interfaceBlockingQueue<E>- Throws:
InterruptedException
-
take
- Specified by:
takein interfaceBlockingQueue<E>- Throws:
InterruptedException
-
tryTake
-
poll
- Specified by:
pollin interfaceBlockingQueue<E>- Throws:
InterruptedException
-
remainingCapacity
public int remainingCapacity()- Specified by:
remainingCapacityin interfaceBlockingQueue<E>
-
drainTo
- Specified by:
drainToin interfaceBlockingQueue<E>
-
drainTo
- Specified by:
drainToin interfaceBlockingQueue<E>
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein classAbstractCollection<E>
-
iterator
- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin classAbstractCollection<E>
-