use of org.apache.flink.api.connector.source.Source in project flink by apache.
the class HybridSourceSplitEnumerator method sendSwitchSourceEvent.
private void sendSwitchSourceEvent(int subtaskId, int sourceIndex) {
readerSourceIndex.put(subtaskId, sourceIndex);
Source source = switchedSources.sourceOf(sourceIndex);
context.sendEventToSourceReader(subtaskId, new SwitchSourceEvent(sourceIndex, source, sourceIndex >= (sources.size() - 1)));
// send pending splits, if any
TreeMap<Integer, List<HybridSourceSplit>> splitsBySource = pendingSplits.get(subtaskId);
if (splitsBySource != null) {
List<HybridSourceSplit> splits = splitsBySource.remove(sourceIndex);
if (splits != null && !splits.isEmpty()) {
LOG.debug("Restoring splits to subtask={} {}", subtaskId, splits);
context.assignSplits(new SplitsAssignment<>(Collections.singletonMap(subtaskId, splits)));
context.signalNoMoreSplits(subtaskId);
}
if (splitsBySource.isEmpty()) {
pendingSplits.remove(subtaskId);
}
}
if (sourceIndex == currentSourceIndex) {
LOG.debug("adding reader subtask={} sourceIndex={}", subtaskId, currentSourceIndex);
currentEnumerator.addReader(subtaskId);
}
}
Aggregations