*/
public void runSingleThreaded() throws Exception {
Object entity = null;
isRunning = true;
bootstrapCPE();
ProcessTrace pTrTemp = getProcessTrace();
boolean success = true;
long entityCount = 0;
// long start = System.currentTimeMillis();
long aggTime = 0;
long ppTime = 0;
long ccTime = 0;
long crTime = 0;
for (int j = 0; j < statusCbL.size(); j++) {
BaseStatusCallbackListener statCL = (BaseStatusCallbackListener) statusCbL.get(j);
if (statCL != null)
statCL.initializationComplete();
}
while (isRunning) {
try {
// Check if processed all entities as defined in the Cpe Descriptor.
if (endOfProcessingReached(entityCount)) {
break;
}
waitForCpmToResumeIfPaused(); // blocks if CPM is paused
// check again the state of the cpm after pause
if (!isRunning)
break;
readerState = 1000;
if (!collectionReader.hasNext())
break;
long st0 = System.currentTimeMillis();
entity = getCasWithSOFA(entity, pTrTemp);
crTime += (System.currentTimeMillis() - st0);
if (entity == null) {
success = false;
continue;
}
if (entity instanceof CAS[] && skipDroppedDocument((Object[]) entity)) {
notifyListeners(CAS_PROCESSED_MSG, (Object[]) entity, pTrTemp, new SkipCasException(
"Skipping Document Due To Dropped Cas in a Sequence"));
releaseCASes((CAS[]) entity);
continue;
} else {
// Clear the cache of bad documents
if (skippedDocs.size() > 0) {
skippedDocs.clear();
}
}
long st1 = System.currentTimeMillis();
// If CAS has been dropped due to an exception dont call CasConsumer
success = nonThreadedProcessingUnit.analyze((Object[]) entity, pTrTemp);
ppTime += (System.currentTimeMillis() - st1);
if (success) {
long st2 = System.currentTimeMillis();
nonThreadedCasConsumerProcessingUnit.analyze((Object[]) entity, pTrTemp);
ccTime += (System.currentTimeMillis() - st2);
}
} catch (Throwable t) {
// may change the state of the isRunning on fatal exception
handleException(t, (Object[]) entity, pTrTemp);
success = false;
} finally {
entityCount++;
// After sucessfull analysis notify listeners. If there was an exception, it has
// already been reported
if (success) {
readerState = 2007;
if (entity == null) {
notifyListeners(CAS_PROCESSED_MSG, null, pTrTemp);
} else {
notifyListeners(CAS_PROCESSED_MSG, (Object[]) entity, pTrTemp);
}
}
if (entity != null && entity instanceof CAS[]) {
releaseCASes((CAS[]) entity);
entity = null;
}
// Update processing trace counts and timers
synchronized (procTr) {
long st = System.currentTimeMillis();
procTr.aggregate(pTrTemp);
pTrTemp.clear();
aggTime += (System.currentTimeMillis() - st);
}
}
} // while
tearDownCPE();