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>
public class ArrayBlockingQueueWithShutdown<E> extends AbstractQueue<E> implements BlockingQueue<E>
Like ArrayBlockingQueue but with additionalshutdown()andstart()methods. Will throwInterruptedExceptionif Queue has been shutdown ontake()andpoll(long, TimeUnit).Based on ArrayBlockingQueue of OpenJDK by Doug Lea (who released ArrayBlockingQueue as public domain).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classArrayBlockingQueueWithShutdown.TryPutResultstatic classArrayBlockingQueueWithShutdown.TryTakeResult<E>static classArrayBlockingQueueWithShutdown.TryTakeResultCode
-
Constructor Summary
Constructors Constructor Description ArrayBlockingQueueWithShutdown(int capacity)ArrayBlockingQueueWithShutdown(int capacity, boolean fair)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intdrainTo(Collection<? super E> c)intdrainTo(Collection<? super E> c, int maxElements)booleanisShutdown()Returns true if the queue is currently shut down.Iterator<E>iterator()booleanoffer(E e)booleanoffer(E e, long timeout, TimeUnit unit)booleanofferAndShutdown(E e)Epeek()Epoll()Epoll(long timeout, TimeUnit unit)voidput(E e)Inserts the specified element into this queue, waiting if necessary for space to become available.voidputAll(Collection<? extends E> elements)booleanputIfNotShutdown(E e)Put if the queue has not been shutdown yet.intremainingCapacity()voidshutdown()Shutdown the Queue.intsize()booleanstart()Start the queue.Etake()ArrayBlockingQueueWithShutdown.TryPutResulttryPut(E e)ArrayBlockingQueueWithShutdown.TryTakeResult<E>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
-
-
-
-
Constructor Detail
-
ArrayBlockingQueueWithShutdown
public ArrayBlockingQueueWithShutdown(int capacity)
-
ArrayBlockingQueueWithShutdown
public ArrayBlockingQueueWithShutdown(int capacity, boolean fair)
-
-
Method Detail
-
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.
-
offerAndShutdown
public boolean offerAndShutdown(E e)
-
put
public void put(E e) throws InterruptedException
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
public boolean putIfNotShutdown(E e) throws InterruptedException
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
public void putAll(Collection<? extends E> elements) throws InterruptedException
- Throws:
InterruptedException
-
tryPut
public ArrayBlockingQueueWithShutdown.TryPutResult tryPut(E e)
-
offer
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
offerin interfaceBlockingQueue<E>- Throws:
InterruptedException
-
take
public E take() throws InterruptedException
- Specified by:
takein interfaceBlockingQueue<E>- Throws:
InterruptedException
-
tryTake
public ArrayBlockingQueueWithShutdown.TryTakeResult<E> tryTake()
-
poll
public E poll(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
pollin interfaceBlockingQueue<E>- Throws:
InterruptedException
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacityin interfaceBlockingQueue<E>
-
drainTo
public int drainTo(Collection<? super E> c)
- Specified by:
drainToin interfaceBlockingQueue<E>
-
drainTo
public int drainTo(Collection<? super E> c, int maxElements)
- Specified by:
drainToin interfaceBlockingQueue<E>
-
size
public int size()
- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein classAbstractCollection<E>
-
-