Package com.opengamma.engine.view.execution

Examples of com.opengamma.engine.view.execution.ViewCycleExecutionOptions$Builder


  private synchronized void spawnWorker() {
    ViewCycleExecutionSequence sequence = getSequence();
    final int partitionSize = getPartitionSize();
    final List<ViewCycleExecutionOptions> partition = new ArrayList<ViewCycleExecutionOptions>(partitionSize);
    for (int i = 0; i < partitionSize; i++) {
      final ViewCycleExecutionOptions step = sequence.poll(getDefaultExecutionOptions());
      if (step != null) {
        partition.add(step);
      } else {
        break;
      }
View Full Code Here


  }

  // caller must hold the monitor
  protected void checkForRecompilation(final AbstractViewProcessWorkerContext primary, CompiledViewDefinitionWithGraphs compiled) {
    final ViewCycleExecutionSequence tailSequence = (getSecondary() == null) ? primary.getSequence().copy() : null;
    final ViewCycleExecutionOptions nextCycle = primary.getSequence().poll(getDefaultExecutionOptions());
    if (nextCycle != null) {
      final VersionCorrection vc = nextCycle.getResolverVersionCorrection();
      boolean changes = false;
      if ((vc == null) || VersionCorrection.LATEST.equals(vc)) {
        if (_resolverChanges == null) {
          _resolverChanges = new TargetResolverChangeListener() {
            @Override
View Full Code Here

  }

  protected InMemoryViewResultModel bootstrapCommonDataFromMessage(final FudgeDeserializer deserializer, final FudgeMsg message) {
    final UniqueId viewProcessId = message.getValue(UniqueId.class, FIELD_VIEWPROCESSID);
    final UniqueId viewCycleId = message.getValue(UniqueId.class, FIELD_VIEWCYCLEID);
    final ViewCycleExecutionOptions viewCycleExecutionOptions = deserializer.fieldValueToObject(ViewCycleExecutionOptions.class, message.getByName(FIELD_VIEW_CYCLE_EXECUTION_OPTIONS));
    final Instant calculationTime = message.getFieldValue(Instant.class, message.getByName(FIELD_CALCULATION_TIME));
    FudgeField durationField = message.getByName(FIELD_CALCULATION_DURATION);
    final Duration calculationDuration = durationField != null ? deserializer.fieldValueToObject(Duration.class, durationField) : null;
    final VersionCorrection versionCorrection = deserializer.fieldValueToObject(VersionCorrection.class, message.getByName(FIELD_VERSION_CORRECTION));
    final Map<String, ViewCalculationResultModel> configurationMap = new HashMap<String, ViewCalculationResultModel>();
View Full Code Here

    }
  }

  // TEMPORARY CODE - This method should be removed post credit work and supports Excel (Jim)
  private ViewExecutionOptions verifyLiveDataViewExecutionOptions(final ViewExecutionOptions executionOptions) {
    ViewCycleExecutionOptions defaultExecutionOptions = executionOptions.getDefaultExecutionOptions();
    if (defaultExecutionOptions != null) {
      List<MarketDataSpecification> specifications = defaultExecutionOptions.getMarketDataSpecifications();
      if (!specifications.isEmpty()) {
        specifications = new ArrayList<>(specifications);
        boolean changed = false;
        for (int i = 0; i < specifications.size(); i++) {
          final MarketDataSpecification specification = specifications.get(i);
          if (specification instanceof LiveMarketDataSpecification) {
            final String dataSource = ((LiveMarketDataSpecification) specification).getDataSource();
            if (dataSource != null && getNamedMarketDataSpecificationRepository() != null) {
              final MarketDataSpecification namedSpec = getNamedMarketDataSpecificationRepository().getSpecification(dataSource);
              if (namedSpec != null && !namedSpec.equals(specification)) {
                s_logger.info("Replacing live data {} with named spec {}", dataSource, namedSpec);
                specifications.set(i, namedSpec);
                changed = true;
              }
            }
          }
        }
        if (changed) {
          ViewCycleExecutionOptions defaultOptions = defaultExecutionOptions.copy()
              .setMarketDataSpecifications(specifications)
              .create();
          return new ExecutionOptions(executionOptions.getExecutionSequence(), executionOptions.getFlags(),
              executionOptions.getMaxSuccessiveDeltaCycles(), defaultOptions);
        }
View Full Code Here

    return msg;
  }

  @Override
  public CycleExecutionFailedCall buildObject(FudgeDeserializer deserializer, FudgeMsg msg) {
    ViewCycleExecutionOptions cycleExecutionOptions = deserializer.fieldValueToObject(ViewCycleExecutionOptions.class, msg.getByName(EXECUTION_OPTIONS_FIELD));
    FudgeField exceptionField = msg.getByName(EXCEPTION_FIELD);
    Exception exception = exceptionField != null ? deserializer.fieldValueToObject(Exception.class, exceptionField) : null;
    return new CycleExecutionFailedCall(cycleExecutionOptions, exception);
  }
View Full Code Here

    do {
      vc = viewCycleOptions.getResolverVersionCorrection();
      if (vc != null) {
        break;
      }
      final ViewCycleExecutionOptions options = getExecutionOptions().getDefaultExecutionOptions();
      if (options != null) {
        vc = options.getResolverVersionCorrection();
        if (vc != null) {
          break;
        }
      }
      vc = VersionCorrection.LATEST;
View Full Code Here

      try {
        cycleType = waitForNextCycle();
      } catch (final InterruptedException e) {
        return;
      }
      ViewCycleExecutionOptions executionOptions = null;
      try {
        if (!getExecutionOptions().getExecutionSequence().isEmpty()) {
          executionOptions = getExecutionOptions().getExecutionSequence().poll(getExecutionOptions().getDefaultExecutionOptions());
          s_logger.debug("Next cycle execution options: {}", executionOptions);
        }
        if (executionOptions == null) {
          s_logger.info("No more view cycle execution options");
          jobCompleted();
          return;
        }
      } catch (final Exception e) {
        s_logger.error("Error obtaining next view cycle execution options from sequence for " + getWorkerContext(), e);
        return;
      }

      if (executionOptions.getMarketDataSpecifications().isEmpty()) {
        s_logger.error("No market data specifications for cycle");
        cycleExecutionFailed(executionOptions, new OpenGammaRuntimeException("No market data specifications for cycle"));
        return;
      }

      SnapshotManager snapshotManager;

      try {
        snapshotManager = _marketDataManager.createSnapshotManagerForCycle(getViewDefinition().getMarketDataUser(), executionOptions.getMarketDataSpecifications());
        _executionCacheKey = ViewExecutionCacheKey.of(getViewDefinition(), _marketDataManager.getAvailabilityProvider());
      } catch (final Exception e) {
        s_logger.error("Error with market data provider", e);
        cycleExecutionFailed(executionOptions, new OpenGammaRuntimeException("Error with market data provider", e));
        return;
      }

      Instant compilationValuationTime;
      try {
        if (executionOptions.getValuationTime() != null) {
          compilationValuationTime = executionOptions.getValuationTime();
        } else {
          // Neither the cycle-specific options nor the defaults have overridden the valuation time so use the time
          // associated with the market data snapshot. To avoid initialising the snapshot perhaps before the required
          // inputs are known or even subscribed to, only ask for an indication at the moment.
          compilationValuationTime = snapshotManager.getSnapshotTimeIndication();
          if (compilationValuationTime == null) {
            throw new OpenGammaRuntimeException("Market data snapshot " + snapshotManager + " produced a null indication of snapshot time");
          }
        }
      } catch (final Exception e) {
        s_logger.error("Error obtaining compilation valuation time", e);
        cycleExecutionFailed(executionOptions, new OpenGammaRuntimeException("Error obtaining compilation valuation time", e));
        return;
      }

      final VersionCorrection versionCorrection = getResolverVersionCorrection(executionOptions);
      VersionCorrectionUtils.lock(versionCorrection);
      try {
        final CompiledViewDefinitionWithGraphs compiledViewDefinition;
        try {
          // Don't query the cache so that the process gets a "compiled" message even if a cached compilation is used
          final CompiledViewDefinitionWithGraphs previous = _latestCompiledViewDefinition;
          if (_ignoreCompilationValidity && (previous != null) && CompiledViewDefinitionWithGraphsImpl.isValidFor(previous, compilationValuationTime)) {
            compiledViewDefinition = previous;
          } else {
            compiledViewDefinition = getCompiledViewDefinition(compilationValuationTime, versionCorrection);
            if (compiledViewDefinition == null) {
              s_logger.warn("Job terminated during view compilation");
              return;
            }
            if ((previous == null) || !previous.getCompilationIdentifier().equals(compiledViewDefinition.getCompilationIdentifier())) {
              if (_targetResolverChanges != null) {
                // We'll try to register for changes that will wake us up for a cycle if market data is not ticking
                if (previous != null) {
                  final Set<UniqueId> subscribedIds = new HashSet<>(previous.getResolvedIdentifiers().values());
                  for (UniqueId uid : compiledViewDefinition.getResolvedIdentifiers().values()) {
                    if (!subscribedIds.contains(uid)) {
                      _targetResolverChanges.watch(uid.getObjectId());
                    }
                  }
                } else {
                  for (UniqueId uid : compiledViewDefinition.getResolvedIdentifiers().values()) {
                    _targetResolverChanges.watch(uid.getObjectId());
                  }
                }
              }
              viewDefinitionCompiled(compiledViewDefinition);
            }
          }
        } catch (final Exception e) {
          final String message = MessageFormat.format("Error obtaining compiled view definition {0} for time {1} at version-correction {2}", getViewDefinition().getUniqueId(),
              compilationValuationTime, versionCorrection);
          s_logger.error(message);
          cycleExecutionFailed(executionOptions, new OpenGammaRuntimeException(message, e));
          return;
        }
        // [PLAT-1174] This is necessary to support global injections by ValueRequirement. The use of a process-context level variable will be bad
        // if there are multiple worker threads that initialise snapshots concurrently.
        getProcessContext().getLiveDataOverrideInjector().setComputationTargetResolver(
            getProcessContext().getFunctionCompilationService().getFunctionCompilationContext().getRawComputationTargetResolver().atVersionCorrection(versionCorrection));

        try {
          snapshotManager.addMarketDataRequirements(compiledViewDefinition.getMarketDataRequirements());
          if (getExecutionOptions().getFlags().contains(ViewExecutionFlags.AWAIT_MARKET_DATA)) {
            snapshotManager.initialiseSnapshotWithSubscriptionResults();
          } else {
            snapshotManager.initialiseSnapshot();
          }
          if (executionOptions.getValuationTime() == null) {
            executionOptions = executionOptions.copy().setValuationTime(snapshotManager.getSnapshotTime()).create();
          }
        } catch (final Exception e) {
          s_logger.error("Error initializing snapshot {}", snapshotManager);
          cycleExecutionFailed(executionOptions, new OpenGammaRuntimeException("Error initializing snapshot " + snapshotManager, e));
        }

        if (_executeCycles) {
          EngineResourceReference<SingleComputationCycle> cycleReference;
          try {
            cycleReference = createCycle(executionOptions, compiledViewDefinition, versionCorrection);
          } catch (final Exception e) {
            s_logger.error("Error creating next view cycle for " + getWorkerContext(), e);
            return;
          }
          try {
            try {
              final SingleComputationCycle singleComputationCycle = cycleReference.get();
              final Map<String, Collection<ComputationTargetSpecification>> configToComputationTargets = new HashMap<>();
              final Map<String, Map<ValueSpecification, Set<ValueRequirement>>> configToTerminalOutputs = new HashMap<>();
              final MarketDataSnapshot marketDataSnapshot = snapshotManager.getSnapshot();

              for (DependencyGraphExplorer graphExp : compiledViewDefinition.getDependencyGraphExplorers()) {
                final DependencyGraph graph = graphExp.getWholeGraph();
                configToComputationTargets.put(graph.getCalculationConfigurationName(), graph.getAllComputationTargets());
                configToTerminalOutputs.put(graph.getCalculationConfigurationName(), graph.getTerminalOutputs());
              }
              if (isTerminated()) {
                return;
              }
              cycleStarted(new DefaultViewCycleMetadata(
                  cycleReference.get().getUniqueId(),
                  marketDataSnapshot.getUniqueId(),
                  compiledViewDefinition.getViewDefinition().getUniqueId(),
                  versionCorrection,
                  executionOptions.getValuationTime(),
                  singleComputationCycle.getAllCalculationConfigurationNames(),
                  configToComputationTargets,
                  configToTerminalOutputs));
              if (isTerminated()) {
                return;
View Full Code Here

    Integer maxSuccessiveDeltaCycles = null;
    if (message.hasField(MAX_SUCCESSIVE_DELTA_CYCLES_FIELD)) {
      maxSuccessiveDeltaCycles = message.getInt(MAX_SUCCESSIVE_DELTA_CYCLES_FIELD);
    }
    FudgeField defaultExecutionOptionsField = message.getByName(DEFAULT_EXECUTION_OPTIONS_FIELD);
    ViewCycleExecutionOptions defaultExecutionOptions = defaultExecutionOptionsField != null ?
        deserializer.fieldValueToObject(ViewCycleExecutionOptions.class, defaultExecutionOptionsField) : null;

    return new ExecutionOptions(executionSequence, flags, maxSuccessiveDeltaCycles, defaultExecutionOptions);
  }
View Full Code Here

  public void rountTrip() {
    Map<DistinctMarketDataSelector, FunctionParameters> selectors2params = Maps.newHashMap();
    Map<String, String> params = ImmutableMap.of("foo", "bar");
    DistinctMarketDataSelector selector = YieldCurveSelector.of(new YieldCurveKey(Currency.AUD, "curveKey"));
    selectors2params.put(selector, new SimpleFunctionParameters(params));
    ViewCycleExecutionOptions options =
        ViewCycleExecutionOptions
            .builder()
            .setValuationTime(Instant.now())
            .setMarketDataSelector(CompositeMarketDataSelector.of(selectors2params.keySet()))
            .setFunctionParameters(selectors2params)
View Full Code Here

    vp.start();

    final ViewClient client = vp.createViewClient(ViewProcessorTestEnvironment.TEST_USER);
    final TestViewResultListener resultListener = new TestViewResultListener();
    client.setResultListener(resultListener);
    final ViewCycleExecutionOptions cycleExecutionOptions = ViewCycleExecutionOptions.builder().setValuationTime(Instant.now()).setMarketDataSpecification(MarketData.live()).create();
    final EnumSet<ViewExecutionFlags> flags = ExecutionFlags.none().awaitMarketData().get();
    final ViewExecutionOptions executionOptions = ExecutionOptions.of(ArbitraryViewCycleExecutionSequence.single(cycleExecutionOptions), flags);
    client.attachToViewProcess(env.getViewDefinition().getUniqueId(), executionOptions);

    resultListener.assertViewDefinitionCompiled(TIMEOUT);
View Full Code Here

TOP

Related Classes of com.opengamma.engine.view.execution.ViewCycleExecutionOptions$Builder

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.