Package com.opengamma.livedata

Examples of com.opengamma.livedata.LiveDataSpecification


  /**
   * @param securityUniqueId Security unique ID
   * @return A {@code LiveDataSpecification} with default normalization rule used.
   */
  public LiveDataSpecification getLiveDataSpecification(String securityUniqueId) {
    return new LiveDataSpecification(
        getDefaultNormalizationRuleSetId(),
        ExternalId.of(getUniqueIdDomain(), securityUniqueId));
  }
View Full Code Here


   * @param persistent See {@link MarketDataDistributor#isPersistent()}
   * @return Whether the subscription succeeded or failed
   * @see #getDefaultNormalizationRuleSetId()
   */
  public LiveDataSubscriptionResponse subscribe(String securityUniqueId, boolean persistent) {
    LiveDataSpecification liveDataSpecification = getLiveDataSpecification(securityUniqueId);
    return subscribe(liveDataSpecification, persistent);
  }
View Full Code Here

        if (distributionSpec == null) {
          s_logger.info("Unable to work out distribution spec for specification " + specFromClient);
          responses.add(buildErrorMessageResponse(specFromClient, LiveDataSubscriptionResult.NOT_PRESENT, "Unable to work out distribution spec"));
          continue;
        }
        final LiveDataSpecification fullyQualifiedSpec = distributionSpec.getFullyQualifiedLiveDataSpecification();
        Subscription subscription = getSubscription(fullyQualifiedSpec);
        if (subscription != null) {
          s_logger.info("Already subscribed to {}", fullyQualifiedSpec);
          responses.add(buildSubscriptionResponse(specFromClient, distributionSpec));
        } else {
          String securityUniqueId = fullyQualifiedSpec.getIdentifier(getUniqueIdDomain());
          if (securityUniqueId == null) {
            String errorMsg = "Qualified spec " + fullyQualifiedSpec + " does not contain ID of domain " + getUniqueIdDomain();
            responses.add(buildErrorMessageResponse(specFromClient, LiveDataSubscriptionResult.INTERNAL_ERROR, errorMsg));
            continue;
          }
          subscription = new Subscription(securityUniqueId, getMarketDataSenderFactory(), getLkvStoreProvider());
          securityUniqueId2NewSubscription.put(subscription.getSecurityUniqueId(), subscription);
          securityUniqueId2SpecFromClient.put(subscription.getSecurityUniqueId(), specFromClient);
        }
        subscription.createDistributor(distributionSpec, persistent).setExpiry(distributionExpiryTime);
      }

      //Allow checks here, before we do the snapshot or the subscribe
      checkSubscribe(securityUniqueId2NewSubscription.keySet());

      // In some cases, the underlying market data API may not, when the subscription is started,
      // return a full image of all fields. If so, we need to get the full image explicitly.
      Collection<String> newSubscriptionsForWhichSnapshotIsRequired = new ArrayList<>();
      for (Subscription subscription : securityUniqueId2NewSubscription.values()) {
        if (snapshotOnSubscriptionStartRequired(subscription)) {
          newSubscriptionsForWhichSnapshotIsRequired.add(subscription.getSecurityUniqueId());
        }
      }

      s_logger.info("Subscription snapshot required for {}", newSubscriptionsForWhichSnapshotIsRequired);
      Map<String, FudgeMsg> snapshots = doSnapshot(newSubscriptionsForWhichSnapshotIsRequired);
      for (Map.Entry<String, FudgeMsg> snapshot : snapshots.entrySet()) {
        Subscription subscription = securityUniqueId2NewSubscription.get(snapshot.getKey());
        subscription.initialSnapshotReceived(snapshot.getValue());
      }

      // Setup the subscriptions in the underlying data provider.
      for (Subscription subscription : securityUniqueId2NewSubscription.values()) {
        // this is necessary so we don't lose any updates immediately after doSubscribe(). See AbstractLiveDataServer#liveDataReceived()
        // and how it calls AbstractLiveDataServer#getSubscription()
        _securityUniqueId2Subscription.put(subscription.getSecurityUniqueId(), subscription);
      }

      s_logger.info("Creating underlying market data API subscription to {}", securityUniqueId2NewSubscription.keySet());
      Map<String, Object> subscriptionHandles = doSubscribe(securityUniqueId2NewSubscription.keySet());

      // Set up data structures
      for (Map.Entry<String, Object> subscriptionHandle : subscriptionHandles.entrySet()) {
        String securityUniqueId = subscriptionHandle.getKey();
        Object handle = subscriptionHandle.getValue();
        LiveDataSpecification specFromClient = securityUniqueId2SpecFromClient.get(securityUniqueId);

        Subscription subscription = securityUniqueId2NewSubscription.get(securityUniqueId);
        subscription.setHandle(handle);

        _currentlyActiveSubscriptions.add(subscription);
View Full Code Here

    Map<String, LiveDataSpecification> securityUniqueId2LiveDataSpecificationFromClient = new HashMap<>();

    Map<LiveDataSpecification, DistributionSpecification> resolved = getDistributionSpecificationResolver().resolve(liveDataSpecificationsFromClient);
    for (LiveDataSpecification liveDataSpecificationFromClient : liveDataSpecificationsFromClient) {
      DistributionSpecification distributionSpec = resolved.get(liveDataSpecificationFromClient);
      LiveDataSpecification fullyQualifiedSpec = distributionSpec.getFullyQualifiedLiveDataSpecification();

      MarketDataDistributor currentlyActiveDistributor = getMarketDataDistributor(distributionSpec);
      if (currentlyActiveDistributor != null) {
        if (currentlyActiveDistributor.getSnapshot() != null) {
          //NOTE simon 28/11/2011: We presume that all the fields were provided in one go, all or nothing.
          s_logger.debug("Able to satisfy {} from existing LKV", liveDataSpecificationFromClient);
          LiveDataValueUpdateBean snapshot = currentlyActiveDistributor.getSnapshot();
          responses.add(buildSnapshotResponse(liveDataSpecificationFromClient, snapshot));
          continue;
        } else if (canSatisfySnapshotFromEmptySubscription(currentlyActiveDistributor)) {
          //BBG-91 - don't requery when an existing subscription indicates that the snapshot will fail
          s_logger.debug("Able to satisfy failed snapshot {} from existing LKV", liveDataSpecificationFromClient);
          String errorMsg = "Existing subscription for " + currentlyActiveDistributor.getDistributionSpec().getMarketDataId() +
              " failed to retrieve a snapshot.  Perhaps required fields are unavailable.";
          responses.add(buildErrorMessageResponse(liveDataSpecificationFromClient, LiveDataSubscriptionResult.INTERNAL_ERROR, errorMsg));
          continue;
        } else {
          s_logger.debug("Can't use existing subscription to satisfy {} from existing LKV", liveDataSpecificationFromClient);
        }
      }

      String securityUniqueId = fullyQualifiedSpec.getIdentifier(getUniqueIdDomain());
      if (securityUniqueId == null) {
        String errorMsg = "Qualified spec " + fullyQualifiedSpec + " does not contain ID of domain " + getUniqueIdDomain();
        responses.add(buildErrorMessageResponse(liveDataSpecificationFromClient, LiveDataSubscriptionResult.INTERNAL_ERROR, errorMsg));
        continue;
      }

      snapshotsToActuallyDo.add(securityUniqueId);
      securityUniqueId2LiveDataSpecificationFromClient.put(securityUniqueId, liveDataSpecificationFromClient);
    }

    s_logger.debug("Need to actually snapshot {}", snapshotsToActuallyDo);
    Map<String, FudgeMsg> snapshots = doSnapshot(snapshotsToActuallyDo);
    for (Map.Entry<String, FudgeMsg> snapshotEntry : snapshots.entrySet()) {
      String securityUniqueId = snapshotEntry.getKey();
      FudgeMsg msg = snapshotEntry.getValue();

      LiveDataSpecification liveDataSpecFromClient = securityUniqueId2LiveDataSpecificationFromClient.get(securityUniqueId);

      DistributionSpecification distributionSpec = resolved.get(liveDataSpecFromClient);
      FudgeMsg normalizedMsg = distributionSpec.getNormalizedMessage(msg, securityUniqueId);
      if (normalizedMsg == null) {
        String errorMsg = "When snapshot for " + securityUniqueId + " was run through normalization, the message disappeared. " +
View Full Code Here

    // check entitlement and sort into snapshots/subscriptions
    ArrayList<LiveDataSpecification> snapshots = new ArrayList<>();
    ArrayList<LiveDataSpecification> subscriptions = new ArrayList<>();
    Map<LiveDataSpecification, Boolean> entitled = getEntitlementChecker().isEntitled(subscriptionRequest.getUser(), distributable);
    for (Entry<LiveDataSpecification, Boolean> entry : entitled.entrySet()) {
      LiveDataSpecification requestedSpecification = entry.getKey();
      try {
        Boolean entitlement = entry.getValue();
        if (!entitlement) {
          String errorMsg = subscriptionRequest.getUser() + " is not entitled to " + requestedSpecification;
          s_logger.info(errorMsg);
View Full Code Here

   *
   * @param msg  the message, not null
   */
  private void dispatchLiveDataUpdate(FudgeMsg msg) {
    CogdaLiveDataUpdateMessage updateMessage = CogdaLiveDataUpdateBuilder.buildObjectStatic(new FudgeDeserializer(getFudgeContext()), msg);
    LiveDataSpecification ldspec = new LiveDataSpecification(updateMessage.getNormalizationScheme(), updateMessage.getSubscriptionId());
    LiveDataValueUpdateBean valueUpdateBean = new LiveDataValueUpdateBean(0L, ldspec, updateMessage.getValues());
    super.valueUpdate(valueUpdateBean);
  }
View Full Code Here

   * @param msg  the message, not null
   * @param subHandle  the subscription handle, not null
   */
  private void dispatchSnapshotResponse(FudgeMsg msg, SubscriptionHandle subHandle) {
    CogdaLiveDataSnapshotResponseMessage responseMessage = CogdaLiveDataSnapshotResponseBuilder.buildObjectStatic(new FudgeDeserializer(getFudgeContext()), msg);
    LiveDataSpecification ldSpec = new LiveDataSpecification(responseMessage.getNormalizationScheme(), responseMessage.getSubscriptionId());
   
    LiveDataSubscriptionResult ldsResult = responseMessage.getGenericResult().toLiveDataSubscriptionResult();
    LiveDataSubscriptionResponse ldsResponse = new LiveDataSubscriptionResponse(subHandle.getRequestedSpecification(), ldsResult);
    ldsResponse.setFullyQualifiedSpecification(ldSpec);
    ldsResponse.setUserMessage(responseMessage.getUserMessage());
View Full Code Here

   * @param msg  the message, not null
   * @param subHandle  the subscription handle, not null
   */
  private void dispatchSubscriptionResponse(FudgeMsg msg, SubscriptionHandle subHandle) {
    CogdaLiveDataSubscriptionResponseMessage responseMessage = CogdaLiveDataSubscriptionResponseBuilder.buildObjectStatic(new FudgeDeserializer(getFudgeContext()), msg);
    LiveDataSpecification ldSpec = new LiveDataSpecification(responseMessage.getNormalizationScheme(), responseMessage.getSubscriptionId());
   
    LiveDataSubscriptionResult ldsResult = responseMessage.getGenericResult().toLiveDataSubscriptionResult();
    LiveDataSubscriptionResponse ldsResponse = new LiveDataSubscriptionResponse(subHandle.getRequestedSpecification(), ldsResult);
    ldsResponse.setFullyQualifiedSpecification(ldSpec);
    ldsResponse.setUserMessage(responseMessage.getUserMessage());
View Full Code Here

  public static void main(final String[] args) throws InterruptedException { // CSIGNORE
    CogdaLiveDataClient client = new CogdaLiveDataClient(UserPrincipal.getLocalUser());
    //client.setServerName("cogdasvr-lx-1.hq.opengamma.com");
    client.start();
   
    LiveDataSpecification lds = new LiveDataSpecification("OpenGamma", ExternalId.of("SURF", "FV2DBEURUSD12M"));
    LiveDataSubscriptionResponse response = client.snapshot(UserPrincipal.getLocalUser(), lds, 60000L);
    s_logger.warn("Snapshot {}", response);
    List<LiveDataSpecification> subs = new LinkedList<LiveDataSpecification>();
    subs.add(lds);
    subs.add(new LiveDataSpecification("OpenGamma", ExternalId.of("SURF", "ASIRSEUR49Y30A03L")));
    subs.add(new LiveDataSpecification("OpenGamma", ExternalId.of("SURF", "FV1DRUSDBRL06M")));
    subs.add(new LiveDataSpecification("OpenGamma", ExternalId.of("ICAP", "SAUD_9Y")));
    subs.add(new LiveDataSpecification("OpenGamma", ExternalId.of("ICAP", "GBP_5Y")));
    subs.add(new LiveDataSpecification("OpenGamma", ExternalId.of("ICAP", "GBPUSD7M")));
    LiveDataListener ldl = new LiveDataListener() {
      @Override
      public void subscriptionResultReceived(LiveDataSubscriptionResponse subscriptionResult) {
        s_logger.warn("Sub result {}", subscriptionResult);
      }

      @Override
      public void subscriptionResultsReceived(final Collection<LiveDataSubscriptionResponse> subscriptionResults) {
        s_logger.warn("Sub result {}", subscriptionResults);
      }

      @Override
      public void subscriptionStopped(LiveDataSpecification fullyQualifiedSpecification) {
        s_logger.warn("Sub stopped {}", fullyQualifiedSpecification);
      }

      @Override
      public void valueUpdate(LiveDataValueUpdate valueUpdate) {
        s_logger.warn("Data received {}", valueUpdate);
      }
     
    };
    client.subscribe(UserPrincipal.getLocalUser(), subs, ldl);
   
    client.subscribe(UserPrincipal.getLocalUser(), new LiveDataSpecification("OpenGamma", ExternalId.of("SURF", "NO_SUCH_THING")), ldl);
   
    Thread.sleep(100000000L);
  }
View Full Code Here

      + " If the server already subscribes to the given market data, this method will make the "
      + " subscription persistent. Returns the name of the JMS topic market data will be published on.")
  @ManagedOperationParameters({ @ManagedOperationParameter(name = "securityUniqueId", description = "Security unique ID. Server type dependent.)") })
  public String subscribePersistently(String securityUniqueId) {
    try {
      LiveDataSpecification spec = getServer().getLiveDataSpecification(securityUniqueId);
      LiveDataSubscriptionResponse response = getServer().subscribe(spec, true);
      if (response.getSubscriptionResult() != LiveDataSubscriptionResult.SUCCESS) {
        throw new RuntimeException("Unsuccessful subscription: " + response.getUserMessage());
      }
      return response.getTickDistributionSpecification();
View Full Code Here

TOP

Related Classes of com.opengamma.livedata.LiveDataSpecification

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.