/** * Tells whether the producer of the given {@link Channel} (and its producers in turn) should be considered. */ private boolean shouldVisitProducerOf(Channel channel) { // We do not follow copied Channels, because they mark the border to already executed ExecutionTasks. return !channel.isCopy(); }
/** * 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; }
/** * Creates a new, hierarchical instance. Mimes the {@code original}'s properties except for the {@link #consumers}. * * @param original the original instance whose properties will be mimed */ protected Channel(Channel original) { this.descriptor = original.getDescriptor(); this.original = original.getOriginal(); assert this.original == null || !this.original.isCopy(); this.producer = original.getProducer(); this.producerSlot = original.getProducerSlot(); }
/** * Merges this instance into the original instance ({@link #getOriginal()}. * <p>The consumers of the original instance are cleared and replaced with the consumers of this instance. * For all other properties, the original and this instance should agree.</p> */ public void mergeIntoOriginal() { if (!this.isCopy()) return; this.getOriginal().copyConsumersFrom(this); this.getOriginal().adoptSiblings(this); }