/** * Removes the given {@link Channel} as output of this instance. * * @return the former output index the {@link Channel} */ public int removeOutputChannel(Channel outputChannel) { int outputIndex; for (outputIndex = 0; outputIndex < this.getNumOuputChannels(); outputIndex++) { if (this.getOutputChannel(outputIndex) == outputChannel) { this.getOutputChannels()[outputIndex] = null; outputChannel.setProducer(null); return outputIndex; } } throw new IllegalArgumentException(String.format("%s is not an output of %s.", outputChannel, this)); }
for (int outputIndex = 0; outputIndex < task.getNumOuputChannels(); outputIndex++) { Channel outputChannel = task.getOutputChannels()[outputIndex]; boolean isInterStageRequired = outputChannel.getConsumers().stream()
/** * Returns the {@link OutputSlot} of the {@link ExecutionOperator} that is associated to the given {@link Channel}. * * @return the {@link OutputSlot} or {@code null} if none */ public OutputSlot<?> getOutputSlotFor(Channel channel) { // Simple implementation: linear search. for (int outputIndex = 0; outputIndex < this.getNumOuputChannels(); outputIndex++) { if (this.getOutputChannel(outputIndex) == channel) { return outputIndex < this.getOperator().getNumOutputs() ? this.getOperator().getOutput(outputIndex) : null; } } throw new IllegalArgumentException(String.format("%s does not belong to %s.", channel, this)); }
/** * Create output {@link ChannelInstance}s for this instance. * * @param task the {@link ExecutionTask} in which this instance is being wrapped * @param producerOperatorContext the {@link OptimizationContext.OperatorContext} for this instance * @param inputChannelInstances the input {@link ChannelInstance}s for the {@code task} * @return */ default ChannelInstance[] createOutputChannelInstances(Executor executor, ExecutionTask task, OptimizationContext.OperatorContext producerOperatorContext, List<ChannelInstance> inputChannelInstances) { assert task.getOperator() == this; ChannelInstance[] channelInstances = new ChannelInstance[task.getNumOuputChannels()]; for (int outputIndex = 0; outputIndex < channelInstances.length; outputIndex++) { final Channel outputChannel = task.getOutputChannel(outputIndex); final ChannelInstance outputChannelInstance = outputChannel.createInstance(executor, producerOperatorContext, outputIndex); channelInstances[outputIndex] = outputChannelInstance; } return channelInstances; }
/** * Brings the given {@code task} into execution. */ private void execute(ExecutionTask task, OptimizationContext optimizationContext, ExecutionState executionState) { final GraphChiExecutionOperator graphChiExecutionOperator = (GraphChiExecutionOperator) task.getOperator(); ChannelInstance[] inputChannelInstances = new ChannelInstance[task.getNumInputChannels()]; for (int i = 0; i < inputChannelInstances.length; i++) { inputChannelInstances[i] = executionState.getChannelInstance(task.getInputChannel(i)); } final OptimizationContext.OperatorContext operatorContext = optimizationContext.getOperatorContext(graphChiExecutionOperator); ChannelInstance[] outputChannelInstances = new ChannelInstance[task.getNumOuputChannels()]; for (int i = 0; i < outputChannelInstances.length; i++) { outputChannelInstances[i] = task.getOutputChannel(i).createInstance(this, operatorContext, i); } long startTime = System.currentTimeMillis(); final Tuple<Collection<ExecutionLineageNode>, Collection<ChannelInstance>> results = graphChiExecutionOperator.execute(inputChannelInstances, outputChannelInstances, operatorContext); long endTime = System.currentTimeMillis(); final Collection<ExecutionLineageNode> executionLineageNodes = results.getField0(); final Collection<ChannelInstance> producedChannelInstances = results.getField1(); for (ChannelInstance outputChannelInstance : outputChannelInstances) { if (outputChannelInstance != null) { executionState.register(outputChannelInstance); } } final PartialExecution partialExecution = this.createPartialExecution(executionLineageNodes, endTime - startTime); executionState.add(partialExecution); this.registerMeasuredCardinalities(producedChannelInstances); }