return; // Invalid message. Nothing to do
}
// Initially make both equal
String inputCasReferenceId = casReferenceId;
// Destination where Free Cas Notification will be sent if the CAS came from a Cas Multiplier
Endpoint freeCasEndpoint = null;
CasStateEntry inputCasStateEntry = null;
// CASes generated by a Cas Multiplier will have a CasSequence property set.
if (aMessageContext.propertyExists(AsynchAEMessage.CasSequence)) {
// Fetch the name of the Cas Multiplier's input queue
// String cmEndpointName = aMessageContext.getEndpoint().getEndpoint();
String cmEndpointName = aMessageContext
.getMessageStringProperty(AsynchAEMessage.MessageFrom);
newCASProducedBy = ((AggregateAnalysisEngineController) getController())
.lookUpDelegateKey(cmEndpointName);
// Fetch an ID of the parent CAS
inputCasReferenceId = aMessageContext
.getMessageStringProperty(AsynchAEMessage.InputCasReference);
// Fetch Cache entry for the parent CAS
CacheEntry inputCasCacheEntry = getController().getInProcessCache().getCacheEntryForCAS(
inputCasReferenceId);
// Fetch an endpoint where Free CAS Notification must be sent.
// This endpoint is unique per CM instance. Meaning, each
// instance of CM will have an endpoint where it expects Free CAS
// notifications.
freeCasEndpoint = aMessageContext.getEndpoint();
// Clone an endpoint where Free Cas Request will be sent
freeCasEndpoint = (Endpoint) ((Endpoint_impl) freeCasEndpoint).clone();
if (getController() instanceof AggregateAnalysisEngineController) {
inputCasStateEntry = ((AggregateAnalysisEngineController) getController())
.getLocalCache().lookupEntry(inputCasReferenceId);
// Associate Free Cas Notification Endpoint with an input Cas
inputCasStateEntry.setFreeCasNotificationEndpoint(freeCasEndpoint);
}
computeStats(aMessageContext, inputCasReferenceId);
// Reset the destination
aMessageContext.getEndpoint().setDestination(null);
// This CAS came in from a CAS Multiplier. Treat it differently than the
// input CAS. In case the Aggregate needs to send this CAS to the
// client, retrieve the client destination by looking up the client endpoint
// using input CAS reference id. CASes generated by the CAS multiplier will have
// the same Cas Reference id.
Endpoint replyToEndpoint = inputCasCacheEntry.getMessageOrigin();
// The message context contains a Cas Multiplier endpoint. Since
// we dont want to send a generated CAS back to the CM, override
// with an endpoint provided by the client of
// this service. Client endpoint is attached to an input Cas cache entry.
aMessageContext.getEndpoint().setEndpoint(replyToEndpoint.getEndpoint());
aMessageContext.getEndpoint().setServerURI(replyToEndpoint.getServerURI());
// Before sending a CAS to Cas Multiplier, the aggregate has
// saved the CM key in the CAS cache entry. Fetch the key
// of the CM so that we can ask the right Shadow Cas Pool for
// a new CAS. Every Shadow Cas Pool has a unique id which
// corresponds to a Cas Multiplier key.
// newCASProducedBy = inputCasCacheEntry.getCasMultiplierKey();
if (getController() instanceof AggregateAnalysisEngineController) {
Endpoint casMultiplierEndpoint = ((AggregateAnalysisEngineController) getController())
.lookUpEndpoint(newCASProducedBy, false);
if (casMultiplierEndpoint != null) {
// Save the URL of the broker managing the Free Cas Notification queue.
// This is needed when we try to establish a connection to the broker.
freeCasEndpoint.setServerURI(casMultiplierEndpoint.getServerURI());
}
}
} else if (getController().isTopLevelComponent()) {
if (getController() instanceof AggregateAnalysisEngineController) {
((AggregateAnalysisEngineController) getController()).addMessageOrigin(casReferenceId,