public abstract class AbstractReader extends Object implements Reader
MySqlSchema.Reader.State| Modifier and Type | Field and Description |
|---|---|
protected MySqlTaskContext |
context |
private AtomicReference<org.apache.kafka.connect.errors.ConnectException> |
failure |
private org.apache.kafka.connect.errors.ConnectException |
failureException |
protected org.slf4j.Logger |
logger |
private int |
maxBatchSize |
private Metronome |
metronome |
private String |
name |
private BlockingQueue<org.apache.kafka.connect.source.SourceRecord> |
records |
private AtomicBoolean |
running |
private AtomicBoolean |
success |
private AtomicReference<Runnable> |
uponCompletion |
| Constructor and Description |
|---|
AbstractReader(String name,
MySqlTaskContext context)
Create a snapshot reader.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
cleanupResources()
|
protected void |
completeSuccessfully()
Call this method only when the reader has successfully completed all of its work, signaling that subsequent
calls to
poll() should forever return null and that this reader should transition from
Reader.State.STOPPING to Reader.State.STOPPED. |
protected abstract void |
doCleanup()
The reader has completed all processing and all
enqueued records have been
consumed, so this reader should clean up any resources that might remain. |
protected void |
doInitialize()
The reader has been requested to initialize resources prior to starting.
|
protected abstract void |
doStart()
The reader has been requested to start, so initialize any un-initialized resources required
by the reader.
|
protected abstract void |
doStop()
The reader has been requested to stop, so perform any work required to stop the reader's resources that were previously
started. |
protected void |
enqueueRecord(org.apache.kafka.connect.source.SourceRecord record)
Enqueue a record so that it can be obtained when this reader is
polled. |
protected void |
failed(Throwable error)
Call this method only when the reader has failed, that a subsequent call to
poll() should throw
this error, and that doCleanup() can be called at any time. |
protected void |
failed(Throwable error,
String msg)
Call this method only when the reader has failed, that a subsequent call to
poll() should throw
this error, and that doCleanup() can be called at any time. |
void |
initialize()
Perform any initialization of the reader before being started.
|
protected boolean |
isRunning() |
String |
name()
Get the name of this reader.
|
List<org.apache.kafka.connect.source.SourceRecord> |
poll()
Poll for the next batch of source records.
|
protected void |
pollComplete(List<org.apache.kafka.connect.source.SourceRecord> batch)
Method called when
poll() completes sending a non-zero-sized batch of 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 the
Reader.State.STOPPING state until all remaining records
are consumed, at which point its state transitions to Reader.State.STOPPED. |
void |
uponCompletion(Runnable handler)
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. |
protected org.apache.kafka.connect.errors.ConnectException |
wrap(Throwable error)
Wraps the specified exception in a
ConnectException, ensuring that all useful state is captured inside
the new exception's message. |
protected final org.slf4j.Logger logger
private final String name
protected final MySqlTaskContext context
private final BlockingQueue<org.apache.kafka.connect.source.SourceRecord> records
private final AtomicBoolean running
private final AtomicBoolean success
private final AtomicReference<org.apache.kafka.connect.errors.ConnectException> failure
private org.apache.kafka.connect.errors.ConnectException failureException
private final int maxBatchSize
private final Metronome metronome
private final AtomicReference<Runnable> uponCompletion
public AbstractReader(String name, MySqlTaskContext context)
name - the name of the readercontext - the task context in which this reader is running; may not be nullpublic void uponCompletion(Runnable handler)
ReaderReader.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.
uponCompletion in interface Readerhandler - the function; may not be nullpublic final void initialize()
ReaderReader.start() is called, and it should block until all
initialization is completed.initialize in interface Readerpublic void start()
ReaderSourceRecords 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.
public void stop()
ReaderReader.State.STOPPING state until all remaining records
are consumed, at which point its state transitions to Reader.State.STOPPED.protected void doInitialize()
doStart().protected abstract void doStart()
protected abstract void doStop()
started.
This method is always called when stop() is called, and the first time isRunning() will return
true the first time and false for any subsequent calls.
protected abstract void doCleanup()
enqueued records have been
consumed, so this reader should clean up any resources that might remain.protected void completeSuccessfully()
poll() should forever return null and that this reader should transition from
Reader.State.STOPPING to Reader.State.STOPPED.protected void failed(Throwable error)
poll() should throw
this error, and that doCleanup() can be called at any time.error - the error that resulted in the failure; should not be nullprotected void failed(Throwable error, String msg)
poll() should throw
this error, and that doCleanup() can be called at any time.error - the error that resulted in the failure; should not be nullmsg - the error message; may not be nullprotected org.apache.kafka.connect.errors.ConnectException wrap(Throwable error)
ConnectException, ensuring that all useful state is captured inside
the new exception's message.error - the exception; may not be nullpublic Reader.State state()
Readerprotected boolean isRunning()
public List<org.apache.kafka.connect.source.SourceRecord> poll() throws InterruptedException
Readernull 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.poll in interface Readernull when there will be no more records
because the reader has completely Reader.State.STOPPED.InterruptedException - if this thread is interrupted while waiting for more recordsprotected void cleanupResources()
poll() when there this reader finishes normally and all generated
records are consumed prior to being stopped. However, if this reader is explicitly
stopped while still working, then subclasses should call this method when they have completed
all of their shutdown work.protected void pollComplete(List<org.apache.kafka.connect.source.SourceRecord> batch)
poll() completes sending a non-zero-sized batch of records.batch - the batch of records being recordedprotected void enqueueRecord(org.apache.kafka.connect.source.SourceRecord record)
throws InterruptedException
polled. This method will block if the
queue is full.record - the record to be enqueuedInterruptedException - if interrupted while waiting for the queue to have room for this recordCopyright © 2018 JBoss by Red Hat. All rights reserved.