Package com.opengamma.engine.function

Examples of com.opengamma.engine.function.FunctionInvoker


    context.setRawComputationTargetResolver(new DefaultComputationTargetResolver());
    final CompiledFunctionService cfs = new CompiledFunctionService(repo, new CachingFunctionRepositoryCompiler(), context);
    cfs.initialize();
    final CompiledFunctionRepository compiledRepo = cfs.compileFunctionRepository(System.currentTimeMillis());
    assertNotNull(compiledRepo.getDefinition(definition.getUniqueId()));
    final FunctionInvoker invoker = compiledRepo.getInvoker(definition.getUniqueId());
    assertNotNull(invoker);
    assertTrue(invoker instanceof MockEmptyFunction);
    assertSame(definition, invoker);
  }
View Full Code Here


    return getUnderlyingCompiled().getLatestInvocationTime();
  }

  @Override
  public FunctionInvoker getFunctionInvoker() {
    final FunctionInvoker underlying = getUnderlyingCompiled().getFunctionInvoker();
    if (underlying == getUnderlyingInvoker()) {
      return this;
    } else {
      return create(underlying);
    }
View Full Code Here

        }
      });
    } else {
      target = LazyComputationTargetResolver.resolve(getTargetResolver(), jobItem.getComputationTargetSpecification());
    }
    final FunctionInvoker invoker = getFunctions().getInvoker(functionUniqueId);
    if (invoker == null) {
      postEvaluationErrors(outputs, MissingOutput.EVALUATION_ERROR);
      resultItemBuilder.withException(ERROR_BAD_FUNCTION, "Unable to locate " + functionUniqueId + " in function repository");
      return;
    }
    // set parameters
    getFunctionExecutionContext().setFunctionParameters(jobItem.getFunctionParameters());
    // assemble inputs
    final ValueSpecification[] inputValueSpecs = jobItem.getInputs();
    final Set<ValueSpecification> missing = Sets.newHashSetWithExpectedSize(inputValueSpecs.length);
    if (!isUseAsynchronousTargetResolve() && (target == null)) {
      if (invoker.canHandleMissingInputs()) {
        // A missing target is just a special case of missing input
        missing.add(TargetSourcingFunction.createSpecification(jobItem.getComputationTargetSpecification()));
      } else {
        postEvaluationErrors(outputs, MissingOutput.EVALUATION_ERROR);
        resultItemBuilder.withException(ERROR_CANT_RESOLVE, "Unable to resolve target " + jobItem.getComputationTargetSpecification());
        return;
      }
    }
    final Collection<ComputedValue> inputs = new ArrayList<ComputedValue>(inputValueSpecs.length);
    int inputBytes = 0;
    int inputSamples = 0;
    final DeferredViewComputationCache cache = getCache();
    _inputs._inputs = inputValueSpecs;
    for (final Pair<ValueSpecification, Object> input : cache.getValues(_inputs, getJob().getCacheSelectHint())) {
      if ((input.getSecond() == null) || (input.getSecond() instanceof MissingValue)) {
        missing.add(input.getFirst());
      } else {
        final ComputedValue value = new ComputedValue(input.getFirst(), input.getSecond());
        inputs.add(value);
        final Integer bytes = cache.estimateValueSize(value);
        if (bytes != null) {
          inputBytes += bytes;
          inputSamples++;
        }
      }
    }
    statistics.setDataInputBytes(inputBytes, inputSamples);
    if (!missing.isEmpty()) {
      if (invoker.canHandleMissingInputs()) {
        s_logger.debug("Executing even with missing inputs {}", missing);
        resultItemBuilder.withPartialInputs(missing);
      } else {
        s_logger.info("Not able to execute as missing inputs {}", missing);
        if (targetFuture != null) {
          // Cancelling doesn't do anything so we have to block and clear the result
          try {
            targetFuture.get();
          } catch (final Throwable t) {
            s_logger.warn("Error resolving target", t);
            postEvaluationErrors(outputs, MissingOutput.EVALUATION_ERROR);
            resultItemBuilder.withException(t);
            return;
          }
        }
        postEvaluationErrors(jobItem.getOutputs(), MissingOutput.MISSING_INPUTS);
        resultItemBuilder.withMissingInputs(missing);
        return;
      }
    }
    final FunctionInputs functionInputs = new FunctionInputsImpl(getTargetResolver().getSpecificationResolver(), inputs, missing);
    if (target == null) {
      try {
        target = targetFuture.get();
      } catch (final Throwable t) {
        s_logger.warn("Error resolving target", t);
        postEvaluationErrors(outputs, MissingOutput.EVALUATION_ERROR);
        resultItemBuilder.withException(t);
        return;
      }
      if (target == null) {
        if (invoker.canHandleMissingInputs()) {
          // A missing target is just a special case of missing input
          missing.add(new ValueSpecification(ValueRequirementNames.TARGET, jobItem.getComputationTargetSpecification(), ValueProperties.with(ValuePropertyNames.FUNCTION, "TargetSourcingFunction")
              .get()));
        } else {
          postEvaluationErrors(outputs, MissingOutput.EVALUATION_ERROR);
          resultItemBuilder.withException(ERROR_CANT_RESOLVE, "Unable to resolve target " + jobItem.getComputationTargetSpecification());
          return;
        }
      }
    }
    // Execute
    statistics.beginInvocation();
    Set<ComputedValue> result;
    try {
      result = invoker.execute(getFunctionExecutionContext(), functionInputs, target, plat2290(outputs));
    } catch (final AsynchronousExecution e) {
      s_logger.debug("Asynchronous execution of {} at {}", jobItem, _nodeId);
      final AsynchronousOperation<Deferred<Void>> async = deferredOperation();
      e.setResultListener(new ResultListener<Set<ComputedValue>>() {
        @Override
View Full Code Here

TOP

Related Classes of com.opengamma.engine.function.FunctionInvoker

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.