Examples of ViewClient


Examples of com.opengamma.engine.view.client.ViewClient

    env.setViewResultListenerFactory(viewResultListenerFactoryStub);
    env.init();
    final ViewProcessorImpl vp = env.getViewProcessor();
    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) {
          references.add(reference);
        }
      }

      @Override
      public UserPrincipal getUser() {
        return UserPrincipal.getTestUser();
      }

    };
    client.setResultListener(resultListener);
    final ViewExecutionOptions executionOptions = ExecutionOptions.batch(generateExecutionSequence(10), ViewCycleExecutionOptions.builder().setMarketDataSpecification(MarketData.live()).create());
    client.attachToViewProcess(env.getViewDefinition().getUniqueId(), executionOptions);

    final ViewProcessImpl viewProcess = env.getViewProcess(vp, client.getUniqueId());
    final UniqueId viewProcessId = viewProcess.getUniqueId();

    waitForCompletionAndShutdown(vp, client, env);

    assertEquals(10, references.size());
View Full Code Here

Examples of com.opengamma.engine.view.client.ViewClient

    if (_valueRequirementNames.isEmpty()) {
      return statusResult;
    }
    final ViewDefinition viewDefinition = createViewDefinition();
    final ViewProcessor viewProcessor = _toolContext.getViewProcessor();
    final ViewClient client = viewProcessor.createViewClient(_user);

    final CountDownLatch latch = new CountDownLatch(1);
    client.setResultListener(new ViewStatusResultListener(latch, statusResult, viewDefinition));
    client.attachToViewProcess(viewDefinition.getUniqueId(), ExecutionOptions.infinite(_marketDataSpecification));
  
    try {
      s_logger.info("main thread waiting");
      if (!latch.await(30, TimeUnit.SECONDS)) {
        s_logger.error("Timed out waiting for {}", viewDefinition);
      }
    } catch (final InterruptedException ex) {
      throw new OpenGammaRuntimeException("Interrupted while waiting for " + viewDefinition, ex);
    }
    client.detachFromViewProcess();
    removeViewDefinition(viewDefinition);
    s_logger.debug("PerViewStatusResult for securityType:{} is {}", _securityType, statusResult);
    return statusResult;
  }
View Full Code Here

Examples of com.opengamma.engine.view.client.ViewClient

    final UniqueId viewId = storeViewDefinition(executionContext, target.getUniqueId(), viewEvaluation.getViewDefinition());
    final ViewProcessor viewProcessor = OpenGammaExecutionContext.getViewProcessor(executionContext);
    if (viewProcessor == null) {
      throw new IllegalStateException("Execution context does not contain a " + OpenGammaExecutionContext.VIEW_PROCESSOR_NAME);
    }
    final ViewClient viewClient = viewProcessor.createViewClient(viewEvaluation.getViewDefinition().getMarketDataUser());
    final UniqueId viewClientId = viewClient.getUniqueId();
    s_logger.info("Created view client {}, connecting to {}", viewClientId, viewId);
    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 {
            callback.setException(e);
          } finally {
            s_logger.info("Shutting down view client {}", viewClientId);
            viewClient.shutdown();
          }
        } else {
          s_logger.warn("Callback already made before exception for {}", viewClientId);
        }
      }

      private void reportResult(final Set<ComputedValue> values) {
        final ResultCallback<Set<ComputedValue>> callback = asyncResult.getAndSet(null);
        if (callback != null) {
          try {
            callback.setResult(values);
          } finally {
            s_logger.info("Shutting down view client {}", viewClientId);
            viewClient.shutdown();
          }
        } else {
          s_logger.warn("Callback already made before results for {}", viewClientId);
        }
      }

      @Override
      public UserPrincipal getUser() {
        return viewEvaluation.getViewDefinition().getMarketDataUser();
      }

      @Override
      public void viewDefinitionCompiled(final CompiledViewDefinition compiledViewDefinition, final boolean hasMarketDataPermissions) {
        s_logger.debug("View definition compiled for {}", viewClientId);
        try {
          store(compiledViewDefinition, resultBuilder);
        } catch (final RuntimeException e) {
          s_logger.error("Caught exception during compilation completed callback", e);
          reportException(e);
        }
      }

      @Override
      public void viewDefinitionCompilationFailed(final Instant valuationTime, final Exception exception) {
        s_logger.error("View compilation failure for {} - {}", viewClientId, exception);
        reportException(new OpenGammaRuntimeException("View definition compilation failed for " + valuationTime, exception));
      }

      @Override
      public void cycleStarted(final ViewCycleMetadata cycleMetadata) {
        // This is good. Don't need to do anything.
        s_logger.debug("Cycle started for {}", viewClientId);
      }

      @Override
      public void cycleFragmentCompleted(final ViewComputationResultModel fullFragment, final ViewDeltaResultModel deltaFragment) {
        // This shouldn't happen. We've asked for full results only
        s_logger.error("Cycle fragment completed for {}", viewClientId);
        reportException(new OpenGammaRuntimeException("Assertion error"));
        assert false;
      }

      @Override
      public void cycleCompleted(final ViewComputationResultModel fullResult, final ViewDeltaResultModel deltaResult) {
        s_logger.debug("Cycle completed for {}", viewClientId);
        try {
          store(fullResult, resultBuilder);
        } catch (final RuntimeException e) {
          s_logger.error("Caught exception during cycle completed callback", e);
          reportException(e);
        }
      }

      @Override
      public void cycleExecutionFailed(final ViewCycleExecutionOptions executionOptions, final Exception exception) {
        s_logger.error("Cycle execution failed for {}", viewClientId);
        reportException(new OpenGammaRuntimeException("View cycle execution failed for " + executionOptions, exception));
      }

      @Override
      public void processCompleted() {
        s_logger.info("View process completed for {}", viewClientId);
        try {
          Set<ComputedValue> results = buildResults(target, resultBuilder);
          reportResult(results);
        } catch (final RuntimeException e) {
          s_logger.error("Caught exception during process completed callback", e);
          reportException(e);
        }
      }

      @Override
      public void processTerminated(final boolean executionInterrupted) {
        // Normally we would have expected one of the other notifications, so if the callback exists we report an error
        final ResultCallback<?> callback = asyncResult.getAndSet(null);
        if (callback != null) {
          s_logger.error("View process terminated for {}", viewClientId);
          reportException(new OpenGammaRuntimeException(executionInterrupted ? "Execution interrupted" : "View process terminated"));
        } else {
          s_logger.debug("View process terminated for {}", viewClientId);
        }
      }

      @Override
      public void clientShutdown(final Exception e) {
        // Normally we would have expected one of the other notifications or this in response to us calling "shutdown", so if the callback exists we report an error
        final ResultCallback<?> callback = asyncResult.getAndSet(null);
        if (callback != null) {
          s_logger.error("View client shutdown for {}", viewClientId);
          reportException(new OpenGammaRuntimeException("View client shutdown", e));
        } else {
          s_logger.debug("View client shutdown for {}", viewClientId);
        }
      }

    });
    viewClient.triggerCycle();
    return async.getResult();
  }
View Full Code Here

Examples of com.opengamma.engine.view.client.ViewClient

  public PortfolioPaymentDiary getPortfolioPaymentDiary(final UniqueId portfolioId) {
    Portfolio portfolio = getPositionSource().getPortfolio(portfolioId, VersionCorrection.LATEST);
    portfolio = PortfolioCompiler.resolvePortfolio(portfolio, Executors.newSingleThreadExecutor(), getSecuritySource());
    final UniqueId viewDefinitionId = getPaymentViewDefinition(portfolio);

    final ViewClient viewClient = getViewProcessor().createViewClient(UserPrincipal.getTestUser());
    viewClient.attachToViewProcess(viewDefinitionId, ExecutionOptions.singleCycle(Instant.now(), MarketData.live()));
    ViewComputationResultModel result;
    try {
      viewClient.waitForCompletion();
      result = viewClient.getLatestResult();
    } catch (final InterruptedException e) {
      throw new OpenGammaRuntimeException("Interrupted while waiting for payment diary calculations");
    } finally {
      viewClient.shutdown();
    }
    if (result == null) {
      throw new OpenGammaRuntimeException("Cash flow view failed to run");
    }
    final PortfolioPaymentDiary paymentDiary = new PortfolioPaymentDiary();
View Full Code Here

Examples of com.opengamma.engine.view.client.ViewClient

    final Set<ExternalId> emittedRecently = Sets.newHashSet();
    final Instant now = OffsetDateTime.ofInstant(Instant.now(), ZoneOffset.UTC).with(LocalTime.NOON).toInstant();
    s_logger.info("{} view(s) defined in demo view processor", viewDefinitions.size());
    _writer.println("# Automatically generated");

    final ViewClient client = _viewProcessor.createViewClient(UserPrincipal.getLocalUser());
    final List<CompiledViewDefinition> compilations = new LinkedList<CompiledViewDefinition>();
    client.setResultListener(new AbstractViewResultListener() {

      @Override
      public UserPrincipal getUser() {
        return UserPrincipal.getLocalUser();
      }

      @Override
      public void viewDefinitionCompiled(final CompiledViewDefinition compiledViewDefinition, final boolean hasMarketDataPermissions) {
        compilations.add(compiledViewDefinition);
      }

      @Override
      public void viewDefinitionCompilationFailed(final Instant valuationTime, final Exception exception) {
        s_logger.error("Error while compiling view definition " + viewDefinitions + " for instant " + valuationTime, exception);
      }

    });

    for (final ConfigItem<ViewDefinition> viewDefinition : viewDefinitions) {

      if (viewDefinition.getName().startsWith("10K")) {
        // Don't do the huge ones!
        s_logger.warn("Skipping {}", viewDefinition);
        _writer.println();
        _writer.print("# Skipping ");
        _writer.println(viewDefinition);
        continue;
      }

      s_logger.debug("Compiling view {}", viewDefinition);
      _writer.println();
      _writer.println("# " + viewDefinition);

      client.attachToViewProcess(viewDefinition.getUniqueId(), generateExecutionOptions(now));
      try {
        client.waitForCompletion();
      } catch (final InterruptedException e) {
        s_logger.warn("Interrupted while waiting for '{}' to complete" + viewDefinition);
      }
      client.detachFromViewProcess();

      if (compilations.size() == 0) {
        _writer.println("# ERROR - Failed to compile " + viewDefinition);
      } else {
        _writer.println("# " + compilations.size() + " different compilations of " + viewDefinition + " for the next " + VALIDITY_PERIOD_DAYS + " days");
      }

      for (int i = 0; i < compilations.size(); i++) {
        final CompiledViewDefinition compilation = compilations.get(i);
        final Set<ValueSpecification> liveData = compilation.getMarketDataRequirements();
        s_logger.info("{} live data requirements for view {} for compilation {}", new Object[] {liveData.size(), viewDefinition, compilation.toString() });
        _writer.println("# " + (i + 1) + " of " + compilations.size() + " - " + compilation);
        for (final ValueSpecification specification : liveData) {
          s_logger.debug("Specification {}", specification);
          emitSpecification(specification, emitted, emittedRecently);
        }
        _writer.flush();
        emittedRecently.clear();
      }

      compilations.clear();
    }
    client.shutdown();
    addInterestRates(emitted);
  }
View Full Code Here

Examples of com.opengamma.engine.view.client.ViewClient

    return treeTableModel;
  }

  protected void startViewer(final ViewProcessor viewProcessor) {
    final UserPrincipal user = UserPrincipal.getLocalUser();
    final ViewClient viewClient = viewProcessor.createViewClient(user);
    final PortfolioTreeTableModel treeTableModel = buildTreeTableModel();
    viewClient.setResultListener(treeTableModel);
    viewClient.attachToViewProcess(viewProcessor.getConfigSource().getSingle(ViewDefinition.class, "Equity Portfolio View", VersionCorrection.LATEST).getUniqueId(),
        ExecutionOptions.infinite(MarketData.live()));

    getMainFrame().setTitle("OpenGamma Viewer");

    final JXTreeTable treeTable = new JXTreeTable(treeTableModel);
View Full Code Here

Examples of com.opengamma.engine.view.client.ViewClient

  }

  //-------------------------------------------------------------------------
  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();
        } catch (final UnknownHostException e) {
          ipAddress = "unknown";
        }
        return new UserPrincipal("MarketDataSnapshotterTool", ipAddress);
      }

      @Override
      public void viewDefinitionCompiled(final CompiledViewDefinition compiledViewDefinition, final boolean hasMarketDataPermissions) {
      }

      @Override
      public void viewDefinitionCompilationFailed(final Instant valuationTime, final Exception exception) {
        s_logger.error(exception.getMessage() + "\n\n" + (exception.getCause() == null ? "" : exception.getCause().getMessage()));
      }

      @Override
      public void cycleStarted(final ViewCycleMetadata cycleMetadata) {
      }

      @Override
      public void cycleFragmentCompleted(final ViewComputationResultModel fullFragment, final ViewDeltaResultModel deltaFragment) {
      }

      @Override
      public void cycleCompleted(final ViewComputationResultModel fullResult, final ViewDeltaResultModel deltaResult) {
        s_logger.info("cycle completed");
      }

      @Override
      public void cycleExecutionFailed(final ViewCycleExecutionOptions executionOptions, final Exception exception) {
        s_logger.error(exception.getMessage() + "\n\n" + (exception.getCause() == null ? "" : exception.getCause().getMessage()));
      }

      @Override
      public void processCompleted() {
      }

      @Override
      public void processTerminated(final boolean executionInterrupted) {
      }

      @Override
      public void clientShutdown(final Exception e) {
      }
    });
    vc.setViewCycleAccessSupported(true);
    vc.attachToViewProcess(viewDefinition.getUniqueId(), viewExecutionOptions);

    vc.waitForCompletion();
    vc.pause();
    EngineResourceReference<? extends ViewCycle> cycleReference = null;
    try {
      cycleReference = vc.createLatestCycleReference();
      return marketDataSnapshotter.createSnapshot(vc, cycleReference.get());
    } finally {
      cycleReference.release();
      vc.shutdown();
    }
  }
View Full Code Here

Examples of com.opengamma.engine.view.client.ViewClient

      appContext = getApplicationContext();
      appContext.start();

      ViewProcessor viewProcessor = appContext.getBean("viewProcessor", ViewProcessor.class);

      ViewClient viewClient = viewProcessor.createViewClient(UserPrincipal.getLocalUser());
      MarketDataSpecification marketDataSpec = new FixedHistoricalMarketDataSpecification(s_observationDateTime.toLocalDate());
      ViewCycleExecutionOptions cycleOptions = ViewCycleExecutionOptions.builder().setValuationTime(s_valuationInstant).setMarketDataSpecification(marketDataSpec)
          .setResolverVersionCorrection(VersionCorrection.of(s_versionAsOf, s_correctedTo)).create();
      ViewCycleExecutionSequence executionSequence = ArbitraryViewCycleExecutionSequence.of(cycleOptions);

      ExecutionOptions executionOptions = new ExecutionOptions(executionSequence, ExecutionFlags.none().awaitMarketData().get(), null, null);

      viewClient.attachToViewProcess(UniqueId.parse(s_viewDefinitionUid), executionOptions);
    } finally {
      if (appContext != null) {
        appContext.close();
      }
    }
View Full Code Here

Examples of com.opengamma.engine.view.client.ViewClient

  @GET
  @Path(PATH_CREATE_SNAPSHOT + "/{viewClientId}" + "/{viewCycleId}")
  public Response createSnapshot(@PathParam("viewClientId") String viewClientIdString, @PathParam("viewCycleId") String viewCycleIdString) {
    UniqueId viewClientId = UniqueId.parse(viewClientIdString);
    UniqueId viewCycleId = UniqueId.parse(viewCycleIdString);
    ViewClient client = _viewProcessor.getViewClient(viewClientId);
    EngineResourceReference<? extends ViewCycle> cycleReference = client.createCycleReference(viewCycleId);
    if (cycleReference == null) {
      throw new IllegalArgumentException("Cycle is not available");
    }
    try {
      StructuredMarketDataSnapshot result = _snapshotter.createSnapshot(client, cycleReference.get());
View Full Code Here

Examples of com.opengamma.engine.view.client.ViewClient

  @GET
  @Path(PATH_YIELD_CURVE_SPECS + "/{viewClientId}" + "/{viewCycleId}")
  public Response getYieldCurveSpecs(@PathParam("viewClientId") String viewClientIdString, @PathParam("viewCycleId") String viewCycleIdString) {
    UniqueId viewClientId = UniqueId.parse(viewClientIdString);
    UniqueId viewCycleId = UniqueId.parse(viewCycleIdString);
    ViewClient client = _viewProcessor.getViewClient(viewClientId);
    EngineResourceReference<? extends ViewCycle> cycleReference = client.createCycleReference(viewCycleId);

    if (cycleReference == null) {
      throw new IllegalArgumentException("Cycle is not available");
    }
    try {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.