Class SourceReaderBase<E,​T,​SplitT extends SourceSplit,​SplitStateT>

    • Method Detail

      • pollNext

        public InputStatus pollNext​(ReaderOutput<T> output)
                             throws Exception
        Description copied from interface: SourceReader
        Poll the next available record into the ReaderOutput.

        The implementation must make sure this method is non-blocking.

        Although the implementation can emit multiple records into the given ReaderOutput, it is recommended not doing so. Instead, emit one record into the ReaderOutput and return a InputStatus.MORE_AVAILABLE to let the caller thread know there are more records available.

        Specified by:
        pollNext in interface SourceReader<E,​T>
        Returns:
        The InputStatus of the SourceReader after the method invocation.
        Throws:
        Exception
      • isAvailable

        public CompletableFuture<Void> isAvailable()
        Description copied from interface: SourceReader
        Returns a future that signals that data is available from the reader.

        Once the future completes, the runtime will keep calling the SourceReader.pollNext(ReaderOutput) method until that method returns a status other than InputStatus.MORE_AVAILABLE. After that, the runtime will again call this method to obtain the next future. Once that completes, it will again call SourceReader.pollNext(ReaderOutput) and so on.

        The contract is the following: If the reader has data available, then all futures previously returned by this method must eventually complete. Otherwise the source might stall indefinitely.

        It is not a problem to have occasional "false positives", meaning to complete a future even if no data is available. However, one should not use an "always complete" future in cases no data is available, because that will result in busy waiting loops calling pollNext(...) even though no data is available.

        Specified by:
        isAvailable in interface SourceReader<E,​T>
        Returns:
        a future that will be completed once there is a record available to poll.
      • snapshotState

        public List<SplitT> snapshotState​(long checkpointId)
        Description copied from interface: SourceReader
        Checkpoint on the state of the source.
        Specified by:
        snapshotState in interface SourceReader<E,​T>
        Returns:
        the state of the source.
      • pauseOrResumeSplits

        public void pauseOrResumeSplits​(Collection<String> splitsToPause,
                                        Collection<String> splitsToResume)
        Description copied from interface: SourceReader
        Pauses or resumes reading of individual source splits.

        Note that no other methods can be called in parallel, so updating subscriptions can be done atomically. This method is simply providing connectors with more expressive APIs the opportunity to update all subscriptions at once.

        This is currently used to align the watermarks of splits, if watermark alignment is used and the source reads from more than one split.

        The default implementation throws an UnsupportedOperationException where the default implementation will be removed in future releases. To be compatible with future releases, it is recommended to implement this method and override the default implementation.

        Specified by:
        pauseOrResumeSplits in interface SourceReader<E,​T>
        Parameters:
        splitsToPause - the splits to pause
        splitsToResume - the splits to resume
      • 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.