in uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/engine/NonThreadedProcessingUnit.java [791:934]
private boolean handleErrors(Throwable e, ProcessingContainer aContainer, CasProcessor aProcessor,
ProcessTrace aProcessTrace, Object[] aCasObjectList, boolean isCasObject)
throws Exception {
boolean retry = true;
String containerName = aContainer.getName();
e.printStackTrace();
if (UIMAFramework.getLogger().isLoggable(Level.SEVERE)) {
UIMAFramework.getLogger(this.getClass()).log(Level.SEVERE, Thread.currentThread().getName(),
e);
UIMAFramework.getLogger(this.getClass()).logrb(Level.SEVERE, this.getClass().getName(),
"process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_handle_exception__SEVERE",
new Object[] { Thread.currentThread().getName(), containerName,
aProcessor.getClass().getName(), e.getMessage() });
}
EntityProcessStatusImpl enProcSt = new EntityProcessStatusImpl(aProcessTrace);
enProcSt.addEventStatus("Process", "Failed", e);
threadState = 2008;
// Send exception notifications to all registered listeners
notifyListeners(aCasObjectList, isCasObject, enProcSt);
threadState = 2009;
// Check the policy to determine what to do with the CAS on exception. Return the CAS back to
// the pool
// and stop the processing chain if required. The policy for what to do with the CAS on
// exception is
// defined in the CPE descriptor
if (cpm.dropCasOnException()) {
if (casCache != null) {
clearCasCache();
}
UIMAFramework.getLogger(this.getClass()).logrb(Level.WARNING, this.getClass().getName(),
"process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_drop_cas__WARNING",
new Object[] { Thread.currentThread().getName(), containerName,
aProcessor.getClass().getName() });
// Release CASes and notify listeners
cpm.invalidateCASes((CAS[]) aCasObjectList);
retry = false; // Dont retry. The CAS has been released
}
// If the container is in pause state dont increment errors since one thread has already
// done this. While the container is in pause state the CPM is attempting to re-connect
// to a failed service. Once that is done, the container is going to be resumed. While
// in pause state ALL threads using the container will be suspended.
if (aProcessor instanceof CasObjectNetworkCasProcessorImpl && aContainer.isPaused()) {
threadState = 2010;
if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
"process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_container_paused_do_retry__FINEST",
new Object[] { Thread.currentThread().getName(), containerName });
}
return true; // retry
}
if (e instanceof Exception && pauseContainer(aContainer, (Exception) e, threadId)) {
if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
"process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_pausing_container__FINEST",
new Object[] { Thread.currentThread().getName(), containerName });
}
threadState = 2011;
// New Code 02/23/05
// Pause the container while the CPM is re-connecting to un-managed service
// that is shared by all processing threads
aContainer.pause();
threadId = Thread.currentThread().getName();
}
try {
// Increments error counter and determines if any threshold have been reached. If
// the max error rate is reached, the CasProcessor can be configured as follows:
// - terminates CPM when threshold is reached ( method below throws AbortCPMException)
// - disables CasProcessor ( method below throws AbortCasProcessorException )
// - continue, CasProcessor continues to run dispite error
aContainer.incrementCasProcessorErrors(e);
// End of new code
} // check if the exception should terminate the CPM
catch (AbortCPMException ex) {
retry = false;
if (aContainer.isPaused()) {
aContainer.resume();
}
aContainer.setStatus(Constants.CAS_PROCESSOR_KILLED);
if (UIMAFramework.getLogger().isLoggable(Level.SEVERE)) {
UIMAFramework.getLogger(this.getClass()).logrb(Level.SEVERE, this.getClass().getName(),
"process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_abort_cpm__SEVERE",
new Object[] { Thread.currentThread().getName(), aProcessor.getClass().getName() });
}
throw new AbortCPMException(CpmLocalizedMessage.getLocalizedMessage(
CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_EXP_configured_to_abort__WARNING",
new Object[] { Thread.currentThread().getName(), containerName }));
} // check if the CasProcessor is to be disabled due to excessive errors
catch (AbortCasProcessorException ex) {
retry = false;
if (aContainer.isPaused()) {
aContainer.resume();
}
if (UIMAFramework.getLogger().isLoggable(Level.SEVERE)) {
UIMAFramework.getLogger(this.getClass()).logrb(Level.SEVERE, this.getClass().getName(),
"process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_disable_cp__SEVERE",
new Object[] { Thread.currentThread().getName(), aProcessor.getClass().getName() });
}
aContainer.setStatus(Constants.CAS_PROCESSOR_DISABLED);
} // check if need to redeploy the CasProcessor
catch (ServiceConnectionException ex) {
aProcessTrace.startEvent(containerName, "Process", "");
String status = "failure";
try {
threadState = 2012;
handleServiceException(aContainer, aProcessor, aProcessTrace, ex);
// Increment number of restarts
// aContainer.incrementRestartCount(1);
status = "success";
} catch (ResourceProcessException rpe) {
throw rpe;
} catch (Exception rpe) {
throw new ResourceProcessException(rpe);
} finally {
aProcessTrace.endEvent(containerName, "Process", status);
}
} catch (SkipCasException ex) {
try {
handleSkipCasProcessor(aContainer, aCasObjectList, false);
retry = false;
} catch (Exception sEx) {
throw new ResourceProcessException(sEx);
}
} catch (Exception ex) {
if (UIMAFramework.getLogger().isLoggable(Level.SEVERE)) {
UIMAFramework.getLogger(this.getClass()).log(Level.SEVERE, Thread.currentThread().getName(),
e);
}
retry = false;
ex.printStackTrace();
}
return retry;
}