return; // out of band reply. Most likely the CAS previously timedout
}
// Increment number of CASes processed by this delegate
if (aDelegateKey != null) {
ServicePerformance delegateServicePerformance = ((AggregateAnalysisEngineController) getController())
.getServicePerformance(aDelegateKey);
if (delegateServicePerformance != null) {
delegateServicePerformance.incrementNumberOfCASesProcessed();
}
}
String xmi = aMessageContext.getStringMessage();
// Fetch entry from the cache for a given Cas Id. The entry contains a CAS that will be used
// during deserialization
CacheEntry cacheEntry = getController().getInProcessCache().getCacheEntryForCAS(
casReferenceId);
if ( aMessageContext.propertyExists(AsynchAEMessage.CASPerComponentMetrics) ) {
try {
CacheEntry ancestor =
getController().
getInProcessCache().
getTopAncestorCasEntry(cacheEntry);
if ( ancestor != null ) {
List<AnalysisEnginePerformanceMetrics> metrics =
UimaSerializer.deserializePerformanceMetrics(aMessageContext.getMessageStringProperty(AsynchAEMessage.CASPerComponentMetrics));
List<AnalysisEnginePerformanceMetrics> adjustedMetrics =
new ArrayList<AnalysisEnginePerformanceMetrics>();
for(AnalysisEnginePerformanceMetrics delegateMetric : metrics ) {
String tmp =
delegateMetric.getUniqueName().substring(delegateMetric.getUniqueName().indexOf(","));
String adjustedUniqueName =
((AggregateAnalysisEngineController) getController()).getJMXDomain()+((AggregateAnalysisEngineController) getController()).getJmxContext()+tmp;
AnalysisEnginePerformanceMetrics metric =
new AnalysisEnginePerformanceMetrics(delegateMetric.getName(),adjustedUniqueName,delegateMetric.getAnalysisTime(),delegateMetric.getNumProcessed());
adjustedMetrics.add(metric);
}
ancestor.addDelegateMetrics(delegateKey, adjustedMetrics, true); // true=remote
}
} catch (Exception e) {
// An exception be be thrown here if the service is being stopped.
// The top level controller may have already cleaned up the cache
// and the getCacheEntryForCAS() will throw an exception. Ignore it
// here, we are shutting down.
}
}
CasStateEntry casStateEntry = ((AggregateAnalysisEngineController) getController())
.getLocalCache().lookupEntry(casReferenceId);
if (casStateEntry != null) {
casStateEntry.setReplyReceived();
// Set the key of the delegate that returned the CAS
casStateEntry.setLastDelegate(delegate);
} else {
return; // Cache Entry Not found
}
cas = cacheEntry.getCas();
int totalNumberOfParallelDelegatesProcessingCas = casStateEntry
.getNumberOfParallelDelegates();
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINE)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, CLASS_NAME.getName(),
"handleProcessResponseFromRemote", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAEE_number_parallel_delegates_FINE",
new Object[] { totalNumberOfParallelDelegatesProcessingCas, Thread.currentThread().getId(), Thread.currentThread().getName() });
}
if (cas == null) {
throw new AsynchAEException(Thread.currentThread().getName()
+ "-Cache Does not contain a CAS. Cas Reference Id::" + casReferenceId);
}
if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(),
"handleProcessResponseFromRemote", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAEE_rcvd_reply_FINEST",
new Object[] { aMessageContext.getEndpoint().getEndpoint(), casReferenceId, xmi });
}
long t1 = getController().getCpuTime();
/* --------------------- */
/** DESERIALIZE THE CAS. */
/* --------------------- */
//all subsequent serialization must be complete CAS.
if ( !aMessageContext.getMessageBooleanProperty(AsynchAEMessage.SentDeltaCas)) {
cacheEntry.setAcceptsDeltaCas(false);
}
// check if the CAS is part of the Parallel Step
if (totalNumberOfParallelDelegatesProcessingCas > 1) {
// Synchronized because replies are merged into the same CAS.
synchronized (cas) {
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(),
"handleProcessResponseFromRemote", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAEE_delegate_responded_count_FINEST",
new Object[] { casStateEntry.howManyDelegatesResponded(), casReferenceId });
}
// If a delta CAS, merge it while checking that no pre-existing FSs are modified.
if (aMessageContext.getMessageBooleanProperty(AsynchAEMessage.SentDeltaCas)) {
int highWaterMark = cacheEntry.getHighWaterMark();
deserialize(xmi, cas, casReferenceId, highWaterMark, AllowPreexistingFS.disallow);
} else {
// If not a delta CAS (old service), take all of first reply, and merge in the new
// entries in the later replies. Ignoring pre-existing FS for 2.2.2 compatibility
if (casStateEntry.howManyDelegatesResponded() == 0) {
deserialize(xmi, cas, casReferenceId);
} else { // process secondary reply from a parallel step
int highWaterMark = cacheEntry.getHighWaterMark();
deserialize(xmi, cas, casReferenceId, highWaterMark, AllowPreexistingFS.ignore);
}
}
casStateEntry.incrementHowManyDelegatesResponded();
}
} else { // Processing a reply from a non-parallel delegate (binary or delta xmi or xmi)
String serializationStrategy = endpointWithTimer.getSerializer();
if (serializationStrategy.equals("binary")) {
UimaSerializer uimaSerializer = SerializerCache.lookupSerializerByThreadId();
byte[] binaryData = aMessageContext.getByteMessage();
uimaSerializer.deserializeCasFromBinary(binaryData, cas);
} else {
if (aMessageContext.getMessageBooleanProperty(AsynchAEMessage.SentDeltaCas)) {
int highWaterMark = cacheEntry.getHighWaterMark();
deserialize(xmi, cas, casReferenceId, highWaterMark, AllowPreexistingFS.allow);
} else {
deserialize(xmi, cas, casReferenceId);
}
}
}
long timeToDeserializeCAS = getController().getCpuTime() - t1;
getController().getServicePerformance().incrementCasDeserializationTime(timeToDeserializeCAS);
ServicePerformance casStats = getController().getCasStatistics(casReferenceId);
casStats.incrementCasDeserializationTime(timeToDeserializeCAS);
LongNumericStatistic statistic;
if ((statistic = getController().getMonitor().getLongNumericStatistic("",
Monitor.TotalDeserializeTime)) != null) {
statistic.increment(timeToDeserializeCAS);
}