Class ClosableBlockingQueue<E>
- java.lang.Object
-
- org.apache.flink.streaming.connectors.kafka.internals.ClosableBlockingQueue<E>
-
- Type Parameters:
E- The type of elements in the queue.
@Internal @Deprecated public class ClosableBlockingQueue<E> extends Object
Deprecated.A special form of blocking queue with two additions:- The queue can be closed atomically when empty. Adding elements after the queue is closed fails. This allows queue consumers to atomically discover that no elements are available and mark themselves as shut down.
- The queue allows to poll batches of elements in one polling call.
The queue has no capacity restriction and is safe for multiple producers and consumers.
Note: Null elements are prohibited.
-
-
Constructor Summary
Constructors Constructor Description ClosableBlockingQueue()Deprecated.Creates a new empty queue.ClosableBlockingQueue(int initialSize)Deprecated.Creates a new empty queue, reserving space for at least the specified number of elements.ClosableBlockingQueue(Collection<? extends E> initialElements)Deprecated.Creates a new queue that contains the given elements.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(E element)Deprecated.Adds the element to the queue, or fails with an exception, if the queue is closed.booleanaddIfOpen(E element)Deprecated.Tries to add an element to the queue, if the queue is still open.booleanclose()Deprecated.Tries to close the queue.booleanequals(Object obj)Deprecated.List<E>getBatchBlocking()Deprecated.Gets all the elements found in the list, or blocks until at least one element was added.List<E>getBatchBlocking(long timeoutMillis)Deprecated.Gets all the elements found in the list, or blocks until at least one element was added.EgetElementBlocking()Deprecated.Returns the next element in the queue.EgetElementBlocking(long timeoutMillis)Deprecated.Returns the next element in the queue.inthashCode()Deprecated.booleanisEmpty()Deprecated.Checks whether the queue is empty (has no elements).booleanisOpen()Deprecated.Checks whether the queue is currently open, meaning elements can be added and polled.Epeek()Deprecated.Returns the queue's next element without removing it, if the queue is non-empty.Epoll()Deprecated.Returns the queue's next element and removes it, the queue is non-empty.List<E>pollBatch()Deprecated.Returns all of the queue's current elements in a list, if the queue is non-empty.intsize()Deprecated.Gets the number of elements currently in the queue.StringtoString()Deprecated.
-
-
-
Constructor Detail
-
ClosableBlockingQueue
public ClosableBlockingQueue()
Deprecated.Creates a new empty queue.
-
ClosableBlockingQueue
public ClosableBlockingQueue(int initialSize)
Deprecated.Creates a new empty queue, reserving space for at least the specified number of elements. The queue can still grow, of more elements are added than the reserved space.- Parameters:
initialSize- The number of elements to reserve space for.
-
ClosableBlockingQueue
public ClosableBlockingQueue(Collection<? extends E> initialElements)
Deprecated.Creates a new queue that contains the given elements.- Parameters:
initialElements- The elements to initially add to the queue.
-
-
Method Detail
-
size
public int size()
Deprecated.Gets the number of elements currently in the queue.- Returns:
- The number of elements currently in the queue.
-
isEmpty
public boolean isEmpty()
Deprecated.Checks whether the queue is empty (has no elements).- Returns:
- True, if the queue is empty; false, if it is non-empty.
-
isOpen
public boolean isOpen()
Deprecated.Checks whether the queue is currently open, meaning elements can be added and polled.- Returns:
- True, if the queue is open; false, if it is closed.
-
close
public boolean close()
Deprecated.Tries to close the queue. Closing the queue only succeeds when no elements are in the queue when this method is called. Checking whether the queue is empty, and marking the queue as closed is one atomic operation.- Returns:
- True, if the queue is closed, false if the queue remains open.
-
addIfOpen
public boolean addIfOpen(E element)
Deprecated.Tries to add an element to the queue, if the queue is still open. Checking whether the queue is open and adding the element is one atomic operation.Unlike the
add(Object)method, this method never throws an exception, but only indicates via the return code if the element was added or the queue was closed.- Parameters:
element- The element to add.- Returns:
- True, if the element was added, false if the queue was closes.
-
add
public void add(E element) throws IllegalStateException
Deprecated.Adds the element to the queue, or fails with an exception, if the queue is closed. Checking whether the queue is open and adding the element is one atomic operation.- Parameters:
element- The element to add.- Throws:
IllegalStateException- Thrown, if the queue is closed.
-
peek
public E peek()
Deprecated.Returns the queue's next element without removing it, if the queue is non-empty. Otherwise, returns null.The method throws an
IllegalStateExceptionif the queue is closed. Checking whether the queue is open and getting the next element is one atomic operation.This method never blocks.
- Returns:
- The queue's next element, or null, if the queue is empty.
- Throws:
IllegalStateException- Thrown, if the queue is closed.
-
poll
public E poll()
Deprecated.Returns the queue's next element and removes it, the queue is non-empty. Otherwise, this method returns null.The method throws an
IllegalStateExceptionif the queue is closed. Checking whether the queue is open and removing the next element is one atomic operation.This method never blocks.
- Returns:
- The queue's next element, or null, if the queue is empty.
- Throws:
IllegalStateException- Thrown, if the queue is closed.
-
pollBatch
public List<E> pollBatch()
Deprecated.Returns all of the queue's current elements in a list, if the queue is non-empty. Otherwise, this method returns null.The method throws an
IllegalStateExceptionif the queue is closed. Checking whether the queue is open and removing the elements is one atomic operation.This method never blocks.
- Returns:
- All of the queue's elements, or null, if the queue is empty.
- Throws:
IllegalStateException- Thrown, if the queue is closed.
-
getElementBlocking
public E getElementBlocking() throws InterruptedException
Deprecated.Returns the next element in the queue. If the queue is empty, this method waits until at least one element is added.The method throws an
IllegalStateExceptionif the queue is closed. Checking whether the queue is open and removing the next element is one atomic operation.- Returns:
- The next element in the queue, never null.
- Throws:
IllegalStateException- Thrown, if the queue is closed.InterruptedException- Throw, if the thread is interrupted while waiting for an element to be added.
-
getElementBlocking
public E getElementBlocking(long timeoutMillis) throws InterruptedException
Deprecated.Returns the next element in the queue. If the queue is empty, this method waits at most a certain time until an element becomes available. If no element is available after that time, the method returns null.The method throws an
IllegalStateExceptionif the queue is closed. Checking whether the queue is open and removing the next element is one atomic operation.- Parameters:
timeoutMillis- The number of milliseconds to block, at most.- Returns:
- The next element in the queue, or null, if the timeout expires before an element is available.
- Throws:
IllegalStateException- Thrown, if the queue is closed.InterruptedException- Throw, if the thread is interrupted while waiting for an element to be added.
-
getBatchBlocking
public List<E> getBatchBlocking() throws InterruptedException
Deprecated.Gets all the elements found in the list, or blocks until at least one element was added. If the queue is empty when this method is called, it blocks until at least one element is added.This method always returns a list with at least one element.
The method throws an
IllegalStateExceptionif the queue is closed. Checking whether the queue is open and removing the next element is one atomic operation.- Returns:
- A list with all elements in the queue, always at least one element.
- Throws:
IllegalStateException- Thrown, if the queue is closed.InterruptedException- Throw, if the thread is interrupted while waiting for an element to be added.
-
getBatchBlocking
public List<E> getBatchBlocking(long timeoutMillis) throws InterruptedException
Deprecated.Gets all the elements found in the list, or blocks until at least one element was added. This method is similar asgetBatchBlocking(), but takes a number of milliseconds that the method will maximally wait before returning.This method never returns null, but an empty list, if the queue is empty when the method is called and the request times out before an element was added.
The method throws an
IllegalStateExceptionif the queue is closed. Checking whether the queue is open and removing the next element is one atomic operation.- Parameters:
timeoutMillis- The number of milliseconds to wait, at most.- Returns:
- A list with all elements in the queue, possible an empty list.
- Throws:
IllegalStateException- Thrown, if the queue is closed.InterruptedException- Throw, if the thread is interrupted while waiting for an element to be added.
-
-