Package com.opengamma.engine.view.listener

Examples of com.opengamma.engine.view.listener.ViewResultListener


  protected void doRun() throws Exception {
    ViewProcessor viewProcessor = getToolContext().getViewProcessor();
    ConfigSource configSource = getToolContext().getConfigSource();
    String viewDefName = getCommandLine().getOptionValue(VIEW_DEF_NAME_OPTION);
    boolean batchMode = getCommandLine().hasOption(BATCH_MODE_OPTION);
    ViewResultListener listener;
    if (getCommandLine().hasOption(RESULT_LISTENER_CLASS_OPTION)) {
      String listenerClass = getCommandLine().getOptionValue(RESULT_LISTENER_CLASS_OPTION);
      listener = instantiate(listenerClass, ViewResultListener.class);
    } else {
      listener = null;
View Full Code Here


    vp.start();

    final ViewClient client = vp.createViewClient(ViewProcessorTestEnvironment.TEST_USER);
    client.setViewCycleAccessSupported(true);
    final List<EngineResourceReference<? extends ViewCycle>> references = new ArrayList<EngineResourceReference<? extends ViewCycle>>();
    final ViewResultListener resultListener = new AbstractViewResultListener() {

      @Override
      public void cycleCompleted(final ViewComputationResultModel fullResult, final ViewDeltaResultModel deltaResult) {
        final EngineResourceReference<? extends ViewCycle> reference = client.createLatestCycleReference();
        if (reference != null) {
View Full Code Here

  @Override
  public void heartbeatFailed(Exception e) {
    super.heartbeatFailed(e);
    terminateRemoteClient();
   
    ViewResultListener listener = _resultListener;
    if (listener != null) {
      listener.clientShutdown(e);
    }
  }
View Full Code Here

  //-------------------------------------------------------------------------
  @Override
  public void setResultListener(ViewResultListener newListener) {
    _listenerLock.lock();
    final ViewResultListener oldListener = _resultListener;
    try {
      _resultListener = newListener;
      if (oldListener == null && newListener != null) {
        incrementListenerDemand();
      } else if (oldListener != null && newListener == null) {
View Full Code Here

  //-------------------------------------------------------------------------
  @Override
  @SuppressWarnings("unchecked")
  protected void dispatchListenerCall(Function<?, ?> listenerCall) {
    ViewResultListener listener = _resultListener;
    if (listener != null) {
      try {
        ((Function<ViewResultListener, ?>) listenerCall).apply(listener);
      } catch (Exception e) {
        s_logger.warn("Exception notifying ViewClient listener of call " + listenerCall.getClass().getName(), e);
View Full Code Here

    viewClient.attachToViewProcess(viewId,
        ExecutionOptions.of(viewEvaluation.getExecutionSequence().createSequence(executionContext), getDefaultCycleOptions(executionContext), getViewExecutionFlags(desiredValues)), true);
    final TResultBuilder resultBuilder = createResultBuilder(viewEvaluation, desiredValues);
    final AsynchronousOperation<Set<ComputedValue>> async = AsynchronousOperation.createSet();
    final AtomicReference<ResultCallback<Set<ComputedValue>>> asyncResult = new AtomicReference<ResultCallback<Set<ComputedValue>>>(async.getCallback());
    viewClient.setResultListener(new ViewResultListener() {

      private void reportException(final RuntimeException e) {
        final ResultCallback<?> callback = asyncResult.getAndSet(null);
        if (callback != null) {
          try {
View Full Code Here

  //-------------------------------------------------------------------------
  private static StructuredMarketDataSnapshot makeSnapshot(final MarketDataSnapshotter marketDataSnapshotter,
      final ViewProcessor viewProcessor, final ViewDefinition viewDefinition, final ViewExecutionOptions viewExecutionOptions) throws InterruptedException {
    final ViewClient vc = viewProcessor.createViewClient(UserPrincipal.getLocalUser());
    vc.setResultListener(new ViewResultListener() {
      @Override
      public UserPrincipal getUser() {
        String ipAddress;
        try {
          ipAddress = InetAddress.getLocalHost().getHostAddress();
View Full Code Here

      final Pair<ViewProcessImpl, ViewResultListener> processAttachment = _clientToProcess.remove(clientId);
      if (processAttachment == null) {
        return;
      }
      final ViewProcessImpl process = processAttachment.getFirst();
      final ViewResultListener listener = processAttachment.getSecond();
      process.detachListener(listener);

      removeViewProcessIfUnused(process);
    } finally {
      _processLock.unlock();
View Full Code Here

    _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) {
View Full Code Here

      }
      detachFromViewProcess();
      getViewProcessor().removeViewClient(getUniqueId());
      _mergingViewProcessListener.terminate();
      _state = ViewClientState.TERMINATED;
      ViewResultListener listener = _userResultListener.get();
      if (listener != null) {
        listener.clientShutdown(null);
      }
    } finally {
      _clientLock.unlock();
    }
  }
View Full Code Here

TOP

Related Classes of com.opengamma.engine.view.listener.ViewResultListener

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.