Class IteratorSourceReaderBase<E,O,IterT extends Iterator<E>,SplitT extends IteratorSourceSplit<E,IterT>>
- java.lang.Object
-
- org.apache.flink.api.connector.source.lib.util.IteratorSourceReaderBase<E,O,IterT,SplitT>
-
- 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 andIteratorSourceSplit
type safe.SplitT
- The concrete type of theIteratorSourceSplit
that creates and converts the iterator that produces this reader's elements.
- All Implemented Interfaces:
AutoCloseable
,CheckpointListener
,SourceReader<O,SplitT>
- Direct Known Subclasses:
DoubleEmittingSourceReaderWithCheckpointsInBetween
,GeneratingIteratorSourceReader
,IteratorSourceReader
@Public public abstract class IteratorSourceReaderBase<E,O,IterT extends Iterator<E>,SplitT extends IteratorSourceSplit<E,IterT>> extends Object implements SourceReader<O,SplitT>
ASourceReader
that returns the values of an iterator, supplied via anIteratorSourceSplit
.The
IteratorSourceSplit
is also responsible for taking the current iterator and turning it back into a split for checkpointing.
-
-
Field Summary
Fields Modifier and Type Field Description protected CompletableFuture<Void>
availability
The availability future.protected SplitT
currentSplit
The split whose data we return.protected IterT
iterator
The iterator producing data.
-
Constructor Summary
Constructors Constructor Description IteratorSourceReaderBase(SourceReaderContext context)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addSplits(List<SplitT> splits)
Adds a list of splits for this reader to read.void
close()
protected abstract O
convert(E value)
protected void
finishSplit()
CompletableFuture<Void>
isAvailable()
Returns a future that signals that data is available from the reader.void
notifyNoMoreSplits()
This method is called when the reader is notified that it will not receive any further splits.InputStatus
pollNext(ReaderOutput<O> output)
Poll the next available record into theReaderOutput
.List<SplitT>
snapshotState(long checkpointId)
Checkpoint on the state of the source.void
start()
Start the reader.protected void
start(SourceReaderContext context)
protected InputStatus
tryMoveToNextSplit()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.flink.api.common.state.CheckpointListener
notifyCheckpointAborted
-
Methods inherited from interface org.apache.flink.api.connector.source.SourceReader
handleSourceEvents, notifyCheckpointComplete, pauseOrResumeSplits
-
-
-
-
Field Detail
-
availability
protected CompletableFuture<Void> availability
The availability future. This reader is available as soon as a split is assigned.
-
iterator
@Nullable protected IterT extends Iterator<E> iterator
The iterator producing data. Non-null after a split has been assigned. This field is null or non-null always together with thecurrentSplit
field.
-
currentSplit
@Nullable protected SplitT extends IteratorSourceSplit<E,IterT> currentSplit
The split whose data we return. Non-null after a split has been assigned. This field is null or non-null always together with theiterator
field.
-
-
Constructor Detail
-
IteratorSourceReaderBase
public IteratorSourceReaderBase(SourceReaderContext context)
-
-
Method Detail
-
start
public void start()
Description copied from interface:SourceReader
Start the reader.- Specified by:
start
in interfaceSourceReader<E,O>
-
start
protected void start(SourceReaderContext context)
-
pollNext
public InputStatus pollNext(ReaderOutput<O> output)
Description copied from interface:SourceReader
Poll the next available record into theReaderOutput
.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 interfaceSourceReader<E,O>
- Returns:
- The InputStatus of the SourceReader after the method invocation.
-
finishSplit
protected void finishSplit()
-
tryMoveToNextSplit
protected InputStatus tryMoveToNextSplit()
-
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 thanInputStatus.MORE_AVAILABLE
. After that, the runtime will again call this method to obtain the next future. Once that completes, it will again callSourceReader.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 interfaceSourceReader<E,O>
- Returns:
- a future that will be completed once there is a record available to poll.
-
addSplits
public void addSplits(List<SplitT> splits)
Description copied from interface:SourceReader
Adds a list of splits for this reader to read. This method is called when the enumerator assigns a split viaSplitEnumeratorContext.assignSplit(SourceSplit, int)
orSplitEnumeratorContext.assignSplits(SplitsAssignment)
.- Specified by:
addSplits
in interfaceSourceReader<E,O>
- Parameters:
splits
- The splits assigned by the split enumerator.
-
notifyNoMoreSplits
public void notifyNoMoreSplits()
Description copied from interface:SourceReader
This method is called when the reader is notified that it will not receive any further splits.It is triggered when the enumerator calls
SplitEnumeratorContext.signalNoMoreSplits(int)
with the reader's parallel subtask.- Specified by:
notifyNoMoreSplits
in interfaceSourceReader<E,O>
-
snapshotState
public List<SplitT> snapshotState(long checkpointId)
Description copied from interface:SourceReader
Checkpoint on the state of the source.- Specified by:
snapshotState
in interfaceSourceReader<E,O>
- Returns:
- the state of the source.
-
close
public void close() throws Exception
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
-