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.SourceTask
Base class for Debezium's CDC
SourceTask implementations. Provides functionality common to all connectors,
such as validation of the configuration.- Author:
- Gunnar Morling
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.kafka.connect.source.SourceTask
org.apache.kafka.connect.source.SourceTask.TransactionBoundary -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Clockprivate ChangeEventSourceCoordinator<P,O> The change event source coordinator for those connectors adhering to the new framework structure,nullfor legacy-style connectors.private static final DurationThe latest offsets that have been acknowledged by the Kafka producer.private static final org.slf4j.Loggerprivate static final Durationprivate final ElapsedTimeStrategyprivate intprivate InstantRaw connector properties, kept here so they can be passed again in case of a restart.private ElapsedTimeStrategyprivate Durationprivate final AtomicReference<BaseSourceTask.State>private final ReentrantLockUsed to ensure that start(), stop() and commitRecord() calls are serialized.Fields inherited from class org.apache.kafka.connect.source.SourceTask
context, TRANSACTION_BOUNDARY_CONFIG -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcommit()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()Returns all configurationFieldsupported by this source task.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) final List<org.apache.kafka.connect.source.SourceRecord>poll()protected abstract ChangeEventSourceCoordinator<P,O> start(Configuration config) Called once when starting this source task.final voidprivate booleanStarts this connector in case it has been stopped after a retriable error, and the backoff period has passed.final voidstop()private voidstop(boolean restart) private voidupdateLastOffset(Map<String, ?> partition, Map<String, ?> lastOffset) Methods inherited from class org.apache.kafka.connect.source.SourceTask
commitRecord, initializeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.kafka.connect.connector.Task
version
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
INITIAL_POLL_PERIOD_IN_MILLIS
-
MAX_POLL_PERIOD_IN_MILLIS
-
state
-
stateLock
Used to ensure that start(), stop() and commitRecord() calls are serialized. -
restartDelay
-
props
Raw connector properties, kept here so they can be passed again in case of a restart. -
coordinator
The change event source coordinator for those connectors adhering to the new framework structure,nullfor legacy-style connectors. -
lastOffsets
The latest offsets that have 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
-
pollOutputDelay
-
clock
-
previousOutputInstant
-
previousOutputBatchSize
private int previousOutputBatchSize
-
-
Constructor Details
-
BaseSourceTask
protected BaseSourceTask()
-
-
Method Details
-
start
- Specified by:
startin interfaceorg.apache.kafka.connect.connector.Task- Specified by:
startin classorg.apache.kafka.connect.source.SourceTask
-
start
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
- Specified by:
pollin classorg.apache.kafka.connect.source.SourceTask- Throws:
InterruptedException
-
logStatistics
-
updateLastOffset
-
doPoll
protected abstract List<org.apache.kafka.connect.source.SourceRecord> doPoll() throws InterruptedExceptionReturns 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
- Overrides:
commitin classorg.apache.kafka.connect.source.SourceTask- Throws:
InterruptedException
-
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.
-