Package io.debezium.connector.common
Class BaseSourceTask<P extends Partition,O extends OffsetContext>
- java.lang.Object
-
- org.apache.kafka.connect.source.SourceTask
-
- io.debezium.connector.common.BaseSourceTask<P,O>
-
- All Implemented Interfaces:
org.apache.kafka.connect.connector.Task
public abstract class BaseSourceTask<P extends Partition,O extends OffsetContext> extends org.apache.kafka.connect.source.SourceTaskBase class for Debezium's CDCSourceTaskimplementations. Provides functionality common to all connectors, such as validation of the configuration.- Author:
- Gunnar Morling
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classBaseSourceTask.State
-
Field Summary
Fields Modifier and Type Field Description private Clockclockprivate ChangeEventSourceCoordinator<P,O>coordinatorThe change event source coordinator for those connectors adhering to the new framework structure,nullfor legacy-style connectors.private static longINITIAL_POLL_PERIOD_IN_MILLISprivate Map<String,?>lastOffsetThe latest offset that has been acknowledged by the Kafka producer.private static org.slf4j.LoggerLOGGERprivate static longMAX_POLL_PERIOD_IN_MILLISprivate ElapsedTimeStrategypollOutputDelayprivate InstantpreviousOutputInstantprivate Map<String,String>propsRaw connector properties, kept here so they can be passed again in case of a restart.private ElapsedTimeStrategyrestartDelayprivate DurationretriableRestartWaitprivate AtomicReference<BaseSourceTask.State>stateprivate ReentrantLockstateLockUsed to ensure that start(), stop() and commitRecord() calls are serialized.
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseSourceTask()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcommit()voidcommitRecord(org.apache.kafka.connect.source.SourceRecord record)protected abstract List<org.apache.kafka.connect.source.SourceRecord>doPoll()Returns the next batch of source records, if any are available.protected abstract voiddoStop()protected abstract Iterable<Field>getAllConfigurationFields()Returns all configurationFieldsupported by this source task.protected Offsets<P,O>getPreviousOffsets(Partition.Provider<P> provider, OffsetContext.Loader<O> loader)Loads the connector's persistent offsets (if present) via the given loader.(package private) voidlogStatistics(List<org.apache.kafka.connect.source.SourceRecord> records)List<org.apache.kafka.connect.source.SourceRecord>poll()protected abstract ChangeEventSourceCoordinator<P,O>start(Configuration config)Called once when starting this source task.voidstart(Map<String,String> props)private booleanstartIfNeededAndPossible()Starts this connector in case it has been stopped after a retriable error, and the backoff period has passed.voidstop()private voidstop(boolean restart)
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
INITIAL_POLL_PERIOD_IN_MILLIS
private static final long INITIAL_POLL_PERIOD_IN_MILLIS
-
MAX_POLL_PERIOD_IN_MILLIS
private static final long MAX_POLL_PERIOD_IN_MILLIS
-
state
private final AtomicReference<BaseSourceTask.State> state
-
stateLock
private final ReentrantLock stateLock
Used to ensure that start(), stop() and commitRecord() calls are serialized.
-
restartDelay
private volatile ElapsedTimeStrategy restartDelay
-
props
private volatile Map<String,String> props
Raw connector properties, kept here so they can be passed again in case of a restart.
-
coordinator
private ChangeEventSourceCoordinator<P extends Partition,O extends OffsetContext> coordinator
The change event source coordinator for those connectors adhering to the new framework structure,nullfor legacy-style connectors.
-
lastOffset
private volatile Map<String,?> lastOffset
The latest offset that has been acknowledged by the Kafka producer. Will be acknowledged with the source database incommit()(which may be a no-op depending on the connector).
-
retriableRestartWait
private Duration retriableRestartWait
-
pollOutputDelay
private final ElapsedTimeStrategy pollOutputDelay
-
clock
private final Clock clock
-
previousOutputInstant
private Instant previousOutputInstant
-
-
Method Detail
-
start
public final void start(Map<String,String> props)
- Specified by:
startin interfaceorg.apache.kafka.connect.connector.Task- Specified by:
startin classorg.apache.kafka.connect.source.SourceTask
-
start
protected abstract ChangeEventSourceCoordinator<P,O> start(Configuration config)
Called once when starting this source task.- Parameters:
config- the task configuration; implementations should wrap it in a dedicated implementation ofCommonConnectorConfigand work with typed access to configuration properties that way
-
poll
public final List<org.apache.kafka.connect.source.SourceRecord> poll() throws InterruptedException
- Specified by:
pollin classorg.apache.kafka.connect.source.SourceTask- Throws:
InterruptedException
-
logStatistics
void logStatistics(List<org.apache.kafka.connect.source.SourceRecord> records)
-
doPoll
protected abstract List<org.apache.kafka.connect.source.SourceRecord> doPoll() throws InterruptedException
Returns the next batch of source records, if any are available.- Throws:
InterruptedException
-
startIfNeededAndPossible
private boolean startIfNeededAndPossible()
Starts this connector in case it has been stopped after a retriable error, and the backoff period has passed.
-
stop
public final void stop()
- Specified by:
stopin interfaceorg.apache.kafka.connect.connector.Task- Specified by:
stopin classorg.apache.kafka.connect.source.SourceTask
-
stop
private void stop(boolean restart)
-
doStop
protected abstract void doStop()
-
commitRecord
public void commitRecord(org.apache.kafka.connect.source.SourceRecord record) throws InterruptedException- Overrides:
commitRecordin classorg.apache.kafka.connect.source.SourceTask- Throws:
InterruptedException
-
commit
public void commit() throws InterruptedException- Overrides:
commitin classorg.apache.kafka.connect.source.SourceTask- Throws:
InterruptedException
-
getAllConfigurationFields
protected abstract Iterable<Field> getAllConfigurationFields()
Returns all configurationFieldsupported by this source task.
-
getPreviousOffsets
protected Offsets<P,O> getPreviousOffsets(Partition.Provider<P> provider, OffsetContext.Loader<O> loader)
Loads the connector's persistent offsets (if present) via the given loader.
-
-