You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2012/01/25 21:06:09 UTC
svn commit: r1235895 - in /uima/uima-as/trunk:
uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/
uimaj-as-core/src/main/java/org/apache/uima/aae/controller/
uimaj-as-core/src/main/java/org/apache/uima/aae/error/
uimaj-as-core/src/ma...
Author: cwiklik
Date: Wed Jan 25 20:06:08 2012
New Revision: 1235895
URL: http://svn.apache.org/viewvc?rev=1235895&view=rev
Log:
UIMA-2358 Added global DefaultUncaughtExceptionHandler to catch java Errors uncaught anywhere else. Added System.exit(2) in JmsInputChannel and PrimitiveAnalysisEngineController_impl when OOM happens
Added:
uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/error/UimaAsUncaughtExceptionHandler.java (with props)
Modified:
uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/JmsInputChannel.java
uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java
uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/PrimitiveAnalysisEngineController_impl.java
uima/uima-as/trunk/uimaj-as-core/src/main/resources/uimaee_messages.properties
Modified: uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/JmsInputChannel.java
URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/JmsInputChannel.java?rev=1235895&r1=1235894&r2=1235895&view=diff
==============================================================================
--- uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/JmsInputChannel.java (original)
+++ uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/JmsInputChannel.java Wed Jan 25 20:06:08 2012
@@ -709,6 +709,13 @@ public class JmsInputChannel implements
}
} catch (Throwable t) {
+ if ( t instanceof Error) {
+ t.printStackTrace();
+ System.err.println("\n\n\n\tUIMA AS Service Caught Java Error. Exiting via System.exit(2)");
+ System.err.flush();
+
+ System.exit(2);
+ }
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.WARNING)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(),
Modified: uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java
URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java?rev=1235895&r1=1235894&r2=1235895&view=diff
==============================================================================
--- uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java (original)
+++ uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java Wed Jan 25 20:06:08 2012
@@ -70,6 +70,7 @@ import org.apache.uima.aae.error.ErrorHa
import org.apache.uima.aae.error.ForcedMessageTimeoutException;
import org.apache.uima.aae.error.MessageTimeoutException;
import org.apache.uima.aae.error.ServiceShutdownException;
+import org.apache.uima.aae.error.UimaAsUncaughtExceptionHandler;
import org.apache.uima.aae.error.handler.ProcessCasErrorHandler;
import org.apache.uima.aae.jmx.JmxManagement;
import org.apache.uima.aae.jmx.JmxManager;
@@ -294,7 +295,6 @@ public abstract class BaseAnalysisEngine
aeDescriptor = aDescriptor;
parentController = aParentController;
componentCasPoolSize = aComponentCasPoolSize;
-
if (this instanceof AggregateAnalysisEngineController) {
// Populate a list of un-registered co-located delegates. A delegate will be taken off the
// un-registered list
@@ -334,6 +334,11 @@ public abstract class BaseAnalysisEngine
resourceSpecifier = UimaClassFactory.produceResourceSpecifier(aDescriptor);
if (isTopLevelComponent()) {
+ // ******************************************************************************
+ // Set a global UncaughtExceptionHandler to handle OOM and other uncaught Throwables
+ // ******************************************************************************
+ // this adds the handler to every thread
+ Thread.setDefaultUncaughtExceptionHandler(new UimaAsUncaughtExceptionHandler(getComponentName()));
// Check the version of uimaj that UIMA AS was built with, against the UIMA Core version. If not the same throw Exception
if (!UimaAsVersion.getUimajFullVersionString().equals(UimaVersion.getFullVersionString())) {
UIMAFramework.getLogger(CLASS_NAME).logrb(
Modified: uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/PrimitiveAnalysisEngineController_impl.java
URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/PrimitiveAnalysisEngineController_impl.java?rev=1235895&r1=1235894&r2=1235895&view=diff
==============================================================================
--- uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/PrimitiveAnalysisEngineController_impl.java (original)
+++ uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/PrimitiveAnalysisEngineController_impl.java Wed Jan 25 20:06:08 2012
@@ -880,6 +880,13 @@ public class PrimitiveAnalysisEngineCont
localCache.remove(aCasReferenceId);
}
} catch (Throwable e) {
+
+ if ( e instanceof OutOfMemoryError ) {
+ e.printStackTrace();
+ System.err.println("\n\n\n\t!!!!! UIMA AS Service Caught Java Error While in process() method. Exiting via System.exit(2)\n\n\n");
+ System.err.flush();
+ System.exit(2);
+ }
if ( stackDumpTimer != null ) {
stackDumpTimer.cancel();
}
Added: uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/error/UimaAsUncaughtExceptionHandler.java
URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/error/UimaAsUncaughtExceptionHandler.java?rev=1235895&view=auto
==============================================================================
--- uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/error/UimaAsUncaughtExceptionHandler.java (added)
+++ uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/error/UimaAsUncaughtExceptionHandler.java Wed Jan 25 20:06:08 2012
@@ -0,0 +1,46 @@
+package org.apache.uima.aae.error;
+
+import java.lang.Thread.UncaughtExceptionHandler;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.aae.UIMAEE_Constants;
+import org.apache.uima.util.Level;
+
+public class UimaAsUncaughtExceptionHandler implements UncaughtExceptionHandler {
+ private static final Class<UimaAsUncaughtExceptionHandler> CLASS_NAME = UimaAsUncaughtExceptionHandler.class;
+ private volatile boolean handledOOMalready;
+ String uimaAsService;
+
+ public UimaAsUncaughtExceptionHandler(String uimaAsService) {
+ this.uimaAsService = uimaAsService;
+ }
+
+ private boolean isTerminalError(Throwable t) {
+ return (t instanceof OutOfMemoryError ||
+ t instanceof LinkageError ||
+ t instanceof NoClassDefFoundError ||
+ t instanceof NoSuchMethodError );
+ }
+ public void uncaughtException(Thread t, Throwable e) {
+ if ( !handledOOMalready ) { // the OOM has already been reported
+ if ( e instanceof OutOfMemoryError ) {
+ handledOOMalready = true;
+ }
+ // the following are best effort attempts to show the errors. If the error
+ // is OOM, dumping trace or logging may cause another OOM.
+ e.printStackTrace();
+ UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(),
+ "uncaughtException", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
+ "UIMAEE_uncaught_error_WARNING", new Object[] {uimaAsService,e});
+ if ( isTerminalError(e) ) {
+ UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(),
+ "uncaughtException", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
+ "UIMAEE_terminal_error_WARNING",new Object[] {uimaAsService});
+ System.exit(2);
+ }
+ } else {
+ System.exit(2); // repeated OOM, just exit
+ }
+ }
+
+}
Propchange: uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/error/UimaAsUncaughtExceptionHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: uima/uima-as/trunk/uimaj-as-core/src/main/resources/uimaee_messages.properties
URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-core/src/main/resources/uimaee_messages.properties?rev=1235895&r1=1235894&r2=1235895&view=diff
==============================================================================
--- uima/uima-as/trunk/uimaj-as-core/src/main/resources/uimaee_messages.properties (original)
+++ uima/uima-as/trunk/uimaj-as-core/src/main/resources/uimaee_messages.properties Wed Jan 25 20:06:08 2012
@@ -251,4 +251,7 @@ UIMAEE_checking_in_ae_to_pool__INFO=Cont
UIMAEE_checked_in_ae_to_pool__INFO=Controller: {0} Checked in AE instance to AePoolManager. Thread Id:{1}
UIMAEE_calling_ae_initialize__INFO=Controller: {0} Initializing AE instance on Thread Id: {1}
UIMAEE_process_thread_exiting__INFO=Controller: {0} --------------- Process Thread ID:{1} EXITING
-UIMAEE_ae_instance_destroy_called__INFO=Controller: {0} --------------- AE destroy() Method Call Returned ID:{1}
\ No newline at end of file
+UIMAEE_ae_instance_destroy_called__INFO=Controller: {0} --------------- AE destroy() Method Call Returned ID:{1}
+UIMAEE_uncaught_error_WARNING=Controller: {0} Handling uncaught Throwable. Stack trace:\n {1}
+UIMAEE_terminal_error_WARNING=Controller:{0} Exiting via System.exit(2) Due to unrecoverable error
+