Class ChainedReader

java.lang.Object
io.debezium.connector.mysql.legacy.ChainedReader
All Implemented Interfaces:
Reader

@ThreadSafe public final class ChainedReader extends Object implements Reader
A Reader implementation that runs one or more other Readers in a consistently, completely, and sequentially. This reader ensures that all records generated by one of its contained Readers are all passed through to callers via polling before the next reader is started. And, when this reader is stopped, this class ensures that current reader is stopped and that no additional readers will be started.
Author:
Randall Hauch
  • Field Details

  • Constructor Details

    • ChainedReader

      private ChainedReader(List<Reader> readers, String completionMessage)
      Create a new chained reader.
  • Method Details

    • uponCompletion

      public void uponCompletion(Consumer<MySqlPartition> handler)
      Description copied from interface: Reader
      Set the function that should be called when this reader transitions from the Reader.State.STOPPING to Reader.State.STOPPED state, which is after all generated records have been consumed via the poll method.

      This method should only be called while the reader is in the Reader.State.STOPPED state.

      Specified by:
      uponCompletion in interface Reader
      Parameters:
      handler - the function; may not be null
    • initialize

      public void initialize()
      Description copied from interface: Reader
      Perform any initialization of the reader before being started. This method should be called exactly once before Reader.start(MySqlPartition) ()} is called, and it should block until all initialization is completed.
      Specified by:
      initialize in interface Reader
    • destroy

      public void destroy()
      Description copied from interface: Reader
      After the reader has stopped, there may still be some resources we want left available until the connector task is destroyed. This method is used to clean up those remaining resources upon shutdown. This method is effectively the opposite of Reader.initialize(), performing any de-initialization of the reader entity before shutdown. This method should be called exactly once after Reader.stop() is called, and it should block until all de-initialization is completed.
      Specified by:
      destroy in interface Reader
    • start

      public void start(MySqlPartition partition)
      Description copied from interface: Reader
      Start the reader and return immediately. Once started, the SourceRecords generated by the reader can be obtained by periodically calling Reader.poll() until that method returns null.

      This method does nothing if it is already running.

      Specified by:
      start in interface Reader
    • stop

      public void stop()
      Description copied from interface: Reader
      Stop the reader from running and transition to the Reader.State.STOPPING state until all remaining records are consumed, at which point its state transitions to Reader.State.STOPPED.
      Specified by:
      stop in interface Reader
    • state

      public Reader.State state()
      Description copied from interface: Reader
      Get the current state of this reader.
      Specified by:
      state in interface Reader
      Returns:
      the state; never null
    • poll

      public List<org.apache.kafka.connect.source.SourceRecord> poll() throws InterruptedException
      Description copied from interface: Reader
      Poll for the next batch of source records. This method returns null only when all records generated by this reader have been processed, following the natural or explicit stopping of this reader. Note that this method may block if no additional records are available but the reader may produce more, thus callers should call this method continually until this method returns null.
      Specified by:
      poll in interface Reader
      Returns:
      the list of source records that may or may not be empty; or null when there will be no more records because the reader has completely Reader.State.STOPPED.
      Throws:
      InterruptedException - if this thread is interrupted while waiting for more records
    • readerCompletedPolling

      private void readerCompletedPolling(MySqlPartition partition)
      Called when the previously-started reader has returned all of its records via polling. Only when this method is called is the now-completed reader removed as the current reader, and this is what guarantees that all records produced by the now-completed reader have been polled.
    • startNextReader

      private boolean startNextReader(MySqlPartition partition)
      Start the next reader.
      Returns:
      true if the next reader was started, or false if there are no more readers
    • name

      public String name()
      Description copied from interface: Reader
      Get the name of this reader.
      Specified by:
      name in interface Reader
      Returns:
      the reader's name; never null