/**
* @param fudgeContext
* @param msg
*/
private CogdaLiveDataCommandResponseMessage handleSubscriptionRequest(FudgeContext fudgeContext, FudgeMsg msg) {
CogdaLiveDataSubscriptionRequestMessage request = CogdaLiveDataSubscriptionRequestBuilder.buildObjectStatic(new FudgeDeserializer(fudgeContext), msg);
CogdaLiveDataSubscriptionResponseMessage response = new CogdaLiveDataSubscriptionResponseMessage();
response.setCorrelationId(request.getCorrelationId());
response.setSubscriptionId(request.getSubscriptionId());
response.setNormalizationScheme(request.getNormalizationScheme());
// TODO kirk 2012-07-23 -- Check entitlements.
if (!getServer().isValidLiveData(request.getSubscriptionId(), request.getNormalizationScheme())) {
response.setGenericResult(CogdaCommandResponseResult.NOT_AVAILABLE);
} else if (!isEntitled(EntitlementUtils.SUBSCRIBE, request.getSubscriptionId(), request.getNormalizationScheme())) {
response.setGenericResult(CogdaCommandResponseResult.NOT_AUTHORIZED);
} else {
LastKnownValueStore lkvStore = getServer().getLastKnownValueStore(request.getSubscriptionId(), request.getNormalizationScheme());
FudgeMsg fields = null;
if (lkvStore != null) {
fields = lkvStore.getFields();
} else {
s_logger.warn("Valid live data {} lacks fields in LKV store", request);
fields = fudgeContext.newMessage();
}
response.setGenericResult(CogdaCommandResponseResult.SUCCESSFUL);
response.setSnapshot(fields);
_subscriptions.putIfAbsent(new LiveDataSpecification(request.getNormalizationScheme(), request.getSubscriptionId()), Boolean.TRUE);
}
return response;
}