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. " +
" This indicates there are buggy normalization rules in place, or that buggy (or unexpected) data was" +
" received from the underlying market data API. Check your normalization rules. Raw, unnormalized msg = " + msg;
responses.add(buildErrorMessageResponse(liveDataSpecFromClient, LiveDataSubscriptionResult.INTERNAL_ERROR, errorMsg));
continue;
}
LiveDataValueUpdateBean snapshot = new LiveDataValueUpdateBean(0, distributionSpec.getFullyQualifiedLiveDataSpecification(), normalizedMsg);
responses.add(buildSnapshotResponse(liveDataSpecFromClient, snapshot));
}
return responses;
}