Interface Reader
- All Known Implementing Classes:
AbstractReader,BinlogReader,BlockingReader,ChainedReader,ParallelSnapshotReader,ReconcilingBinlogReader,SnapshotReader,TimedBlockingReader
A reader starts out in the stopped state, and when start(MySqlPartition) () started} transitions to a
Reader.State.RUNNING state. The reader may either complete its work or be explicitly stopped, at which
point the reader transitions to a {@value State#STOPPING stopping} state until all already-generated SourceRecords
are consumed by the client via the poll method. Only after all records are consumed does the reader
transition to the stopped state and call the uponCompletion(Consumer) method.
See ChainedReader if multiple Reader implementations are to be run in-sequence while keeping the
correct start, stop, and completion semantics.
- Author:
- Randall Hauch
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiondefault voiddestroy()After the reader has stopped, there may still be some resources we want left available until the connector task is destroyed.default voidPerform any initialization of the reader before being started.name()Get the name of this reader.List<org.apache.kafka.connect.source.SourceRecord>poll()Poll for the next batch of source records.voidstart(MySqlPartition partition) Start the reader and return immediately.state()Get the current state of this reader.voidstop()Stop the reader from running and transition to theReader.State.STOPPINGstate until all remaining records areconsumed, at which point its state transitions toReader.State.STOPPED.voiduponCompletion(Consumer<MySqlPartition> handler) Set the function that should be called when this reader transitions from theReader.State.STOPPINGtoReader.State.STOPPEDstate, which is after all generated records have been consumed via thepollmethod.
-
Method Details
-
name
String name()Get the name of this reader.- Returns:
- the reader's name; never null
-
state
Reader.State state()Get the current state of this reader.- Returns:
- the state; never null
-
uponCompletion
Set the function that should be called when this reader transitions from theReader.State.STOPPINGtoReader.State.STOPPEDstate, which is after all generated records have been consumed via thepollmethod.This method should only be called while the reader is in the
Reader.State.STOPPEDstate.- Parameters:
handler- the function; may not be null
-
initialize
default void initialize()Perform any initialization of the reader before being started. This method should be called exactly once beforestart(MySqlPartition)()} is called, and it should block until all initialization is completed. -
destroy
default void destroy()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 ofinitialize(), performing any de-initialization of the reader entity before shutdown. This method should be called exactly once afterstop()is called, and it should block until all de-initialization is completed. -
start
Start the reader and return immediately. Once started, theSourceRecords generated by the reader can be obtained by periodically callingpoll()until that method returnsnull.This method does nothing if it is already running.
-
stop
void stop()Stop the reader from running and transition to theReader.State.STOPPINGstate until all remaining records areconsumed, at which point its state transitions toReader.State.STOPPED. -
poll
Poll for the next batch of source records. This method returnsnullonly when all records generated by this reader have been processed, following the natural or explicitstoppingof 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 returnsnull.- Returns:
- the list of source records that may or may not be empty; or
nullwhen there will be no more records because the reader has completelyReader.State.STOPPED. - Throws:
InterruptedException- if this thread is interrupted while waiting for more recordsorg.apache.kafka.connect.errors.ConnectException- if there is an error while this reader is running
-