Package com.opengamma.engine.view

Examples of com.opengamma.engine.view.ViewComputationResultModel


   */
  private boolean updateLatestResult(ViewComputationResultModel result) {
    if (isViewCycleAccessSupported()) {
      getLatestCycleRetainer().replaceRetainedCycle(result.getViewCycleId());
    }
    ViewComputationResultModel oldResult = _latestResult.getAndSet(result);
    return oldResult == null;
  }
View Full Code Here


  @Override
  public void cycleCompleted(final ViewCycle cycle) {
    // Caller MUST NOT hold the semaphore
    s_logger.debug("View cycle {} completed on view process {}", cycle.getUniqueId(), getUniqueId());
    final ViewComputationResultModel result;
    ViewDeltaResultModel deltaResult = null;
    final ViewResultListener[] listeners;
    lock();
    try {
      result = cycle.getResultModel();
      if (_mustCalculateDeltas.get()) {
        // We swap these first so that in the callback the process is consistent.
        final ViewComputationResultModel previousResult = _latestResult.getAndSet(result);
        // [PLAT-1158] Is the cost of computing the delta going to be high; should we offload that to a slave thread before dispatching to the listeners?
        deltaResult = ViewDeltaResultCalculator.computeDeltaModel(cycle.getCompiledViewDefinition().getViewDefinition(), previousResult, result);
      }
      listeners = getListenerArray();
    } finally {
View Full Code Here

    final ViewDeltaResultModel deltaFragment;
    final ViewResultListener[] listeners;
    lock();
    try {
      // [PLAT-1158] Is the cost of computing the delta going to be high; should we offload that to a slave thread before dispatching to the listeners?
      final ViewComputationResultModel previousResult = _latestResult.get();
      deltaFragment = ViewDeltaResultCalculator.computeDeltaModel(viewDefinition, previousResult, fullFragment);
      listeners = getListenerArray();
    } finally {
      unlock();
    }
View Full Code Here

    ArgumentChecker.notNull(listener, "listener");
    ArgumentChecker.notNull(resultMode, "resultMode");
    ArgumentChecker.notNull(fragmentResultMode, "fragmentResultMode");
    // Caller MUST NOT hold the semaphore
    Pair<CompiledViewDefinitionWithGraphs, MarketDataPermissionProvider> latestCompilation = null;
    ViewComputationResultModel latestResult = null;
    boolean listenerRequiresDeltas = doesListenerRequireDeltas(resultMode, fragmentResultMode);
    lock();
    try {
      if (_listeners.put(listener, listenerRequiresDeltas) == null) {
        if (listenerRequiresDeltas) {
View Full Code Here

    final CompiledViewDefinitionWithGraphsImpl preCompilation = mock(CompiledViewDefinitionWithGraphsImpl.class);
    mergingListener.viewDefinitionCompiled(preCompilation, true);

    addResults(mergingListener, 10);
    mergingListener.cycleCompleted(mock(ViewComputationResultModel.class), getDeltaResult(1));
    final ViewComputationResultModel latestResult = mock(ViewComputationResultModel.class);
    mergingListener.cycleCompleted(latestResult, getDeltaResult(2));

    final CompiledViewDefinitionWithGraphsImpl postCompilation = mock(CompiledViewDefinitionWithGraphsImpl.class);
    mergingListener.viewDefinitionCompiled(postCompilation, true);
View Full Code Here

    resultListener.assertViewDefinitionCompiled(TIMEOUT);
    resultListener.assertCycleStarted(TIMEOUT);
    final ViewResultModel result1Fragment = resultListener.getCycleFragmentCompleted(TIMEOUT).getFullFragment();
    assertNotNull(result1Fragment);
    final ViewComputationResultModel result1 = resultListener.getCycleCompleted(TIMEOUT).getFullResult();
    assertNotNull(result1);

    Map<ValueRequirement, Object> expected = new HashMap<ValueRequirement, Object>();
    expected.put(ViewProcessorTestEnvironment.getPrimitive1(), (byte) 1);
    expected.put(ViewProcessorTestEnvironment.getPrimitive2(), (byte) 2);
    assertComputationResult(expected, env.getCalculationResult(result1));
    assertComputationResult(expected, env.getCalculationResult(result1Fragment));
    assertTrue(client.isResultAvailable());
    assertEquals(result1, client.getLatestResult());

    client.pause();

    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive1(), (byte) 3);
    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive2(), (byte) 4);

    env.getCurrentWorker(viewProcess).requestCycle();

    // Should have been merging results received in the meantime
    client.resume();
    final UniqueId cycleStartedId = resultListener.getCycleStarted(TIMEOUT).getCycleMetadata().getViewCycleId();
    resultListener.assertCycleFragmentCompleted(TIMEOUT);
    final ViewComputationResultModel result2 = resultListener.getCycleCompleted(TIMEOUT).getFullResult();
    assertEquals(result2.getViewCycleId(), cycleStartedId);

    expected = new HashMap<ValueRequirement, Object>();
    expected.put(ViewProcessorTestEnvironment.getPrimitive1(), (byte) 3);
    expected.put(ViewProcessorTestEnvironment.getPrimitive2(), (byte) 4);
    assertComputationResult(expected, env.getCalculationResult(result2));
View Full Code Here

    client1ResultListener.assertNoCalls(TIMEOUT);

    // Resuming should release the most recent result to the client
    client1.resume();
    client1ResultListener.getCycleStarted(TIMEOUT).getCycleMetadata();
    final ViewComputationResultModel result2Fragment = client1ResultListener.getCycleFragmentCompleted(TIMEOUT).getFullFragment();
    final ViewComputationResultModel result2 = client1ResultListener.getCycleCompleted(TIMEOUT).getFullResult();
    Map<ValueRequirement, Object> expected = new HashMap<ValueRequirement, Object>();
    expected.put(ViewProcessorTestEnvironment.getPrimitive1(), (byte) 2);
    expected.put(ViewProcessorTestEnvironment.getPrimitive2(), (byte) 0);
    assertComputationResult(expected, env.getCalculationResult(result2Fragment));
    assertComputationResult(expected, env.getCalculationResult(result2));

    // Changes should now propagate straight away to both listeners
    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive1(), (byte) 3);
    env.getCurrentWorker(viewProcess1).requestCycle();
    client1ResultListener.assertCycleStarted(TIMEOUT);
    client2ResultListener.assertCycleStarted(TIMEOUT);
    client2ResultListener.assertCycleFragmentCompleted(TIMEOUT);
    client2ResultListener.assertCycleCompleted(TIMEOUT);
    final ViewComputationResultModel result3Fragment = client1ResultListener.getCycleFragmentCompleted(TIMEOUT).getFullFragment();
    final ViewComputationResultModel result3 = client1ResultListener.getCycleCompleted(TIMEOUT).getFullResult();
    expected = new HashMap<ValueRequirement, Object>();
    expected.put(ViewProcessorTestEnvironment.getPrimitive1(), (byte) 3);
    expected.put(ViewProcessorTestEnvironment.getPrimitive2(), (byte) 0);
    assertComputationResult(expected, env.getCalculationResult(result3Fragment));
    assertComputationResult(expected, env.getCalculationResult(result3));

    // Pause results again and we should be back to merging both whole cycle results and fragments
    client1.pause();
    client2ResultListener.assertNoCalls(TIMEOUT);
    client1ResultListener.assertNoCalls(TIMEOUT);

    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive2(), (byte) 1);
    env.getCurrentWorker(viewProcess1).requestCycle();
    client2ResultListener.assertCycleStarted(TIMEOUT);
    client2ResultListener.assertCycleFragmentCompleted(TIMEOUT);
    client2ResultListener.assertCycleCompleted(TIMEOUT);
    assertEquals(0, client2ResultListener.getQueueSize());
    client1ResultListener.assertNoCalls(TIMEOUT);

    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive2(), (byte) 2);
    env.getCurrentWorker(viewProcess1).requestCycle();
    client2ResultListener.assertCycleStarted(TIMEOUT);
    client2ResultListener.assertCycleFragmentCompleted(TIMEOUT);
    client2ResultListener.assertCycleCompleted(TIMEOUT);
    assertEquals(0, client2ResultListener.getQueueSize());
    client1ResultListener.assertNoCalls(TIMEOUT);

    // Start results again
    client1.resume();
    client1ResultListener.assertCycleStarted(TIMEOUT);
    final ViewComputationResultModel result4Fragment = client1ResultListener.getCycleFragmentCompleted(TIMEOUT).getFullFragment();
    final ViewComputationResultModel result4 = client1ResultListener.getCycleCompleted(TIMEOUT).getFullResult();
    assertEquals(0, client1ResultListener.getQueueSize());
    client2ResultListener.assertNoCalls(TIMEOUT);
    expected = new HashMap<ValueRequirement, Object>();
    expected.put(ViewProcessorTestEnvironment.getPrimitive1(), (byte) 3);
    expected.put(ViewProcessorTestEnvironment.getPrimitive2(), (byte) 2);
View Full Code Here

    client.setResultListener(resultListener);

    client.attachToViewProcess(env.getViewDefinition().getUniqueId(), ExecutionOptions.infinite(MarketData.live(), ExecutionFlags.none().get()));

    resultListener.assertViewDefinitionCompiled(TIMEOUT);
    final ViewComputationResultModel result1 = resultListener.getCycleCompleted(TIMEOUT).getFullResult();
    assertEquals(0, resultListener.getQueueSize());

    assertEquals(1, result1.getAllResults().size());
    final ComputedValueResult result1Value = Iterables.getOnlyElement(result1.getAllResults()).getComputedValue();
    assertEquals("result2", result1Value.getValue());

    final AggregatedExecutionLog log1 = result1Value.getAggregatedExecutionLog();
    assertNotNull(log1);
    assertTrue(log1.getLogLevels().contains(LogLevel.ERROR));
    assertTrue(log1.getLogLevels().contains(LogLevel.WARN));
    assertFalse(log1.getLogLevels().contains(LogLevel.INFO));
    assertNull(log1.getLogs());

    final Pair<String, ValueSpecification> resultSpec = Pair.of(calcConfig.getName(), Iterables.getOnlyElement(client.getLatestCompiledViewDefinition().getTerminalValuesRequirements().keySet()));
    client.setMinimumLogMode(ExecutionLogMode.FULL, ImmutableSet.of(resultSpec));

    final ViewProcessImpl viewProcess = env.getViewProcess(vp, client.getUniqueId());
    final ViewProcessWorker worker = env.getCurrentWorker(viewProcess);
    worker.triggerCycle();

    final ViewComputationResultModel result2 = resultListener.getCycleCompleted(TIMEOUT).getFullResult();
    assertEquals(0, resultListener.getQueueSize());

    assertEquals(1, result2.getAllResults().size());
    final ComputedValueResult result2Value = Iterables.getOnlyElement(result2.getAllResults()).getComputedValue();
    assertEquals("result2", result2Value.getValue());

    final AggregatedExecutionLog log2 = result2Value.getAggregatedExecutionLog();
    assertNotNull(log2);
    assertTrue(log2.getLogLevels().contains(LogLevel.ERROR));
    assertTrue(log2.getLogLevels().contains(LogLevel.WARN));
    assertFalse(log2.getLogLevels().contains(LogLevel.INFO));
    assertNotNull(log2.getLogs());
    assertEquals(2, log2.getLogs().size());

    final ExecutionLogWithContext result2LogContext = log2.getLogs().get(0);
    assertNotNull(result2LogContext);
    assertEquals(fn2.getFunctionDefinition().getShortName(), result2LogContext.getFunctionName());
    assertEquals(resultSpec.getSecond().getTargetSpecification(), result2LogContext.getTargetSpecification());
    final ExecutionLog result2Log = result2LogContext.getExecutionLog();
    assertEquals(1, result2Log.getEvents().size());
    final LogEvent result2Event1 = result2Log.getEvents().get(0);
    assertEquals(LogLevel.WARN, result2Event1.getLevel());
    assertEquals("Warning during execution", result2Event1.getMessage());
    assertNull(result2Log.getExceptionClass());
    assertNull(result2Log.getExceptionMessage());
    assertNull(result2Log.getExceptionStackTrace());

    final ExecutionLogWithContext result1LogContext = log2.getLogs().get(1);
    assertNotNull(result1LogContext);
    assertEquals(fn1.getFunctionDefinition().getShortName(), result1LogContext.getFunctionName());
    assertEquals(resultSpec.getSecond().getTargetSpecification(), result1LogContext.getTargetSpecification());
    final ExecutionLog result1Log = result1LogContext.getExecutionLog();
    assertEquals(2, result1Log.getEvents().size());
    final LogEvent result1Event1 = result1Log.getEvents().get(0);
    assertEquals(LogLevel.WARN, result1Event1.getLevel());
    assertEquals("Warning during execution", result1Event1.getMessage());
    final LogEvent result1Event2 = result1Log.getEvents().get(1);
    assertEquals(LogLevel.ERROR, result1Event2.getLevel());
    assertEquals("Error during execution", result1Event2.getMessage());
    assertNull(result1Log.getExceptionClass());
    assertNull(result1Log.getExceptionMessage());
    assertNull(result1Log.getExceptionStackTrace());

    client.setMinimumLogMode(ExecutionLogMode.INDICATORS, ImmutableSet.of(resultSpec));
    worker.triggerCycle();

    final ViewComputationResultModel result3 = resultListener.getCycleCompleted(TIMEOUT).getFullResult();
    assertEquals(0, resultListener.getQueueSize());

    assertEquals(1, result3.getAllResults().size());
    final ComputedValueResult result3Value = Iterables.getOnlyElement(result3.getAllResults()).getComputedValue();
    assertEquals("result2", result3Value.getValue());

    final AggregatedExecutionLog log3 = result3Value.getAggregatedExecutionLog();
    assertNotNull(log3);
    // Delta cycle - should reuse the previous result which *does* include logs.
    assertNotNull(log3.getLogs());

    // Force a full cycle - should *not* reuse any previous result, so back to indicators only
    // TODO: [PLAT-3215] This is bad; future optimizations will not necessarily mean a full cycle happens just because a new view definition got posted
    vd.setUniqueId(UniqueId.of(vd.getUniqueId().getScheme(), vd.getUniqueId().getValue(), "PLAT-3215"));
    worker.updateViewDefinition(vd);
    worker.triggerCycle();

    resultListener.assertViewDefinitionCompiled(TIMEOUT);
    final ViewComputationResultModel result4 = resultListener.getCycleCompleted(TIMEOUT).getFullResult();
    assertEquals(0, resultListener.getQueueSize());

    assertEquals(1, result4.getAllResults().size());
    final ComputedValueResult result4Value = Iterables.getOnlyElement(result4.getAllResults()).getComputedValue();
    assertEquals("result2", result4Value.getValue());

    final AggregatedExecutionLog log4 = result4Value.getAggregatedExecutionLog();
    assertNotNull(log4);
    assertNull(log4.getLogs());
View Full Code Here

    return _objectName;
  }
 
  public synchronized boolean processResults() {
    CompiledViewDefinition compiledViewDef;
    ViewComputationResultModel viewComputationResultModel;
    synchronized (this) {
      compiledViewDef = _lastCompiledViewDefinition;
      viewComputationResultModel = _lastViewComputationResultModel;
    }
    if (compiledViewDef == null || viewComputationResultModel == null) {
View Full Code Here

    underlyingProvider.addValue(ViewProcessorTestEnvironment.getPrimitive2(), 456d);
    recalcThread.join();
    resultListener.assertCycleCompleted(TIMEOUT);

    final Map<String, Object> resultValues = new HashMap<String, Object>();
    final ViewComputationResultModel result = client.getLatestResult();
    final ViewTargetResultModel targetResult = result.getTargetResult(ViewProcessorTestEnvironment.getPrimitiveTarget());
    for (final ComputedValue computedValue : targetResult.getAllValues(ViewProcessorTestEnvironment.TEST_CALC_CONFIG_NAME)) {
      resultValues.put(computedValue.getSpecification().getValueName(), computedValue.getValue());
    }

    assertEquals(123d, resultValues.get(ViewProcessorTestEnvironment.getPrimitive1().getValueName()));
View Full Code Here

TOP

Related Classes of com.opengamma.engine.view.ViewComputationResultModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.