@ThreadSafe public class CancellableQueue<T> extends java.lang.Object
ThreadSafe
blocking queue that can be cancelled freeing any blocked Thread
s and preventing future Thread
s from blocking.
The queue is able to be reset and re-used.
Constructor and Description |
---|
CancellableQueue(int capacity)
Creates a
ThreadSafe blocking queue with a maximum capacity. |
Modifier and Type | Method and Description |
---|---|
void |
cancel(java.lang.Exception exception)
|
void |
put(T t)
Adds an element to this queue.
|
void |
reset()
Enables the queue to be re-used after it has been cancelled.
|
T |
take()
Takes an element from this queue.
|
public CancellableQueue(int capacity)
ThreadSafe
blocking queue with a maximum capacity.public void put(T t) throws java.lang.Exception, java.lang.InterruptedException
java.lang.InterruptedException
- if this thread was interrupted waiting to put the element. The
caller must invoke cancel(java.lang.Exception)
if the interrupt is unrecoverable.java.lang.Exception
- if the queue is cancelled.public T take() throws java.lang.Exception, java.lang.InterruptedException
java.lang.InterruptedException
- if this thread was interrupted waiting for an element. The caller
must invoke cancel(java.lang.Exception)
if the interrupt is unrecoverable.java.lang.Exception
- if the queue is cancelled.public void cancel(java.lang.Exception exception)
put(T)
and take()
invocations to throw an exception.
The first call to cancel(java.lang.Exception)
sets the exception that will be thrown. Resetting the
queue clears the exception.
public void reset()