@ThreadSafe public final class ChainedReader extends Object implements Reader
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.| Modifier and Type | Class and Description |
|---|---|
static class |
ChainedReader.Builder |
Reader.State| Modifier and Type | Field and Description |
|---|---|
private AtomicBoolean |
completed |
private String |
completionMessage |
private AtomicReference<Reader> |
currentReader |
private org.slf4j.Logger |
logger |
private List<Reader> |
readers |
private LinkedList<Reader> |
remainingReaders |
private AtomicBoolean |
running |
private AtomicReference<Runnable> |
uponCompletion |
| Modifier | Constructor and Description |
|---|---|
private |
ChainedReader(List<Reader> readers,
String completionMessage)
Create a new chained reader.
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
After the reader has stopped, there may still be some resources we want left available until the connector
task is destroyed.
|
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.
|
private void |
readerCompletedPolling()
Called when the previously-started reader has returned all of its records via
polling. |
void |
start()
Start the reader and return immediately.
|
private boolean |
startNextReader()
Start the next reader.
|
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. |
private final org.slf4j.Logger logger
private final String completionMessage
private final LinkedList<Reader> remainingReaders
private final AtomicBoolean running
private final AtomicBoolean completed
private final AtomicReference<Reader> currentReader
private final AtomicReference<Runnable> uponCompletion
public 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 void initialize()
ReaderReader.start() is called, and it should block until all
initialization is completed.initialize in interface Readerpublic void destroy()
ReaderReader.initialize(), performing any
de-initialization of the reader entity before shutdown. This method should be called exactly
once after Reader.stop() is called, and it should block until all de-initialization is completed.public 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.public Reader.State state()
Readerpublic 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 recordsprivate void readerCompletedPolling()
polling.
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.private boolean startNextReader()
true if the next reader was started, or false if there are no more readersCopyright © 2018 JBoss by Red Hat. All rights reserved.