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 without interrupting threads.

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.WakeupException rather than a thread interrupt.

The Handover can also be "closed", signalling from one thread to the other that it the thread has terminated.

  • Constructor Details

    • Handover

      public Handover()
      Deprecated.
  • Method Details

    • 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 was closed.
      Exception - Rethrows exceptions from the reportError(Throwable) method.
    • produce

      public void produce(org.apache.kafka.clients.consumer.ConsumerRecords<byte[],byte[]> element) throws InterruptedException, Handover.WakeupException, Handover.ClosedException
      Deprecated.
      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 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.
    • reportError

      public void reportError(Throwable t)
      Deprecated.
      Reports an exception. The consumer will throw the given exception immediately, if it is currently blocked in the pollNext() method, or the next time it calls that method.

      After this method has been called, no call to either produce(ConsumerRecords) or pollNext() 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 the produce(ConsumerRecords) method and the pollNext() will throw a Handover.ClosedException on 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 calling pollNext(), rather than the ClosedException.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • wakeupProducer

      public void wakeupProducer()
      Deprecated.
      Wakes the producer thread up. If the producer thread is currently blocked in the produce(ConsumerRecords) method, it will exit the method throwing a Handover.WakeupException.