Class Handover
- java.lang.Object
-
- org.apache.flink.streaming.connectors.kafka.internals.Handover
-
- All Implemented Interfaces:
Closeable,AutoCloseable
@ThreadSafe @Internal @Deprecated public final class Handover extends Object implements Closeable
Deprecated.The Handover is a utility to hand over data (a buffer of records) and exception from a producer thread to a consumer thread. It effectively behaves like a "size one blocking queue", with some extras around exception reporting, closing, and waking up thread withoutinterruptingthreads.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
Handover.WakeupExceptionrather than a thread interrupt.The Handover can also be "closed", signalling from one thread to the other that it the thread has terminated.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHandover.ClosedExceptionDeprecated.An exception thrown by the Handover in thepollNext()orproduce(ConsumerRecords)method, after the Handover was closed viaclose().static classHandover.WakeupExceptionDeprecated.A special exception thrown bv the Handover in theproduce(ConsumerRecords)method when the producer is woken up from a blocking call viawakeupProducer().
-
Constructor Summary
Constructors Constructor Description Handover()Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()Deprecated.Closes the handover.org.apache.kafka.clients.consumer.ConsumerRecords<byte[],byte[]>pollNext()Deprecated.Polls the next element from the Handover, possibly blocking until the next element is available.voidproduce(org.apache.kafka.clients.consumer.ConsumerRecords<byte[],byte[]> element)Deprecated.Hands over an element from the producer.voidreportError(Throwable t)Deprecated.Reports an exception.voidwakeupProducer()Deprecated.Wakes the producer thread up.
-
-
-
Method Detail
-
pollNext
@Nonnull public org.apache.kafka.clients.consumer.ConsumerRecords<byte[],byte[]> pollNext() throws Exception
Deprecated.Polls the next element from the Handover, possibly blocking until the next element is available. This method behaves similar to polling from a blocking queue.If an exception was handed in by the producer (
reportError(Throwable)), then that exception is thrown rather than an element being returned.- Returns:
- The next element (buffer of records, never null).
- Throws:
Handover.ClosedException- Thrown if the Handover wasclosed.Exception- Rethrows exceptions from thereportError(Throwable)method.
-
produce
public void produce(org.apache.kafka.clients.consumer.ConsumerRecords<byte[],byte[]> element) throws InterruptedException, Handover.WakeupException, Handover.ClosedExceptionDeprecated.Hands over an element from the producer. If the Handover already has an element that was not yet picked up by the consumer thread, this call blocks until the consumer picks up that previous element.This behavior is similar to a "size one" blocking queue.
- Parameters:
element- The next element to hand over.- Throws:
InterruptedException- Thrown, if the thread is interrupted while blocking for the Handover to be empty.Handover.WakeupException- Thrown, if thewakeupProducer()method is called while blocking for the Handover to be empty.Handover.ClosedException- Thrown if the Handover was closed or concurrently being closed.
-
reportError
public void reportError(Throwable t)
Deprecated.Reports an exception. The consumer will throw the given exception immediately, if it is currently blocked in thepollNext()method, or the next time it calls that method.After this method has been called, no call to either
produce(ConsumerRecords)orpollNext()will ever return regularly any more, but will always return exceptionally.If another exception was already reported, this method does nothing.
For the producer, the Handover will appear as if it was
closed.- Parameters:
t- The exception to report.
-
close
public void close()
Deprecated.Closes the handover. Both theproduce(ConsumerRecords)method and thepollNext()will throw aHandover.ClosedExceptionon any currently blocking and future invocations.If an exception was previously reported via the
reportError(Throwable)method, that exception will not be overridden. The consumer thread will throw that exception upon callingpollNext(), rather than theClosedException.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
wakeupProducer
public void wakeupProducer()
Deprecated.Wakes the producer thread up. If the producer thread is currently blocked in theproduce(ConsumerRecords)method, it will exit the method throwing aHandover.WakeupException.
-
-