Class ChainedReader
java.lang.Object
io.debezium.connector.mysql.legacy.ChainedReader
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface io.debezium.connector.mysql.legacy.Reader
Reader.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicBooleanprivate final Stringprivate final AtomicReference<Reader>private final org.slf4j.Loggerprivate final LinkedList<Reader>private final AtomicBooleanprivate final AtomicReference<Consumer<MySqlPartition>> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateChainedReader(List<Reader> readers, String completionMessage) Create a new chained reader. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()After the reader has stopped, there may still be some resources we want left available until the connector task is destroyed.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.private voidreaderCompletedPolling(MySqlPartition partition) Called when the previously-started reader has returned all of its records viapolling.voidstart(MySqlPartition partition) Start the reader and return immediately.private booleanstartNextReader(MySqlPartition partition) Start the next reader.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.
-
Field Details
-
logger
private final org.slf4j.Logger logger -
readers
-
completionMessage
-
remainingReaders
-
running
-
completed
-
currentReader
-
uponCompletion
-
-
Constructor Details
-
ChainedReader
Create a new chained reader.
-
-
Method Details
-
uponCompletion
Description copied from interface:ReaderSet 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.- Specified by:
uponCompletionin interfaceReader- Parameters:
handler- the function; may not be null
-
initialize
public void initialize()Description copied from interface:ReaderPerform any initialization of the reader before being started. This method should be called exactly once beforeReader.start(MySqlPartition)()} is called, and it should block until all initialization is completed.- Specified by:
initializein interfaceReader
-
destroy
public void destroy()Description copied from interface:ReaderAfter 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 ofReader.initialize(), performing any de-initialization of the reader entity before shutdown. This method should be called exactly once afterReader.stop()is called, and it should block until all de-initialization is completed. -
start
Description copied from interface:ReaderStart the reader and return immediately. Once started, theSourceRecords generated by the reader can be obtained by periodically callingReader.poll()until that method returnsnull.This method does nothing if it is already running.
-
stop
public void stop()Description copied from interface:ReaderStop the reader from running and transition to theReader.State.STOPPINGstate until all remaining records areconsumed, at which point its state transitions toReader.State.STOPPED. -
state
Description copied from interface:ReaderGet the current state of this reader. -
poll
Description copied from interface:ReaderPoll 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.- Specified by:
pollin interfaceReader- 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 records
-
readerCompletedPolling
Called when the previously-started reader has returned all of its records viapolling. 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
Start the next reader.- Returns:
trueif the next reader was started, orfalseif there are no more readers
-
name
Description copied from interface:ReaderGet the name of this reader.
-