public abstract class AbstractReader extends Object
MySqlSchema.| 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 BlockingQueue<org.apache.kafka.connect.source.SourceRecord> |
records |
private AtomicBoolean |
running |
private AtomicBoolean |
success |
| Constructor and Description |
|---|
AbstractReader(MySqlTaskContext context)
Create a snapshot reader.
|
| Modifier and Type | Method and Description |
|---|---|
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. |
protected abstract void |
doCleanup()
The reader has completed sending all
enqueued records, so clean up any resources
that remain. |
protected abstract void |
doStart()
The reader has been requested to start, so initialize any 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, and that a subsequent call to
poll() should throw this error. |
protected void |
failed(Throwable error,
String msg)
Call this method only when the reader has failed, and that a subsequent call to
poll() should throw this error. |
boolean |
isRunning()
Get whether the snapshot is still running and records are available.
|
List<org.apache.kafka.connect.source.SourceRecord> |
poll()
Poll for the next batch of source records.
|
void |
start()
Start the reader and return immediately.
|
void |
stop()
Stop the snapshot from running.
|
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
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
public AbstractReader(MySqlTaskContext context)
context - the task context in which this reader is running; may not be nullpublic void start()
SourceRecord can be obtained by periodically calling
poll() until that method returns null.
This method does nothing if it is already running.
public void stop()
This method does nothing if the snapshot is not running.
protected abstract void doStart()
protected abstract void doStop()
started..protected abstract void doCleanup()
enqueued records, so clean up any resources
that remain.protected void completeSuccessfully()
poll() should forever return null.protected void failed(Throwable error)
poll() should throw this error.error - the error that resulted in the failure; should not be nullprotected void failed(Throwable error, String msg)
poll() should throw this error.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 boolean isRunning()
true if still running, or false if no longer running and/or all records have been processedpublic List<org.apache.kafka.connect.source.SourceRecord> poll() throws InterruptedException
null when the snapshot is complete, all records have previously been
returned, and the completion function (supplied in the constructor) has been calledInterruptedException - if this thread is interrupted while waiting for more recordsorg.apache.kafka.connect.errors.ConnectException - if there is an error while this reader is runningprotected 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 © 2016 JBoss by Red Hat. All rights reserved.