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
Modifier and TypeClassDescriptionstatic enum
static final class
static enum
-
Constructor Summary
ConstructorDescriptionArrayBlockingQueueWithShutdown
(int capacity) ArrayBlockingQueueWithShutdown
(int capacity, boolean fair) -
Method Summary
Modifier and TypeMethodDescriptionint
drainTo
(Collection<? super E> c) int
drainTo
(Collection<? super E> c, int maxElements) boolean
Returns true if the queue is currently shut down.iterator()
boolean
boolean
boolean
peek()
poll()
void
Inserts the specified element into this queue, waiting if necessary for space to become available.void
putAll
(Collection<? extends E> elements) boolean
Put if the queue has not been shutdown yet.int
void
shutdown()
Shutdown the Queue.int
size()
boolean
start()
Start the queue.take()
tryTake()
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
Methods inherited from interface java.util.concurrent.BlockingQueue
add, contains, remove
Methods inherited from interface java.util.Collection
addAll, clear, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
-
Constructor Details
-
ArrayBlockingQueueWithShutdown
-
ArrayBlockingQueueWithShutdown
-
-
Method Details
-
shutdown
Shutdown the Queue. Will method currently waiting for a not full/empty condition will unblock (and usually throw a InterruptedException). -
start
Start the queue. Newly created instances will be started automatically, thus this only needs to be called aftershutdown()
.- Returns:
true
if the queues was shutdown before,false
if not.
-
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
InterruptedException
in two cases- If the queue was shut down.
- If the thread was was interrupted.
isShutdown()
.- Specified by:
put
in 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:
true
if the element has been put into the queue,false
if the queue was shutdown.- Throws:
InterruptedException
- if the calling thread was interrupted.- Since:
- 4.4
-
putAll
- Throws:
InterruptedException
-
tryPut
-
offer
- Specified by:
offer
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
take
- Specified by:
take
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
tryTake
-
poll
- Specified by:
poll
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
remainingCapacity
- Specified by:
remainingCapacity
in interfaceBlockingQueue<E>
-
drainTo
- Specified by:
drainTo
in interfaceBlockingQueue<E>
-
drainTo
- Specified by:
drainTo
in interfaceBlockingQueue<E>
-
size
- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in classAbstractCollection<E>
-
iterator
- Specified by:
iterator
in interfaceCollection<E>
- Specified by:
iterator
in interfaceIterable<E>
- Specified by:
iterator
in classAbstractCollection<E>
-