Search in sources :

Example 1 with CopyingDirectedOutput

use of org.apache.flink.streaming.api.collector.selector.CopyingDirectedOutput in project flink by apache.

the class OperatorChain method createOutputCollector.

// ------------------------------------------------------------------------
//  initialization utilities
// ------------------------------------------------------------------------
private <T> Output<StreamRecord<T>> createOutputCollector(StreamTask<?, ?> containingTask, StreamConfig operatorConfig, Map<Integer, StreamConfig> chainedConfigs, ClassLoader userCodeClassloader, Map<StreamEdge, RecordWriterOutput<?>> streamOutputs, List<StreamOperator<?>> allOperators) {
    List<Tuple2<Output<StreamRecord<T>>, StreamEdge>> allOutputs = new ArrayList<>(4);
    // create collectors for the network outputs
    for (StreamEdge outputEdge : operatorConfig.getNonChainedOutputs(userCodeClassloader)) {
        @SuppressWarnings("unchecked") RecordWriterOutput<T> output = (RecordWriterOutput<T>) streamOutputs.get(outputEdge);
        allOutputs.add(new Tuple2<Output<StreamRecord<T>>, StreamEdge>(output, outputEdge));
    }
    // Create collectors for the chained outputs
    for (StreamEdge outputEdge : operatorConfig.getChainedOutputs(userCodeClassloader)) {
        int outputId = outputEdge.getTargetId();
        StreamConfig chainedOpConfig = chainedConfigs.get(outputId);
        Output<StreamRecord<T>> output = createChainedOperator(containingTask, chainedOpConfig, chainedConfigs, userCodeClassloader, streamOutputs, allOperators, outputEdge.getOutputTag());
        allOutputs.add(new Tuple2<>(output, outputEdge));
    }
    // if there are multiple outputs, or the outputs are directed, we need to
    // wrap them as one output
    List<OutputSelector<T>> selectors = operatorConfig.getOutputSelectors(userCodeClassloader);
    if (selectors == null || selectors.isEmpty()) {
        // simple path, no selector necessary
        if (allOutputs.size() == 1) {
            return allOutputs.get(0).f0;
        } else {
            // send to N outputs. Note that this includes teh special case
            // of sending to zero outputs
            @SuppressWarnings({ "unchecked", "rawtypes" }) Output<StreamRecord<T>>[] asArray = new Output[allOutputs.size()];
            for (int i = 0; i < allOutputs.size(); i++) {
                asArray[i] = allOutputs.get(i).f0;
            }
            // otherwise multi-chaining would not work correctly.
            if (containingTask.getExecutionConfig().isObjectReuseEnabled()) {
                return new CopyingBroadcastingOutputCollector<>(asArray, this);
            } else {
                return new BroadcastingOutputCollector<>(asArray, this);
            }
        }
    } else {
        // otherwise multi-chaining would not work correctly.
        if (containingTask.getExecutionConfig().isObjectReuseEnabled()) {
            return new CopyingDirectedOutput<>(selectors, allOutputs);
        } else {
            return new DirectedOutput<>(selectors, allOutputs);
        }
    }
}
Also used : CopyingDirectedOutput(org.apache.flink.streaming.api.collector.selector.CopyingDirectedOutput) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) ArrayList(java.util.ArrayList) StreamEdge(org.apache.flink.streaming.api.graph.StreamEdge) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) CopyingDirectedOutput(org.apache.flink.streaming.api.collector.selector.CopyingDirectedOutput) DirectedOutput(org.apache.flink.streaming.api.collector.selector.DirectedOutput) RecordWriterOutput(org.apache.flink.streaming.runtime.io.RecordWriterOutput) OutputSelector(org.apache.flink.streaming.api.collector.selector.OutputSelector) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Output(org.apache.flink.streaming.api.operators.Output) CopyingDirectedOutput(org.apache.flink.streaming.api.collector.selector.CopyingDirectedOutput) DirectedOutput(org.apache.flink.streaming.api.collector.selector.DirectedOutput) RecordWriterOutput(org.apache.flink.streaming.runtime.io.RecordWriterOutput)

Aggregations

ArrayList (java.util.ArrayList)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 CopyingDirectedOutput (org.apache.flink.streaming.api.collector.selector.CopyingDirectedOutput)1 DirectedOutput (org.apache.flink.streaming.api.collector.selector.DirectedOutput)1 OutputSelector (org.apache.flink.streaming.api.collector.selector.OutputSelector)1 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)1 StreamEdge (org.apache.flink.streaming.api.graph.StreamEdge)1 Output (org.apache.flink.streaming.api.operators.Output)1 RecordWriterOutput (org.apache.flink.streaming.runtime.io.RecordWriterOutput)1 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)1