Class AbstractSourceTask
java.lang.Object
org.apache.kafka.connect.source.SourceTask
io.aiven.commons.kafka.connector.source.AbstractSourceTask
- All Implemented Interfaces:
org.apache.kafka.connect.connector.Task
public abstract class AbstractSourceTask
extends org.apache.kafka.connect.source.SourceTask
This class handles extracting records from an iterator and returning them to Kafka. It uses an
exponential backoff with jitter to reduce the number of calls to the backend when there is no
data. This solution:
- When polled this implementation moves available records from the SourceRecord iterator to the return array.
- if there are no records
poll()will return null.- The poll will delay no more than approx 5 seconds.
- Upto
maxPollRecordswill be sent in a single poll request - When the connector is stopped any collected records are returned to kafka before stopping.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.kafka.connect.source.SourceTask
org.apache.kafka.connect.source.SourceTask.TransactionBoundary -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationThe maximum time to spend polling.static final List<org.apache.kafka.connect.source.SourceRecord>Anulllist representing no values in the polling functionality.Fields inherited from class org.apache.kafka.connect.source.SourceTask
context, TRANSACTION_BOUNDARY_CONFIG -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidClose any resources the source has open.protected abstract SourceCommonConfigconfigure(Map<String, String> props, OffsetManager offsetManager) Called bystart(java.util.Map<java.lang.String, java.lang.String>)to allows the concrete implementation to configure itself based on properties.protected abstract EvolvingSourceRecordIteratorgetIterator(SourceCommonConfig config) Gets the iterator of SourceRecords.final booleanReturns the running state of the task.protected EvolvingSourceRecordlastEvolution(EvolvingSourceRecord evolvingSourceRecord) An insertion point for the last evolution step in the EvolvingSourceRecord.final List<org.apache.kafka.connect.source.SourceRecord>poll()final voidprotected final booleanReturnstrueif the connector is not stopped and the timer has not expired.final voidstop()Methods inherited from class org.apache.kafka.connect.source.SourceTask
commit, commitRecord, 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
-
NULL_RESULT
Anulllist representing no values in the polling functionality. -
MAX_POLL_TIME
The maximum time to spend polling. This is set to 4 seconds as 5 seconds is the kafka limit that is allotted to a system for shutdown, and this allows the polling and iterator to smoothly shutdown accounting for latency.
-
-
Constructor Details
-
AbstractSourceTask
protected AbstractSourceTask()Constructor.
-
-
Method Details
-
getIterator
Gets the iterator of SourceRecords. The iterator that SourceRecords are extracted from for a poll event. When this iterator runs out of records it should attempt to reset and read more records from the backend on the nexthasNext()call. In this way it should detect when new data has been added to the backend and continue processing.This method should handle any backend exception that can be retried. Any runtime exceptions that are thrown when this iterator executes may cause the task to abort.
- Parameters:
config- the SourceCommonConfig instance.- Returns:
- The iterator of SourceRecords.
-
configure
protected abstract SourceCommonConfig configure(Map<String, String> props, OffsetManager offsetManager) Called bystart(java.util.Map<java.lang.String, java.lang.String>)to allows the concrete implementation to configure itself based on properties.- Parameters:
props- The properties to use for configuration.offsetManager- the OffsetManager to use.- Returns:
- A SourceCommonConfig based configuration.
-
start
- Specified by:
startin interfaceorg.apache.kafka.connect.connector.Task- Specified by:
startin classorg.apache.kafka.connect.source.SourceTask
-
lastEvolution
An insertion point for the last evolution step in the EvolvingSourceRecord. This method is called just before the EvolvingSourceRecord is converted into a SourceRecord. This is the last point to modify- Key schema and/or value
- Value schema and/or value
- Offset manager entry
- Parameters:
evolvingSourceRecord- the record to modify.- Returns:
- the modified record.
-
stillPolling
protected final boolean stillPolling()Returnstrueif the connector is not stopped and the timer has not expired.- Returns:
trueif the connector is not stopped and the timer has not expired.
-
poll
- Specified by:
pollin classorg.apache.kafka.connect.source.SourceTask
-
stop
public final void stop()- Specified by:
stopin interfaceorg.apache.kafka.connect.connector.Task- Specified by:
stopin classorg.apache.kafka.connect.source.SourceTask
-
isRunning
public final boolean isRunning()Returns the running state of the task.- Returns:
trueif the connector is running,falseotherwise.
-
closeResources
protected abstract void closeResources()Close any resources the source has open. Called when stopping.
-