Interface Reader
-
- All Known Implementing Classes:
AbstractReader
,BinlogReader
,BlockingReader
,ChainedReader
,ParallelSnapshotReader
,ReconcilingBinlogReader
,SnapshotReader
,TimedBlockingReader
public interface Reader
A component that reads a portion of the MySQL server history or current state.A reader starts out in the
stopped
state, and whenstarted
transitions to aReader.State.RUNNING
state. The reader may either complete its work or be explicitlystopped
, at which point the reader transitions to a {@value State#STOPPING stopping} state until all already-generatedSourceRecord
s are consumed by the client via thepoll
method. Only after all records are consumed does the reader transition to thestopped
state and call theuponCompletion(Runnable)
method.See
ChainedReader
if multipleReader
implementations are to be run in-sequence while keeping the correct start, stop, and completion semantics.- Author:
- Randall Hauch
- See Also:
ChainedReader
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Reader.State
The possible states of a reader.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
destroy()
After the reader has stopped, there may still be some resources we want left available until the connector task is destroyed.default void
initialize()
Perform any initialization of the reader before being started.String
name()
Get the name of this reader.List<org.apache.kafka.connect.source.SourceRecord>
poll()
Poll for the next batch of source records.void
start()
Start the reader and return immediately.Reader.State
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(Runnable 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.
-
-
-
Method Detail
-
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
void uponCompletion(Runnable 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.This method should only be called while the reader is in the
Reader.State.STOPPED
state.- 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()
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
void start()
Start the reader and return immediately. Once started, theSourceRecord
s 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.STOPPING
state until all remaining records areconsumed
, at which point its state transitions toReader.State.STOPPED
.
-
poll
List<org.apache.kafka.connect.source.SourceRecord> poll() throws InterruptedException
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
.- 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 recordsorg.apache.kafka.connect.errors.ConnectException
- if there is an error while this reader is running
-
-