Class SourceReaderBase<E,​T,​SplitT extends org.apache.flink.api.connector.source.SourceSplit,​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 Detail

      • recordEmitter

        protected final RecordEmitter<E,​T,​SplitStateT> 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> splitFetcherManager
        The split fetcher manager to run split fetchers.
      • config

        protected final org.apache.flink.configuration.Configuration config
        The raw configurations that may be used by subclasses.
      • context

        protected org.apache.flink.api.connector.source.SourceReaderContext context
        The context of this source reader.
    • Method Detail

      • start

        public void start()
        Specified by:
        start in interface org.apache.flink.api.connector.source.SourceReader<E,​T>
      • pollNext

        public org.apache.flink.core.io.InputStatus pollNext​(org.apache.flink.api.connector.source.ReaderOutput<T> output)
                                                      throws Exception
        Specified by:
        pollNext in interface org.apache.flink.api.connector.source.SourceReader<E,​T>
        Throws:
        Exception
      • isAvailable

        public CompletableFuture<Void> isAvailable()
        Specified by:
        isAvailable in interface org.apache.flink.api.connector.source.SourceReader<E,​T>
      • snapshotState

        public List<SplitT> snapshotState​(long checkpointId)
        Specified by:
        snapshotState in interface org.apache.flink.api.connector.source.SourceReader<E,​T>
      • addSplits

        public void addSplits​(List<SplitT> splits)
        Specified by:
        addSplits in interface org.apache.flink.api.connector.source.SourceReader<E,​T>
      • notifyNoMoreSplits

        public void notifyNoMoreSplits()
        Specified by:
        notifyNoMoreSplits in interface org.apache.flink.api.connector.source.SourceReader<E,​T>
      • handleSourceEvents

        public void handleSourceEvents​(org.apache.flink.api.connector.source.SourceEvent sourceEvent)
        Specified by:
        handleSourceEvents in interface org.apache.flink.api.connector.source.SourceReader<E,​T>
      • pauseOrResumeSplits

        public void pauseOrResumeSplits​(Collection<String> splitsToPause,
                                        Collection<String> splitsToResume)
        Specified by:
        pauseOrResumeSplits in interface org.apache.flink.api.connector.source.SourceReader<E,​T>
      • onSplitFinished

        protected abstract void onSplitFinished​(Map<String,​SplitStateT> finishedSplitIds)
        Handles the finished splits to clean the state if needed.
      • initializedState

        protected abstract SplitStateT initializedState​(SplitT split)
        When new splits are added to the reader. The initialize the state of the new splits.
        Parameters:
        split - a newly added split.
      • toSplitType

        protected abstract SplitT toSplitType​(String splitId,
                                              SplitStateT splitState)
        Convert a mutable SplitStateT to immutable SplitT.
        Parameters:
        splitState - splitState.
        Returns:
        an immutable Split state.