E - The rich element type that contains information for split state update or timestamp
extraction.T - The final element type to emit.SplitT - the immutable split type.SplitStateT - the mutable type of split state.@PublicEvolving public abstract class SourceReaderBase<E,T,SplitT extends org.apache.flink.api.connector.source.SourceSplit,SplitStateT> extends Object implements org.apache.flink.api.connector.source.SourceReader<T,SplitT>
SourceReader which provides some synchronization between
the mail box main thread and the SourceReader internal threads. This class allows user to just
provide a SplitReader and snapshot the split state.
This implementation provides the following metrics out of the box:
OperatorIOMetricGroup.getNumRecordsInCounter()
| Modifier and Type | Field and Description |
|---|---|
protected org.apache.flink.configuration.Configuration |
config
The raw configurations that may be used by subclasses.
|
protected org.apache.flink.api.connector.source.SourceReaderContext |
context
The context of this source reader.
|
protected RecordEvaluator<T> |
eofRecordEvaluator |
protected SourceReaderOptions |
options
The configuration for the reader.
|
protected RecordEmitter<E,T,SplitStateT> |
recordEmitter
The record emitter to handle the records read by the SplitReaders.
|
protected SplitFetcherManager<E,SplitT> |
splitFetcherManager
The split fetcher manager to run split fetchers.
|
| Constructor and Description |
|---|
SourceReaderBase(FutureCompletingBlockingQueue<RecordsWithSplitIds<E>> elementsQueue,
SplitFetcherManager<E,SplitT> splitFetcherManager,
RecordEmitter<E,T,SplitStateT> recordEmitter,
org.apache.flink.configuration.Configuration config,
org.apache.flink.api.connector.source.SourceReaderContext context)
Deprecated.
|
SourceReaderBase(FutureCompletingBlockingQueue<RecordsWithSplitIds<E>> elementsQueue,
SplitFetcherManager<E,SplitT> splitFetcherManager,
RecordEmitter<E,T,SplitStateT> recordEmitter,
RecordEvaluator<T> eofRecordEvaluator,
org.apache.flink.configuration.Configuration config,
org.apache.flink.api.connector.source.SourceReaderContext context)
Deprecated.
|
SourceReaderBase(SplitFetcherManager<E,SplitT> splitFetcherManager,
RecordEmitter<E,T,SplitStateT> recordEmitter,
org.apache.flink.configuration.Configuration config,
org.apache.flink.api.connector.source.SourceReaderContext context)
The primary constructor for the source reader.
|
SourceReaderBase(SplitFetcherManager<E,SplitT> splitFetcherManager,
RecordEmitter<E,T,SplitStateT> recordEmitter,
RecordEvaluator<T> eofRecordEvaluator,
org.apache.flink.configuration.Configuration config,
org.apache.flink.api.connector.source.SourceReaderContext context) |
| Modifier and Type | Method and Description |
|---|---|
void |
addSplits(List<SplitT> splits) |
void |
close() |
int |
getNumberOfCurrentlyAssignedSplits()
Gets the number of splits the reads has currently assigned.
|
void |
handleSourceEvents(org.apache.flink.api.connector.source.SourceEvent sourceEvent) |
protected abstract SplitStateT |
initializedState(SplitT split)
When new splits are added to the reader.
|
CompletableFuture<Void> |
isAvailable() |
void |
notifyNoMoreSplits() |
protected abstract void |
onSplitFinished(Map<String,SplitStateT> finishedSplitIds)
Handles the finished splits to clean the state if needed.
|
void |
pauseOrResumeSplits(Collection<String> splitsToPause,
Collection<String> splitsToResume) |
org.apache.flink.core.io.InputStatus |
pollNext(org.apache.flink.api.connector.source.ReaderOutput<T> output) |
List<SplitT> |
snapshotState(long checkpointId) |
void |
start() |
protected abstract SplitT |
toSplitType(String splitId,
SplitStateT splitState)
Convert a mutable SplitStateT to immutable SplitT.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitprotected final RecordEmitter<E,T,SplitStateT> recordEmitter
protected final SplitFetcherManager<E,SplitT extends org.apache.flink.api.connector.source.SourceSplit> splitFetcherManager
protected final SourceReaderOptions options
protected final org.apache.flink.configuration.Configuration config
protected org.apache.flink.api.connector.source.SourceReaderContext context
@Nullable protected final RecordEvaluator<T> eofRecordEvaluator
@Deprecated public SourceReaderBase(FutureCompletingBlockingQueue<RecordsWithSplitIds<E>> elementsQueue, SplitFetcherManager<E,SplitT> splitFetcherManager, RecordEmitter<E,T,SplitStateT> recordEmitter, org.apache.flink.configuration.Configuration config, org.apache.flink.api.connector.source.SourceReaderContext context)
SourceReaderBase(SplitFetcherManager, RecordEmitter,
Configuration, SourceReaderContext) instead.@Deprecated public SourceReaderBase(FutureCompletingBlockingQueue<RecordsWithSplitIds<E>> elementsQueue, SplitFetcherManager<E,SplitT> splitFetcherManager, RecordEmitter<E,T,SplitStateT> recordEmitter, @Nullable RecordEvaluator<T> eofRecordEvaluator, org.apache.flink.configuration.Configuration config, org.apache.flink.api.connector.source.SourceReaderContext context)
SourceReaderBase(SplitFetcherManager, RecordEmitter,
RecordEvaluator, Configuration, SourceReaderContext) instead.public SourceReaderBase(SplitFetcherManager<E,SplitT> splitFetcherManager, RecordEmitter<E,T,SplitStateT> recordEmitter, org.apache.flink.configuration.Configuration config, org.apache.flink.api.connector.source.SourceReaderContext context)
The reader will use a handover queue sized as configured via SourceReaderOptions.ELEMENT_QUEUE_CAPACITY.
public SourceReaderBase(SplitFetcherManager<E,SplitT> splitFetcherManager, RecordEmitter<E,T,SplitStateT> recordEmitter, @Nullable RecordEvaluator<T> eofRecordEvaluator, org.apache.flink.configuration.Configuration config, org.apache.flink.api.connector.source.SourceReaderContext context)
public void start()
public org.apache.flink.core.io.InputStatus pollNext(org.apache.flink.api.connector.source.ReaderOutput<T> output) throws Exception
public CompletableFuture<Void> isAvailable()
public void notifyNoMoreSplits()
public void handleSourceEvents(org.apache.flink.api.connector.source.SourceEvent sourceEvent)
public void pauseOrResumeSplits(Collection<String> splitsToPause, Collection<String> splitsToResume)
public void close()
throws Exception
close in interface AutoCloseableExceptionpublic int getNumberOfCurrentlyAssignedSplits()
These are the splits that have been added via addSplits(List) and have not yet
been finished by returning them from the SplitReader.fetch() as part of RecordsWithSplitIds.finishedSplits().
protected abstract void onSplitFinished(Map<String,SplitStateT> finishedSplitIds)
protected abstract SplitStateT initializedState(SplitT split)
split - a newly added split.protected abstract SplitT toSplitType(String splitId, SplitStateT splitState)
splitState - splitState.Copyright © 2014–2025 The Apache Software Foundation. All rights reserved.