CAS cas = null;
try {
byte[] serializedCAS = null;
// Using Cas reference Id retrieve CAS from the shared Cash
cas = getAnalysisEngineController().getInProcessCache().getCasByReference(aCasReferenceId);
ServicePerformance casStats = getAnalysisEngineController().getCasStatistics(aCasReferenceId);
CacheEntry entry = getAnalysisEngineController().getInProcessCache().getCacheEntryForCAS(
aCasReferenceId);
long t1 = getAnalysisEngineController().getCpuTime();
// Serialize CAS for remote Delegates
SerialFormat serializerType = anEndpoint.getSerialFormat();
if (cas == null || entry == null) {
return null;
}
// Fetch dedicated Serializer associated with this thread
UimaSerializer serializer = SerializerCache.lookupSerializerByThreadId();
if (serializerType == SerialFormat.BINARY || serializerType == SerialFormat.COMPRESSED_FILTERED) {
if (entry.acceptsDeltaCas() && isReply) {
if (entry.getMarker() != null && entry.getMarker().isValid()) {
if (serializerType == SerialFormat.COMPRESSED_FILTERED) {
serializedCAS = serializer.serializeCasToBinary6(cas, entry.getMarker(), entry.getCompress6ReuseInfo());
} else {
serializedCAS = serializer.serializeCasToBinary(cas, entry.getMarker());
}
entry.setSentDeltaCas(true);
} else {
if (serializerType == SerialFormat.COMPRESSED_FILTERED) {
serializedCAS = serializer.serializeCasToBinary6(cas);
} else {
serializedCAS = serializer.serializeCasToBinary(cas);
}
entry.setSentDeltaCas(false);
}
} else {
// either is a reply to a caller not accepting delta, or
// is not a reply
if (serializerType == SerialFormat.COMPRESSED_FILTERED) {
if (isReply) {
serializedCAS = serializer.serializeCasToBinary6(cas); // never called?
} else {
serializedCAS = serializer.serializeCasToBinary6(cas, entry, anEndpoint.getTypeSystemImpl());
}
} else {
serializedCAS = serializer.serializeCasToBinary(cas);
}
entry.setSentDeltaCas(false);
if (isReply) {
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, CLASS_NAME.getName(), "getBinaryCas",
JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_serialize_cas__FINEST",
new Object[] { aCasReferenceId, "FULL Cas serialized and sent." });
}
}
}
// create a fresh marker
if (entry.getMarker() != null && !entry.getMarker().isValid()) {
entry.setMarker(cas.createMarker());
}
} else {
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.INFO)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(
Level.INFO,
CLASS_NAME.getName(),
"getBinaryCas",
JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAJMS_invalid_serializer__WARNING",
new Object[] { getAnalysisEngineController().getName(), serializerType,
anEndpoint.getEndpoint() });
}
throw new UimaEEServiceException("Invalid Serializer:" + serializerType + " For Endpoint:"
+ anEndpoint.getEndpoint());
}
long timeToSerializeCas = getAnalysisEngineController().getCpuTime() - t1;
getAnalysisEngineController().incrementSerializationTime(timeToSerializeCas);
entry.incrementTimeToSerializeCAS(timeToSerializeCas);
casStats.incrementCasSerializationTime(timeToSerializeCas);
getAnalysisEngineController().getServicePerformance().incrementCasSerializationTime(
timeToSerializeCas);
return serializedCAS;
} catch (Exception e) {
throw new AsynchAEException(e);