long start = getAnalysisEngineController().getCpuTime();
String serializedCas = null;
// Fetch dedicated Serializer associated with this thread
UimaSerializer serializer = SerializerCache.lookupSerializerByThreadId();
if (isReply || "xmi".equalsIgnoreCase(aSerializerKey)) {
CacheEntry cacheEntry = getAnalysisEngineController().getInProcessCache()
.getCacheEntryForCAS(aCasReferenceId);
XmiSerializationSharedData serSharedData;
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINE)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, CLASS_NAME.getName(), "serializeCAS",
JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_serialize_cas__FINE",
new Object[] { aCasReferenceId });
}
if (isReply) {
serSharedData = cacheEntry.getDeserSharedData();
if (cacheEntry.acceptsDeltaCas()
&& (cacheEntry.getMarker() != null && cacheEntry.getMarker().isValid())) {
serializedCas = serializer.serializeCasToXmi(aCAS, serSharedData, cacheEntry
.getMarker());
cacheEntry.setSentDeltaCas(true);
} else {
serializedCas = serializer.serializeCasToXmi(aCAS, serSharedData);
cacheEntry.setSentDeltaCas(false);
}
// if market is invalid, create a fresh marker.
if (cacheEntry.getMarker() != null && !cacheEntry.getMarker().isValid()) {
cacheEntry.setMarker(aCAS.createMarker());
}
if ( !cacheEntry.sentDeltaCas() ) {
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, CLASS_NAME.getName(), "serializeCAS",
JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_serialize_cas__FINEST",
new Object[] { aCasReferenceId, "FULL Cas serialized and sent." });
}
}
} else {
serSharedData = cacheEntry.getDeserSharedData();
if (serSharedData == null) {
serSharedData = new XmiSerializationSharedData();
cacheEntry.setXmiSerializationData(serSharedData);
}
serializedCas = serializer.serializeCasToXmi(aCAS, serSharedData);
int maxOutgoingXmiId = serSharedData.getMaxXmiId();
// Save High Water Mark in case a merge is needed
getAnalysisEngineController().getInProcessCache().getCacheEntryForCAS(aCasReferenceId)
.setHighWaterMark(maxOutgoingXmiId);
}
} else if ("xcas".equalsIgnoreCase(aSerializerKey)) {
// Default is XCAS
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
serializer.serializeToXCAS(bos, aCAS, null, null, null);
serializedCas = bos.toString();
} catch (Exception e) {
throw e;
} finally {
bos.close();