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 ServiceLoader<SignalChannelReader>private final Clockprivate Configurationprotected 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 List<NotificationChannel>private final ElapsedTimeStrategyprivate intprivate Instantprivate 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.protected voidlogStatistics(List<org.apache.kafka.connect.source.SourceRecord> records) final List<org.apache.kafka.connect.source.SourceRecord>poll()protected voidregisterServiceProviders(ServiceRegistry serviceRegistry) private voidsetTaskState(BaseSourceTask.State newState) Sets the new state for the task.protected abstract ChangeEventSourceCoordinator<P,O> start(Configuration config) Called 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) protected ConfigurationMethods 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
-
config
-
state
-
stateLock
Used to ensure that start(), stop() and commitRecord() calls are serialized. -
restartDelay
-
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 -
availableSignalChannels
-
notificationChannels
-
-
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
-
getAvailableSignalChannels
-
withMaskedSensitiveOptions
-
start
Called when starting this source task. This method can throw aRetriableExceptionto indicate that the task should attempt to retry the start later.- 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
Starts this connector in case it has been stopped after a retriable error, and the backoff period has passed.- Throws:
InterruptedException
-
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. -
setTaskState
Sets the new state for the task. The caller must be holdingstateLocklock.- Parameters:
newState-
-
getTaskState
-
getNotificationChannels
-
registerServiceProviders
-