Class IteratorSourceReaderBase<E,​O,​IterT extends Iterator<E>,​SplitT extends IteratorSourceSplit<E,​IterT>>

  • Type Parameters:
    E - The type of events returned by the reader.
    IterT - The type of the iterator that produces the events. This type exists to make the conversion between iterator and IteratorSourceSplit type safe.
    SplitT - The concrete type of the IteratorSourceSplit that creates and converts the iterator that produces this reader's elements.
    All Implemented Interfaces:
    AutoCloseable, CheckpointListener, SourceReader<O,​SplitT>
    Direct Known Subclasses:
    IteratorSourceReader

    @Public
    public abstract class IteratorSourceReaderBase<E,​O,​IterT extends Iterator<E>,​SplitT extends IteratorSourceSplit<E,​IterT>>
    extends Object
    implements SourceReader<O,​SplitT>
    A SourceReader that returns the values of an iterator, supplied via an IteratorSourceSplit.

    The IteratorSourceSplit is also responsible for taking the current iterator and turning it back into a split for checkpointing.

    • Constructor Detail

    • Method Detail

      • pollNext

        public InputStatus pollNext​(ReaderOutput<O> output)
        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,​O>
        Returns:
        The InputStatus of the SourceReader after the method invocation.
      • convert

        protected abstract O convert​(E value)
      • 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,​O>
        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,​O>
        Returns:
        the state of the source.