From 1fdd19079f5ef7e2b006c5d4b10b507179653268 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Wed, 20 May 2009 14:11:21 +0000 Subject: [PATCH] catch exceptions thrown from script threads --- .../sics/cooja/plugins/LogScriptEngine.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/plugins/LogScriptEngine.java b/tools/cooja/java/se/sics/cooja/plugins/LogScriptEngine.java index 7e1697ce2..e3bcd2360 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/LogScriptEngine.java +++ b/tools/cooja/java/se/sics/cooja/plugins/LogScriptEngine.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: LogScriptEngine.java,v 1.11 2009/04/23 10:41:35 fros4943 Exp $ + * $Id: LogScriptEngine.java,v 1.12 2009/05/20 14:11:21 fros4943 Exp $ */ package se.sics.cooja.plugins; @@ -48,9 +48,8 @@ import se.sics.cooja.*; * @author Fredrik Osterlind */ public class LogScriptEngine { - private static final int DEFAULT_TIMEOUT = 1200000; /* 1200s = 20 minutes */ + private static final long DEFAULT_TIMEOUT = 20*60*1000*1000; /* 1200s = 20 minutes */ - private static final long serialVersionUID = 1L; private static Logger logger = Logger.getLogger(LogScriptEngine.class); private ScriptEngineManager factory = new ScriptEngineManager(); @@ -333,7 +332,20 @@ public class LogScriptEngine { } catch (InterruptedException e) { e.printStackTrace(); } - scriptThread = new Thread(new Runnable() { + ThreadGroup group = new ThreadGroup("script") { + public void uncaughtException(Thread t, Throwable e) { + while (e.getCause() != null) { + e = e.getCause(); + } + if (e.getMessage() != null && + e.getMessage().contains("test script killed") ) { + /* Ignore normal shutdown exceptions */ + } else { + logger.fatal("Script error:", e); + } + } + }; + scriptThread = new Thread(group, new Runnable() { public void run() { /*logger.info("test script thread starts");*/ try {