Class ClosableBlockingQueue<T>
- java.lang.Object
-
- org.apache.nemo.runtime.executor.transfer.ClosableBlockingQueue<T>
-
- Type Parameters:
T
- the type of elements
- All Implemented Interfaces:
java.lang.AutoCloseable
@ThreadSafe public final class ClosableBlockingQueue<T> extends java.lang.Object implements java.lang.AutoCloseable
A blocking queue implementation which is capable of closing.
-
-
Constructor Summary
Constructors Constructor Description ClosableBlockingQueue()
Creates a closable blocking queue.ClosableBlockingQueue(int numElements)
Creates a closable blocking queue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Mark the input end of this queue as closed.void
closeExceptionally(java.lang.Throwable throwableToSet)
Mark the input end of this queue as closed.T
peek()
Retrieves, but does not removes, the head of this queue, waiting if necessary.void
put(T element)
Adds an element.T
take()
Retrieves and removes the head of this queue, waiting if necessary.
-
-
-
Method Detail
-
put
public void put(T element)
Adds an element.- Parameters:
element
- the element to add- Throws:
java.lang.IllegalStateException
- if the input end of this queue has been closedjava.lang.NullPointerException
- ifelement
isnull
-
close
public void close()
Mark the input end of this queue as closed.- Specified by:
close
in interfacejava.lang.AutoCloseable
-
closeExceptionally
public void closeExceptionally(java.lang.Throwable throwableToSet)
Mark the input end of this queue as closed.- Parameters:
throwableToSet
- a throwable to set as the cause
-
take
@Nullable public T take() throws java.lang.InterruptedException
Retrieves and removes the head of this queue, waiting if necessary.- Returns:
- the head of this queue, or
null
if no elements are there and this queue has been closed - Throws:
java.lang.InterruptedException
- when interrupted while waiting
-
peek
@Nullable public T peek() throws java.lang.InterruptedException
Retrieves, but does not removes, the head of this queue, waiting if necessary.- Returns:
- the head of this queue, or
null
if no elements are there and this queue has been closed - Throws:
java.lang.InterruptedException
- when interrupted while waiting
-
-