Class BlockingReader
- java.lang.Object
-
- io.debezium.connector.mysql.legacy.BlockingReader
-
- All Implemented Interfaces:
Reader
- Direct Known Subclasses:
TimedBlockingReader
public class BlockingReader extends Object implements Reader
A component that blocks doing nothing until the connector task is stopped- Author:
- Peter Goransson
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.debezium.connector.mysql.legacy.Reader
Reader.State
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Logger
logger
private Metronome
metronome
private String
name
private String
runningLogMessage
private AtomicReference<Reader.State>
state
private AtomicReference<Runnable>
uponCompletion
-
Constructor Summary
Constructors Constructor Description BlockingReader(String name, String runningLogMessage)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
name()
Get the name of this reader.List<org.apache.kafka.connect.source.SourceRecord>
poll()
Does nothing until the connector task is shut down, but regularly returns control back to Connect in order for being paused if requested.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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.debezium.connector.mysql.legacy.Reader
destroy, initialize
-
-
-
-
Field Detail
-
logger
protected final org.slf4j.Logger logger
-
uponCompletion
private final AtomicReference<Runnable> uponCompletion
-
state
private final AtomicReference<Reader.State> state
-
metronome
private final Metronome metronome
-
name
private final String name
-
runningLogMessage
private final String runningLogMessage
-
-
Method Detail
-
poll
public List<org.apache.kafka.connect.source.SourceRecord> poll() throws InterruptedException
Does nothing until the connector task is shut down, but regularly returns control back to Connect in order for being paused if requested.- 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
-
state
public Reader.State state()
Description copied from interface:Reader
Get the current state of this reader.
-
uponCompletion
public void uponCompletion(Runnable handler)
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
-
start
public void 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
.
-
-