/** * Switch the state of this instance: Age the next to the previous transition and create a new * current {@link ExecutionStageLoopIterationContext}. */ public void activateNextIteration() { logger.info("Activating next iteration."); if (this.currentIteration != null) this.currentIteration.noteDiscardedReference(true); this.currentIteration = this.createIterationContext(); if (this.prevTransition != null) this.prevTransition.noteDiscardedReference(true); this.prevTransition = this.nextTransition; this.nextTransition = null; }
/** * Provide a {@link ChannelInstance} from this instance. The instance can be provided from the previous or * next transition or the current {@link ExecutionStageLoopIterationContext}. * * @param channel whose {@link ChannelInstance} should be provided * @param isPeekingToNextTransition whether the next transition {@link ExecutionStageLoopIterationContext} * may be accessed * @return the {@link ChannelInstance} or {@code null} if it cannot be found */ public ChannelInstance getChannelInstance(Channel channel, boolean isPeekingToNextTransition) { if (isPeekingToNextTransition) { return this.getOrCreateNextTransition().getChannelInstance(channel); } if (this.prevTransition != null) { final ChannelInstance channelInstance = this.prevTransition.getChannelInstance(channel); if (channelInstance != null) return channelInstance; } if (this.currentIteration != null) { return this.currentIteration.getChannelInstance(channel); } return null; }
/** * Registers the given {@link ChannelInstance} with appropriate {@link ExecutionStageLoopIterationContext}s. * * @param channelInstance the {@link ChannelInstance} */ public void register(ChannelInstance channelInstance) { final Channel channel = channelInstance.getChannel(); boolean isFeedback = false, isIterationLocal = false; for (ExecutionTask consumer : channel.getConsumers()) { if (consumer.isFeedbackInput(channel)) { isFeedback = true; } else { isIterationLocal = true; } } if (isIterationLocal) this.currentIteration.register(channelInstance); if (isFeedback) this.getOrCreateNextTransition().register(channelInstance); }
/** * Removes the previous transition {@link ExecutionStageLoopIterationContext}. Included resources * will not be provided anymore by this instance. */ public void scrapPreviousTransitionContext() { if (this.prevTransition != null) this.prevTransition.noteDiscardedReference(true); this.prevTransition = null; } }
@Override protected void disposeUnreferenced() { for (ExecutionResource loopInvariant : this.loopInvariants) { loopInvariant.noteDiscardedReference(true); } this.loopInvariants = null; CrossPlatformExecutor.this.removeLoopContext(this.loop); if (this.prevTransition != null) this.prevTransition.noteDiscardedReference(true); if (this.currentIteration != null) this.currentIteration.noteDiscardedReference(true); if (this.nextTransition != null) this.nextTransition.noteDiscardedReference(true); }
private ExecutionStageLoopIterationContext createIterationContext() { final ExecutionStageLoopIterationContext iteration = new ExecutionStageLoopIterationContext(this); iteration.noteObtainedReference(); return iteration; }