Package org.apache.beam.sdk.fn
Class CancellableQueue<T extends @NonNull java.lang.Object>
- java.lang.Object
-
- org.apache.beam.sdk.fn.CancellableQueue<T>
-
@ThreadSafe public class CancellableQueue<T extends @NonNull java.lang.Object> extends java.lang.ObjectA simplifiedThreadSafeblocking queue that can be cancelled freeing any blockedThreads and preventing futureThreads from blocking.The queue is able to be reset and re-used.
-
-
Constructor Summary
Constructors Constructor Description CancellableQueue(int capacity)Creates aThreadSafeblocking queue with a maximum capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel(java.lang.Exception exception)voidput(T t)Adds an element to this queue.voidreset()Enables the queue to be re-used after it has been cancelled.Ttake()Takes an element from this queue.
-
-
-
Method Detail
-
put
public void put(T t) throws java.lang.Exception, java.lang.InterruptedException
Adds an element to this queue. Will block until the queue is not full or is cancelled.- Throws:
java.lang.InterruptedException- if this thread was interrupted waiting to put the element. The caller must invokecancel(java.lang.Exception)if the interrupt is unrecoverable.java.lang.Exception- if the queue is cancelled.
-
take
public T take() throws java.lang.Exception, java.lang.InterruptedException
Takes an element from this queue. Will block until the queue is not full or is cancelled.- Throws:
java.lang.InterruptedException- if this thread was interrupted waiting for an element. The caller must invokecancel(java.lang.Exception)if the interrupt is unrecoverable.java.lang.Exception- if the queue is cancelled.
-
cancel
public void cancel(java.lang.Exception exception)
Causes any pending and futureput(T)andtake()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.
-
reset
public void reset()
Enables the queue to be re-used after it has been cancelled.
-
-