public ChannelInstance getChannelInstance(Channel channel, boolean isPeekingToNextTransition) { final ExecutionStageLoop loop = getExecutionStageLoop(channel); if (loop == null) { return this.channelInstances.get(channel); } else { final ExecutionStageLoopContext loopContext = this.getOrCreateLoopContext(loop); return loopContext.getChannelInstance(channel, isPeekingToNextTransition); } }
@Override public void register(ChannelInstance channelInstance) { final ExecutionStageLoop loop = getExecutionStageLoop(channelInstance.getChannel()); if (loop == null) { final ChannelInstance oldChannelInstance = this.channelInstances.put(channelInstance.getChannel(), channelInstance); channelInstance.noteObtainedReference(); if (oldChannelInstance != null) { oldChannelInstance.noteDiscardedReference(true); } } else { final ExecutionStageLoopContext loopContext = this.getOrCreateLoopContext(loop); loopContext.register(channelInstance); } }
/** * Tries to execute the given {@link ExecutionStage}. * * @param stageActivator that should be executed * @return whether the {@link ExecutionStage} was really executed */ private void execute(StageActivator stageActivator) { final ExecutionStage stage = stageActivator.getStage(); final OptimizationContext optimizationContext = stageActivator.getOptimizationContext(); // Find parts of the stage to instrument. this.instrumentationStrategy.applyTo(stage); // Obtain an Executor for the stage. Executor executor = this.getOrCreateExecutorFor(stage); // Have the execution done. CrossPlatformExecutor.this.logger.info("Having {} execute {}:\n{}", executor, stage, stage.getPlanAsString("> ")); long startTime = System.currentTimeMillis(); executor.execute(stage, optimizationContext, this); long finishTime = System.currentTimeMillis(); CrossPlatformExecutor.this.logger.info("Executed {} in {}.", stage, Formats.formatDuration(finishTime - startTime, true)); // Remember that we have executed the stage. this.completedStages.add(stage); if (stage.isLoopHead()) { this.getOrCreateLoopContext(stage.getLoop()).scrapPreviousTransitionContext(); } }