Class SourceReaderBase<E,T,SplitT extends org.apache.flink.api.connector.source.SourceSplit,SplitStateT>
java.lang.Object
org.apache.flink.connector.base.source.reader.SourceReaderBase<E,T,SplitT,SplitStateT>
- Type Parameters:
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.
- All Implemented Interfaces:
AutoCloseable,org.apache.flink.api.common.state.CheckpointListener,org.apache.flink.api.connector.source.SourceReader<T,SplitT>
- Direct Known Subclasses:
SingleThreadMultiplexSourceReaderBase
@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>
An abstract implementation of
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()
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.flink.configuration.ConfigurationThe raw configurations that may be used by subclasses.protected org.apache.flink.api.connector.source.SourceReaderContextThe context of this source reader.protected final RecordEvaluator<T>protected final SourceReaderOptionsThe configuration for the reader.protected final RecordEmitter<E,T, SplitStateT> The record emitter to handle the records read by the SplitReaders.protected final SplitFetcherManager<E,SplitT> The split fetcher manager to run split fetchers. -
Constructor Summary
ConstructorsConstructorDescriptionSourceReaderBase(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) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclose()intGets the number of splits the reads has currently assigned.voidhandleSourceEvents(org.apache.flink.api.connector.source.SourceEvent sourceEvent) protected abstract SplitStateTinitializedState(SplitT split) When new splits are added to the reader.voidprotected abstract voidonSplitFinished(Map<String, SplitStateT> finishedSplitIds) Handles the finished splits to clean the state if needed.voidpauseOrResumeSplits(Collection<String> splitsToPause, Collection<String> splitsToResume) org.apache.flink.core.io.InputStatussnapshotState(long checkpointId) voidstart()protected abstract SplitTtoSplitType(String splitId, SplitStateT splitState) Convert a mutable SplitStateT to immutable SplitT.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.flink.api.common.state.CheckpointListener
notifyCheckpointAbortedMethods inherited from interface org.apache.flink.api.connector.source.SourceReader
notifyCheckpointComplete
-
Field Details
-
recordEmitter
The record emitter to handle the records read by the SplitReaders. -
splitFetcherManager
protected final SplitFetcherManager<E,SplitT extends org.apache.flink.api.connector.source.SourceSplit> splitFetcherManagerThe split fetcher manager to run split fetchers. -
options
The configuration for the reader. -
config
protected final org.apache.flink.configuration.Configuration configThe raw configurations that may be used by subclasses. -
context
protected org.apache.flink.api.connector.source.SourceReaderContext contextThe context of this source reader. -
eofRecordEvaluator
-
-
Constructor Details
-
SourceReaderBase
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 primary constructor for the source reader.The reader will use a handover queue sized as configured via
SourceReaderOptions.ELEMENT_QUEUE_CAPACITY. -
SourceReaderBase
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)
-
-
Method Details
-
start
public void start() -
pollNext
-
isAvailable
-
snapshotState
-
addSplits
-
notifyNoMoreSplits
public void notifyNoMoreSplits() -
handleSourceEvents
public void handleSourceEvents(org.apache.flink.api.connector.source.SourceEvent sourceEvent) -
pauseOrResumeSplits
public void pauseOrResumeSplits(Collection<String> splitsToPause, Collection<String> splitsToResume) -
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
getNumberOfCurrentlyAssignedSplits
public int getNumberOfCurrentlyAssignedSplits()Gets the number of splits the reads has currently assigned.These are the splits that have been added via
addSplits(List)and have not yet been finished by returning them from theSplitReader.fetch()as part ofRecordsWithSplitIds.finishedSplits(). -
onSplitFinished
Handles the finished splits to clean the state if needed. -
initializedState
When new splits are added to the reader. The initialize the state of the new splits.- Parameters:
split- a newly added split.
-
toSplitType
Convert a mutable SplitStateT to immutable SplitT.- Parameters:
splitState- splitState.- Returns:
- an immutable Split state.
-