Package com.opengamma.engine

Examples of com.opengamma.engine.ComputationTarget


    for (final ResolutionRule rule : getRules()) {
      final CompiledFunctionDefinition function = rule.getParameterizedFunction().getFunction();
      if (!function.getTargetType().isCompatible(target.getType())) {
        continue;
      }
      final ComputationTarget adjustedTarget = rule.adjustTarget(adjustedTargetCache, target);
      final Set<ValueSpecification> results;
      try {
        results = rule.getResults(adjustedTarget, getContext());
        if (results == null) {
          continue;
View Full Code Here


      s_logger.debug("Recursive request for {}", requirement);
      return null;
    }
    final ComputationTargetSpecification targetSpec = getTargetSpecificationResolver().getTargetSpecification(
        ComputationTargetResolverUtils.simplifyType(requirement.getTargetReference(), getTargetResolver()));
    final ComputationTarget target = getTargetResolver().resolve(targetSpec);
    if (target == null) {
      s_logger.debug("Couldn't resolve target for {}", requirement);
      visited.remove(requirement);
      return null;
    }
    s_logger.debug("Partially resolving {}", requirement);
    for (final ResolutionRule rule : getRules()) {
      final CompiledFunctionDefinition function = rule.getParameterizedFunction().getFunction();
      if (!function.getTargetType().isCompatible(target.getType())) {
        continue;
      }
      final ComputationTarget adjustedTarget = rule.adjustTarget(adjustedTargetCache, target);
      final ValueSpecification result;
      try {
        result = rule.getResult(requirement.getValueName(), adjustedTarget, requirement.getConstraints(), getContext());
        if (result == null) {
          continue;
View Full Code Here

    } else if (adjusted == ComputationTargetType.NULL) {
      // Exact match
      return target;
    } else {
      // Type replacement
      return new ComputationTarget(target.toSpecification().replaceType(adjusted).getSpecification(), target.getValue());
    }
  }
View Full Code Here

    final ComputationTargetType type = getParameterizedFunction().getFunction().getTargetType();
    if (ComputationTargetType.NULL.equals(type)) {
      // We use NULL to mark failure in the cache, and NULL will never need adjusting
      return target;
    }
    ComputationTarget adjusted = adjustmentCache.get(type);
    if (adjusted == null) {
      adjusted = adjustTarget(type, target);
      if (adjusted != null) {
        adjustmentCache.put(type, adjusted);
      } else {
        // Store the failure
        adjustmentCache.put(type, ComputationTarget.NULL);
      }
    } else {
      if (ComputationTargetType.NULL.equals(adjusted.getType())) {
        // Got a failure from the cache
        adjusted = null;
      }
    }
    return adjusted;
View Full Code Here

    context.setComputationTargetResolver(context.getRawComputationTargetResolver().atVersionCorrection(VersionCorrection.of(Instant.now(), Instant.now())));
    return context;
  }

  public void testBasicResolution() {
    final ComputationTarget target = new ComputationTarget(ComputationTargetType.PRIMITIVE, UniqueId.of("scheme", "test_target"));
    final ParameterizedFunction parameterizedF1 = function(new PrimitiveTestFunction("req1"), "1");
    final ParameterizedFunction parameterizedF2 = function(new PrimitiveTestFunction("req1"), "2");
    final DefaultCompiledFunctionResolver resolver = new DefaultCompiledFunctionResolver(createFunctionCompilationContext());
    resolver.addRule(new ResolutionRule(parameterizedF1, ApplyToAllTargets.INSTANCE, 100));
    resolver.addRule(new ResolutionRule(parameterizedF2, ApplyToAllTargets.INSTANCE, 200));
View Full Code Here

    }

  }

  public void testFilteredRule() {
    final ComputationTarget target = new ComputationTarget(ComputationTargetType.PRIMITIVE, UniqueId.of("scheme", "test_target"));
    final ParameterizedFunction parameterizedF1 = function(new PrimitiveTestFunction("req1"), "1");
    final ParameterizedFunction parameterizedF2 = function(new PrimitiveTestFunction("req1"), "2");
    final DefaultCompiledFunctionResolver resolver = new DefaultCompiledFunctionResolver(createFunctionCompilationContext());
    resolver.addRule(new ResolutionRule(parameterizedF1, ApplyToAllTargets.INSTANCE, 100));
    resolver.addRule(new ResolutionRule(parameterizedF2, new Filter(target), 200));
    resolver.compileRules();
    Triple<ParameterizedFunction, ValueSpecification, Collection<ValueSpecification>> result = resolver.resolveFunction("req1", target, ValueProperties.none()).next();
    assertEquals(result.getFirst(), parameterizedF2);
    ComputationTarget anotherTarget = new ComputationTarget(ComputationTargetType.PRIMITIVE, UniqueId.of("scheme", "target2"));
    result = resolver.resolveFunction("req1", anotherTarget, ValueProperties.none()).next();
    assertEquals(result.getFirst(), parameterizedF1);
  }
View Full Code Here

    }

  }

  public void testSecurityFunction() {
    final ComputationTarget target = new ComputationTarget(ComputationTargetType.SECURITY, new MockSecurityA());
    final ParameterizedFunction pfn = function(new TestSecurityFunction(), "1");
    final DefaultCompiledFunctionResolver resolver = new DefaultCompiledFunctionResolver(createFunctionCompilationContext());
    resolver.addRule(new ResolutionRule(pfn, ApplyToAllTargets.INSTANCE, 0));
    resolver.compileRules();
    Triple<ParameterizedFunction, ValueSpecification, Collection<ValueSpecification>> result = resolver.resolveFunction("Value", target, ValueProperties.none()).next();
View Full Code Here

    final DefaultCompiledFunctionResolver resolver = new DefaultCompiledFunctionResolver(createFunctionCompilationContext());
    resolver.addRule(new ResolutionRule(pfn1, ApplyToAllTargets.INSTANCE, 0));
    resolver.addRule(new ResolutionRule(pfn2, ApplyToAllTargets.INSTANCE, 1));
    resolver.compileRules();
    Triple<ParameterizedFunction, ValueSpecification, Collection<ValueSpecification>> result = resolver.resolveFunction("Value",
        new ComputationTarget(ComputationTargetType.of(MockSecurityA.class), new MockSecurityA()), ValueProperties.none()).next();
    assertEquals(result.getFirst(), pfn2);
    result = resolver.resolveFunction("Value", new ComputationTarget(ComputationTargetType.of(MockSecurityB.class), new MockSecurityB()), ValueProperties.none()).next();
    assertEquals(result.getFirst(), pfn1);
  }
View Full Code Here

    Mockito.when(object.getUniqueId()).thenReturn(UniqueId.of(clazz.getSimpleName(), Integer.toString(object.hashCode())));
    return object;
  }

  public void testPositionFunction() {
    final ComputationTarget target = new ComputationTarget(ComputationTargetType.of(SimplePosition.class), mock(SimplePosition.class));
    final ParameterizedFunction pfn = function(new TestPositionFunction(), "1");
    final DefaultCompiledFunctionResolver resolver = new DefaultCompiledFunctionResolver(createFunctionCompilationContext());
    resolver.addRule(new ResolutionRule(pfn, ApplyToAllTargets.INSTANCE, 0));
    resolver.compileRules();
    Triple<ParameterizedFunction, ValueSpecification, Collection<ValueSpecification>> result = resolver.resolveFunction("Value", target, ValueProperties.none()).next();
    assertEquals(result.getFirst(), pfn);
    result = resolver.resolveFunction(
        "Value",
        new ComputationTarget(new ComputationTargetSpecification(ComputationTargetType.PORTFOLIO_NODE, UniqueId.of("Node", "0")).containing(ComputationTargetType.POSITION, target.getUniqueId()),
            target.getValue()), ValueProperties.none())
        .next();
    assertEquals(result.getFirst(), pfn);
  }
View Full Code Here

    }

  }

  public void testContextPositionFunction() {
    final ComputationTarget target = new ComputationTarget(ComputationTargetType.of(SimplePosition.class), mock(SimplePosition.class));
    final ParameterizedFunction pfn = function(new TestContextPositionFunction(), "1");
    final FunctionCompilationContext context = new FunctionCompilationContext();
    final ComputationTargetResolver.AtVersionCorrection targetResolver = Mockito.mock(ComputationTargetResolver.AtVersionCorrection.class);
    Mockito.when(targetResolver.resolve(target.toSpecification())).thenReturn(target);
    context.setComputationTargetResolver(targetResolver);
    final DefaultCompiledFunctionResolver resolver = new DefaultCompiledFunctionResolver(context);
    resolver.addRule(new ResolutionRule(pfn, ApplyToAllTargets.INSTANCE, 0));
    resolver.compileRules();
    assertFalse(resolver.resolveFunction("Value", target, ValueProperties.none()).hasNext());
    Triple<ParameterizedFunction, ValueSpecification, Collection<ValueSpecification>> result = resolver.resolveFunction(
        "Value", new ComputationTarget(new ComputationTargetSpecification(ComputationTargetType.PORTFOLIO_NODE, UniqueId.of("Node", "0")).containing(ComputationTargetType.of(SimplePosition.class),
            target.getUniqueId()), target.getValue()), ValueProperties.none()).next();
    assertEquals(result.getFirst(), pfn);
  }
View Full Code Here

TOP

Related Classes of com.opengamma.engine.ComputationTarget

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.