Implementation:Apache Flink HybridSourceReader PollNext
| Knowledge Sources | |
|---|---|
| Domains | Stream_Processing, Source_Architecture |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
Concrete tool for delegating record polling to the current source reader and signaling source completion provided by the Apache Flink connector-base module.
Description
HybridSourceReader.pollNext delegates to the current underlying SourceReader.pollNext. When the current reader returns END_OF_INPUT and it is not the final source, the reader sends a SourceReaderFinishedEvent to the enumerator and returns NOTHING_AVAILABLE. For the final source, END_OF_INPUT propagates directly. When no reader is active (during switching), it returns NOTHING_AVAILABLE.
Usage
This is an internal method called by the Flink runtime during source execution.
Code Reference
Source Location
- Repository: Apache Flink
- File: flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/hybrid/HybridSourceReader.java
- Lines: L81-106
Signature
public class HybridSourceReader<T> implements SourceReader<T, HybridSourceSplit> {
@Override
public InputStatus pollNext(ReaderOutput output) throws Exception {
if (currentReader == null) {
return InputStatus.NOTHING_AVAILABLE;
}
InputStatus status = currentReader.pollNext(output);
if (status == InputStatus.END_OF_INPUT) {
if (!isFinalSource) {
// Signal completion to coordinator
readerContext.sendSourceEventToCoordinator(
new SourceReaderFinishedEvent(currentSourceIndex));
currentReader = null;
return InputStatus.NOTHING_AVAILABLE;
}
}
return status;
}
}
Import
import org.apache.flink.connector.base.source.hybrid.HybridSourceReader;
// Internal class
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| output | ReaderOutput | Yes | Output collector for emitting records |
Outputs
| Name | Type | Description |
|---|---|---|
| status | InputStatus | MORE_AVAILABLE, NOTHING_AVAILABLE, or END_OF_INPUT |
| side effect | SourceEvent | SourceReaderFinishedEvent sent when current source completes |
Usage Examples
Processing Flow
// HybridSourceReader.pollNext lifecycle:
// 1. If no current reader (waiting for switch) -> NOTHING_AVAILABLE
// 2. Delegate to currentReader.pollNext(output)
// 3. If current reader returns END_OF_INPUT:
// a. If NOT final source -> send SourceReaderFinishedEvent, null reader
// b. If final source -> propagate END_OF_INPUT
// 4. Otherwise return the status as-is