*/
private void computeDelta(final SingleComputationCycle previousCycle) {
if (previousCycle.getState() != ViewCycleState.EXECUTED) {
throw new IllegalArgumentException("State of previous cycle must be " + ViewCycleState.EXECUTED);
}
final InMemoryViewComputationResultModel fragmentResultModel = constructTemplateResultModel();
final InMemoryViewComputationResultModel fullResultModel = getResultModel();
for (final DependencyGraphExplorer depGraphExplorer : getCompiledViewDefinition().getDependencyGraphExplorers()) {
final DependencyGraph depGraph = depGraphExplorer.getWholeGraph();
final ViewComputationCache cache = getComputationCache(depGraph.getCalculationConfigurationName());
final ViewComputationCache previousCache = previousCycle.getComputationCache(depGraph.getCalculationConfigurationName());
final DependencyNodeJobExecutionResultCache jobExecutionResultCache = getJobExecutionResultCache(depGraph.getCalculationConfigurationName());
final DependencyNodeJobExecutionResultCache previousJobExecutionResultCache = previousCycle.getJobExecutionResultCache(depGraph.getCalculationConfigurationName());
final LiveDataDeltaCalculator deltaCalculator = new LiveDataDeltaCalculator(depGraph, cache, previousCache);
deltaCalculator.computeDelta();
s_logger.info("Computed delta for calculation configuration '{}'. {} nodes out of {} require recomputation.",
depGraph.getCalculationConfigurationName(),
deltaCalculator.getChangedNodes().size(),
depGraph.getSize());
final Collection<ValueSpecification> specsToCopy = new LinkedList<>();
final Collection<ComputedValue> errors = new LinkedList<>();
for (final DependencyNode unchangedNode : deltaCalculator.getUnchangedNodes()) {
if (unchangedNode.isMarketDataSourcingFunction()) {
// Market data is already in the cache, so don't need to copy it across again
continue;
}
final DependencyNodeJobExecutionResult previousExecutionResult = previousJobExecutionResultCache.find(unchangedNode.getOutputValues());
if (getLogModeSource().getLogMode(unchangedNode) == ExecutionLogMode.FULL
&& (previousExecutionResult == null || previousExecutionResult.getJobResultItem().getExecutionLog().getEvents() == null)) {
// Need to rerun calculation to collect logs, so cannot reuse
continue;
}
final NodeStateFlag nodeState = previousCycle.getNodeState(unchangedNode);
if (nodeState != null) {
setNodeState(unchangedNode, nodeState);
if (nodeState == NodeStateFlag.EXECUTED) {
specsToCopy.addAll(unchangedNode.getOutputValues());
} else {
for (final ValueSpecification outputValue : unchangedNode.getOutputValues()) {
errors.add(new ComputedValue(outputValue, MissingOutput.SUPPRESSED));
}
}
}
}
if (!specsToCopy.isEmpty()) {
final ComputationCycleQuery reusableResultsQuery = new ComputationCycleQuery();
reusableResultsQuery.setCalculationConfigurationName(depGraph.getCalculationConfigurationName());
reusableResultsQuery.setValueSpecifications(specsToCopy);
final ComputationResultsResponse reusableResultsQueryResponse = previousCycle.queryResults(reusableResultsQuery);
final Map<ValueSpecification, ComputedValueResult> resultsToReuse = reusableResultsQueryResponse.getResults();
final Collection<ComputedValue> newValues = new ArrayList<>(resultsToReuse.size());
for (final ComputedValueResult computedValueResult : resultsToReuse.values()) {
final ValueSpecification valueSpec = computedValueResult.getSpecification();
if (depGraph.getTerminalOutputSpecifications().contains(valueSpec)
&& getViewDefinition().getResultModelDefinition().shouldOutputResult(valueSpec, depGraph)) {
fragmentResultModel.addValue(depGraph.getCalculationConfigurationName(), computedValueResult);
fullResultModel.addValue(depGraph.getCalculationConfigurationName(), computedValueResult);
}
final Object previousValue = computedValueResult.getValue() != null ? computedValueResult.getValue() : MissingOutput.EVALUATION_ERROR;
newValues.add(new ComputedValue(valueSpec, previousValue));
final DependencyNodeJobExecutionResult previousDependencyNodeJobExecutionResult = previousJobExecutionResultCache.get(valueSpec);
if (previousDependencyNodeJobExecutionResult != null) {