@ThreadSafe @Internal public final class Handover extends Object implements Closeable
This class is used in the Flink Kafka Consumer to hand over data and exceptions between the thread that runs the KafkaConsumer class and the main thread.
The Handover has the notion of "waking up" the producer thread with a
rather than a thread interrupt.
The Handover can also be "closed", signalling from one thread to the other that it the thread has terminated.
|Modifier and Type||Class and Description|
An exception thrown by the Handover in the
A special exception thrown bv the Handover in the
|Constructor and Description|
|Modifier and Type||Method and Description|
Closes the handover.
Polls the next element from the Handover, possibly blocking until the next element is available.
Hands over an element from the producer.
Reports an exception.
Wakes the producer thread up.
@Nonnull public org.apache.kafka.clients.consumer.ConsumerRecords<byte,byte> pollNext() throws Exception
If an exception was handed in by the producer (
reportError(Throwable)), then that
exception is thrown rather than an element being returned.
Handover.ClosedException- Thrown if the Handover was
Exception- Rethrows exceptions from the
public void produce(org.apache.kafka.clients.consumer.ConsumerRecords<byte,byte> element) throws InterruptedException, Handover.WakeupException, Handover.ClosedException
This behavior is similar to a "size one" blocking queue.
element- The next element to hand over.
InterruptedException- Thrown, if the thread is interrupted while blocking for the Handover to be empty.
Handover.WakeupException- Thrown, if the
wakeupProducer()method is called while blocking for the Handover to be empty.
Handover.ClosedException- Thrown if the Handover was closed or concurrently being closed.
public void reportError(Throwable t)
pollNext()method, or the next time it calls that method.
After this method has been called, no call to either
pollNext() will ever return regularly any more, but will always return
If another exception was already reported, this method does nothing.
For the producer, the Handover will appear as if it was
t- The exception to report.
public void close()
produce(ConsumerRecords)method and the
pollNext()will throw a
Handover.ClosedExceptionon any currently blocking and future invocations.
If an exception was previously reported via the
that exception will not be overridden. The consumer thread will throw that exception upon
pollNext(), rather than the
public void wakeupProducer()
produce(ConsumerRecords)method, it will exit the method throwing a
Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.