public int getNumInputChannels() { return this.getInputChannels().length; }
public Channel getInputChannel(int index) { return this.getInputChannels()[index]; }
/** * Collects all {@link Channel}s that are copies. We recognize them as {@link Channel}s that are open. */ public Collection<Channel> getOpenInputChannels() { return this.collectAllTasks().stream() .flatMap(task -> Arrays.stream(task.getInputChannels())) .filter(Channel::isCopy) .collect(Collectors.toList()); }
private void collectAllTasksAux(ExecutionTask currentTask, Set<ExecutionTask> collector) { if (collector.add(currentTask)) { final Stream<ExecutionTask> producerStream = Arrays.stream(currentTask.getInputChannels()) .filter(Objects::nonNull) .map(Channel::getProducer) .filter(Objects::nonNull); this.collectAllTasksAux(producerStream, collector); } }
/** * @return all {@link Channel}s of this instance that connect from other {@link ExecutionStage}s */ public Collection<Channel> getInboundChannels() { return this.getAllTasks().stream() .flatMap(task -> Arrays.stream(task.getInputChannels()).filter( channel -> channel.getProducer().getStage() != this ) ).collect(Collectors.toList()); }
public boolean isComplete() { final Logger logger = LoggerFactory.getLogger(this.getClass()); final Set<ExecutionTask> allTasks = this.collectAllTasks(); if (allTasks.isEmpty()) { logger.warn("Instance has not tasks."); return false; } for (ExecutionTask task : allTasks) { if (Arrays.stream(task.getOutputChannels()).anyMatch(Objects::isNull)) { logger.warn("{} has missing output channels among {}.", task, Arrays.toString(task.getOutputChannels())); return false; } if (Arrays.stream(task.getInputChannels()).anyMatch(Objects::isNull)) { logger.warn("{} has missing input channels among {}.", task, Arrays.toString(task.getInputChannels())); return false; } } return true; }
/** * Checks if <i>all</i> input {@link Channel}s of the given {@code task} are outbound w.r.t. to the * {@link InterimStage}. */ private boolean checkIfStartTask(ExecutionTask task) { for (Channel channel : task.getInputChannels()) { if (this.checkIfFeedbackChannel(task, channel)) continue; final ExecutionTask producer = channel.getProducer(); if (this.equals(StageAssignmentTraversal.this.assignedInterimStages.get(producer))) { return false; } } return true; }
/** * Appends this instance's {@link ExecutionTask}s and {@link Channel}s to the given {@link StringBuilder}. * * @param sb to which the representation should be appended * @param indent will be used to indent every line of the textual representation */ public void getPlanAsString(StringBuilder sb, String indent) { Set<ExecutionTask> seenTasks = new HashSet<>(); for (ExecutionTask startTask : this.startTasks) { for (Channel inputChannel : startTask.getInputChannels()) { sb.append(indent) .append("In ") .append(this.prettyPrint(inputChannel)) .append(" => ") .append(this.prettyPrint(startTask)).append('\n'); } this.toExtensiveStringAux(startTask, seenTasks, sb, indent); } }
/** * Removes the given {@link Channel} as input of this instance. * * @return the former input index the {@link Channel} */ public int removeInputChannel(Channel inputChannel) { int inputIndex; for (inputIndex = 0; inputIndex < this.getNumInputChannels(); inputIndex++) { if (this.getInputChannel(inputIndex) == inputChannel) { this.getInputChannels()[inputIndex] = null; inputChannel.getConsumers().remove(this); return inputIndex; } } throw new IllegalArgumentException(String.format("%s is not an input of %s.", inputChannel, this)); }
/** * Sets an input {@link Channel} for this instance. Consider using {@link Channel#addConsumer(ExecutionTask, int)} * instead. */ void setInputChannel(int index, Channel channel) { assert channel == null || this.getInputChannel(index) == null : String.format("Cannot set up %s for %s@%d: There is already %s.", channel, this.getOperator(), index, this.getInputChannel(index)); this.getInputChannels()[index] = channel; }
/** * Handle the upstream neighbors of the given {@code task} by expanding the {@code expandableStage} if possible. */ private void expandUpstream(ExecutionTask task, InterimStage expandableStage) { for (Channel channel : task.getInputChannels()) { if (!this.shouldVisitProducerOf(channel)) continue; final ExecutionTask producer = channel.getProducer(); assert producer != null; final InterimStage assignedStage = this.assignedInterimStages.get(producer); if (assignedStage == null) { this.handleTaskWithoutPlatformExecution(producer, /*channel.isExecutionBreaker() ? null : */expandableStage); } } }
for (int i = 0; i < executionTask.getInputChannels().length; i++) { Channel channel = executionTask.getInputChannels()[i]; if (channel == null) { logger.warn("{} does not have an input channel @{}.", executionTask, i);
/** * Implements various sanity checks. Problems are logged. */ public boolean isSane() { // 1. Check if every ExecutionTask is assigned an ExecutionStage. final Set<ExecutionTask> allTasks = this.collectAllTasks(); boolean isAllTasksAssigned = allTasks.stream().allMatch(task -> task.getStage() != null); if (!isAllTasksAssigned) { this.logger.error("There are tasks without stages."); } final Set<Channel> allChannels = allTasks.stream() .flatMap(task -> Stream.concat(Arrays.stream(task.getInputChannels()), Arrays.stream(task.getOutputChannels()))) .collect(Collectors.toSet()); boolean isAllChannelsOriginal = allChannels.stream() .allMatch(channel -> !channel.isCopy()); if (!isAllChannelsOriginal) { this.logger.error("There are channels that are copies."); } boolean isAllSiblingsConsistent = true; for (Channel channel : allChannels) { for (Channel sibling : channel.getSiblings()) { if (!allChannels.contains(sibling)) { this.logger.error("A sibling of {}, namely {}, seems to be invalid.", channel, sibling); isAllSiblingsConsistent = false; } } } return isAllTasksAssigned && isAllChannelsOriginal && isAllSiblingsConsistent; }
while ((task = stagedTasks.poll()) != null) { connectedComponent.add(task); for (Channel channel : task.getInputChannels()) { if (task.isFeedbackInput(channel)) continue; final ExecutionTask producer = channel.getProducer();
for (Channel channel : currentExecutionTask.getInputChannels()) { if (this.shouldVisitProducerOf(channel)) { final ExecutionTask predecessor = channel.getProducer();
for (Channel inputChannel : task.getInputChannels()) { if (!this.shouldVisitProducerOf(inputChannel)) { // Barrier.
for (Channel inputChannel : executionTask.getInputChannels()) { if (inputChannel == null) continue;