_viewProcessor = viewProcessor;
_user = user;
_latestCycleRetainer = new EngineResourceRetainer(viewProcessor.getViewCycleManager());
ViewResultListener mergedViewProcessListener = new ViewResultListener() {
@Override
public UserPrincipal getUser() {
return ViewClientImpl.this.getUser();
}
@Override
public void viewDefinitionCompiled(CompiledViewDefinition compiledViewDefinition,
boolean hasMarketDataPermissions) {
updateLatestCompiledViewDefinition(compiledViewDefinition);
_canAccessCompiledViewDefinition = _permissionProvider.canAccessCompiledViewDefinition(getUser(),
compiledViewDefinition);
_canAccessComputationResults = _permissionProvider.canAccessComputationResults(getUser(),
compiledViewDefinition,
hasMarketDataPermissions);
PortfolioFilter filter = _portfolioPermissionProvider.createPortfolioFilter(getUser());
// TODO [PLAT-1144] -- so we know whether or not the user is permissioned for various things, but what do we
// pass to downstream listeners? Some special perm denied message in place of results on each computation
// cycle?
// Would be better if there was a builder for this!
CompiledViewDefinition replacementViewDef = new CompiledViewDefinitionImpl(
compiledViewDefinition.getResolverVersionCorrection(),
compiledViewDefinition.getCompilationIdentifier(),
compiledViewDefinition.getViewDefinition(),
filter.generateRestrictedPortfolio(compiledViewDefinition.getPortfolio()),
compiledViewDefinition.getCompiledCalculationConfigurations(),
compiledViewDefinition.getValidFrom(),
compiledViewDefinition.getValidTo());
ViewResultListener listener = _userResultListener.get();
if (listener != null) {
listener.viewDefinitionCompiled(replacementViewDef, hasMarketDataPermissions);
}
}
@Override
public void cycleStarted(ViewCycleMetadata cycleMetadata) {
ViewResultListener listener = _userResultListener.get();
if (listener != null) {
// Only send cycle started results in conjunction with fragments
if (!getFragmentResultMode().equals(ViewResultMode.NONE)) {
listener.cycleStarted(cycleMetadata);
}
}
}
@Override
public void cycleCompleted(ViewComputationResultModel fullResult, ViewDeltaResultModel deltaResult) {
boolean isFirstResult = updateLatestResult(fullResult);
ViewResultListener listener = _userResultListener.get();
if (listener != null) {
ViewResultMode resultMode = getResultMode();
if (!resultMode.equals(ViewResultMode.NONE)) {
ViewComputationResultModel userFullResult = isFullResultRequired(resultMode,
isFirstResult) ? fullResult : null;
ViewDeltaResultModel userDeltaResult = isDeltaResultRequired(resultMode,
isFirstResult) ? deltaResult : null;
if (userFullResult != null || userDeltaResult != null) {
listener.cycleCompleted(userFullResult, userDeltaResult);
} else if (!isFirstResult || resultMode != ViewResultMode.DELTA_ONLY) {
// Would expect this if it's the first result and we're in delta only mode, otherwise log a warning
s_logger.warn("Ignored CycleCompleted call with no useful results to propagate");
}
}
}
}
@Override
public void cycleFragmentCompleted(ViewComputationResultModel fullFragment, ViewDeltaResultModel deltaFragment) {
ViewComputationResultModel prevResult = _latestResult.get();
ViewResultListener listener = _userResultListener.get();
if (listener != null) {
ViewResultMode resultMode = getFragmentResultMode();
if (!resultMode.equals(ViewResultMode.NONE)) {
ViewComputationResultModel userFullResult = isFullResultRequired(resultMode,
prevResult == null) ? fullFragment : null;
ViewDeltaResultModel userDeltaResult = isDeltaResultRequired(resultMode,
prevResult == null) ? deltaFragment : null;
if (userFullResult != null || userDeltaResult != null) {
listener.cycleFragmentCompleted(userFullResult, userDeltaResult);
} else if (prevResult == null || resultMode != ViewResultMode.DELTA_ONLY) {
// Would expect this if it's the first result and we're in delta only mode, otherwise log a warning
s_logger.warn("Ignored CycleFragmentCompleted call with no useful results to propagate");
}
}
}
}
@Override
public void cycleExecutionFailed(ViewCycleExecutionOptions executionOptions, Exception exception) {
ViewResultListener listener = _userResultListener.get();
if (listener != null) {
listener.cycleExecutionFailed(executionOptions, exception);
}
}
@Override
public void viewDefinitionCompilationFailed(Instant valuationTime, Exception exception) {
ViewResultListener listener = _userResultListener.get();
if (listener != null) {
listener.viewDefinitionCompilationFailed(valuationTime, exception);
}
}
@Override
public void processCompleted() {
ViewClientImpl.this.processCompleted();
ViewResultListener listener = _userResultListener.get();
if (listener != null) {
listener.processCompleted();
}
}
@Override
public void processTerminated(boolean executionInterrupted) {
ViewClientImpl.this.detachFromViewProcess();
ViewResultListener listener = _userResultListener.get();
if (listener != null) {
listener.processTerminated(executionInterrupted);
}
}
@Override
public void clientShutdown(Exception e) {