public abstract class BaseSourceTask
extends org.apache.kafka.connect.source.SourceTask
SourceTask implementations. Provides functionality common to all connectors,
such as validation of the configuration.| Modifier and Type | Class and Description |
|---|---|
protected static class |
BaseSourceTask.State |
| Modifier and Type | Field and Description |
|---|---|
private ChangeEventSourceCoordinator |
coordinator
The change event source coordinator for those connectors adhering to the new
framework structure,
null for legacy-style connectors. |
private Map<String,?> |
lastOffset
The latest offset that has been acknowledged by the Kafka producer.
|
private static org.slf4j.Logger |
LOGGER |
private Map<String,String> |
props
Raw connector properties, kept here so they can be passed again in case of a restart.
|
private ElapsedTimeStrategy |
restartDelay |
private Duration |
retriableRestartWait |
private AtomicReference<BaseSourceTask.State> |
state |
private ReentrantLock |
stateLock
Used to ensure that start(), stop() and commitRecord() calls are serialized.
|
| Constructor and Description |
|---|
BaseSourceTask() |
| Modifier and Type | Method and Description |
|---|---|
void |
commit() |
void |
commitRecord(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 void |
doStop() |
protected abstract Iterable<Field> |
getAllConfigurationFields()
Returns all configuration
Field supported by this source task. |
protected OffsetContext |
getPreviousOffset(OffsetContext.Loader loader)
Loads the connector's persistent offset (if present) via the given loader.
|
List<org.apache.kafka.connect.source.SourceRecord> |
poll() |
protected abstract ChangeEventSourceCoordinator |
start(Configuration config)
Called once when starting this source task.
|
void |
start(Map<String,String> props) |
private boolean |
startIfNeededAndPossible()
Starts this connector in case it has been stopped after a retriable error,
and the backoff period has passed.
|
void |
stop() |
private void |
stop(boolean restart) |
private static final org.slf4j.Logger LOGGER
private final AtomicReference<BaseSourceTask.State> state
private final ReentrantLock stateLock
private volatile ElapsedTimeStrategy restartDelay
private volatile Map<String,String> props
private ChangeEventSourceCoordinator coordinator
null for legacy-style connectors.private volatile Map<String,?> lastOffset
commit()
(which may be a no-op depending on the connector).private Duration retriableRestartWait
public final void start(Map<String,String> props)
start in interface org.apache.kafka.connect.connector.Taskstart in class org.apache.kafka.connect.source.SourceTaskprotected abstract ChangeEventSourceCoordinator start(Configuration config)
config - the task configuration; implementations should wrap it in a dedicated implementation of
CommonConnectorConfig and work with typed access to configuration properties that waypublic final List<org.apache.kafka.connect.source.SourceRecord> poll() throws InterruptedException
poll in class org.apache.kafka.connect.source.SourceTaskInterruptedExceptionprotected abstract List<org.apache.kafka.connect.source.SourceRecord> doPoll() throws InterruptedException
InterruptedExceptionprivate boolean startIfNeededAndPossible()
public final void stop()
stop in interface org.apache.kafka.connect.connector.Taskstop in class org.apache.kafka.connect.source.SourceTaskprivate void stop(boolean restart)
protected abstract void doStop()
public void commitRecord(org.apache.kafka.connect.source.SourceRecord record)
throws InterruptedException
commitRecord in class org.apache.kafka.connect.source.SourceTaskInterruptedExceptionpublic void commit()
throws InterruptedException
commit in class org.apache.kafka.connect.source.SourceTaskInterruptedExceptionprotected abstract Iterable<Field> getAllConfigurationFields()
Field supported by this source task.protected OffsetContext getPreviousOffset(OffsetContext.Loader loader)
Copyright © 2021 JBoss by Red Hat. All rights reserved.