Class ChainedReader
java.lang.Object
io.debezium.connector.mysql.legacy.ChainedReader
- All Implemented Interfaces:
Reader
A
Reader
implementation that runs one or more other Reader
s in a consistently, completely, and sequentially.
This reader ensures that all records generated by one of its contained Reader
s 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 classes/interfaces inherited from interface io.debezium.connector.mysql.legacy.Reader
Reader.State
-
Field Summary
Modifier and TypeFieldDescriptionprivate final AtomicBoolean
private final String
private final AtomicReference<Reader>
private final org.slf4j.Logger
private final LinkedList<Reader>
private final AtomicBoolean
private final AtomicReference<Consumer<MySqlPartition>>
-
Constructor Summary
ModifierConstructorDescriptionprivate
ChainedReader
(List<Reader> readers, String completionMessage) Create a new chained reader. -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
After the reader has stopped, there may still be some resources we want left available until the connector task is destroyed.void
Perform 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 void
readerCompletedPolling
(MySqlPartition partition) Called when the previously-started reader has returned all of its records viapolling
.void
start
(MySqlPartition partition) Start the reader and return immediately.private boolean
startNextReader
(MySqlPartition partition) Start the next reader.state()
Get the current state of this reader.void
stop()
Stop the reader from running and transition to theReader.State.STOPPING
state until all remaining records areconsumed
, at which point its state transitions toReader.State.STOPPED
.void
uponCompletion
(Consumer<MySqlPartition> handler) Set the function that should be called when this reader transitions from theReader.State.STOPPING
toReader.State.STOPPED
state, which is after all generated records have been consumed via thepoll
method.
-
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:Reader
Set the function that should be called when this reader transitions from theReader.State.STOPPING
toReader.State.STOPPED
state, which is after all generated records have been consumed via thepoll
method.This method should only be called while the reader is in the
Reader.State.STOPPED
state.- Specified by:
uponCompletion
in interfaceReader
- 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 beforeReader.start(MySqlPartition)
()} is called, and it should block until all initialization is completed.- Specified by:
initialize
in interfaceReader
-
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 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:Reader
Start the reader and return immediately. Once started, theSourceRecord
s 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:Reader
Stop the reader from running and transition to theReader.State.STOPPING
state until all remaining records areconsumed
, at which point its state transitions toReader.State.STOPPED
. -
state
Description copied from interface:Reader
Get the current state of this reader. -
poll
Description copied from interface:Reader
Poll for the next batch of source records. This method returnsnull
only when all records generated by this reader have been processed, following the natural or explicitstopping
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 returnsnull
.- Specified by:
poll
in interfaceReader
- 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 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:
true
if the next reader was started, orfalse
if there are no more readers
-
name
Description copied from interface:Reader
Get the name of this reader.
-