From 7dd0b1c97817690899bcfd338002e77958bb3a9c Mon Sep 17 00:00:00 2001 From: Nate Jensen Date: Thu, 23 Jan 2014 18:04:11 -0600 Subject: [PATCH] Issue #2359 printout shutdown of application to try and detect kills Change-Id: I113890428cfd5a22c2fbb0a4abdcff18a4ccd11e Former-commit-id: 47d6e5b54fe532d3b32a8f478e0fcd1104fd6fe4 [formerly 34b2c7a402bcf7f3b04ea1e98090f7e0df48566f] Former-commit-id: cdbd05b2935fd9ea015dec56a1d684e1f3739841 --- .../uf/viz/application/VizApplication.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/cave/com.raytheon.uf.viz.application/src/com/raytheon/uf/viz/application/VizApplication.java b/cave/com.raytheon.uf.viz.application/src/com/raytheon/uf/viz/application/VizApplication.java index 777fdcdf63..9400e36ff9 100644 --- a/cave/com.raytheon.uf.viz.application/src/com/raytheon/uf/viz/application/VizApplication.java +++ b/cave/com.raytheon.uf.viz.application/src/com/raytheon/uf/viz/application/VizApplication.java @@ -19,6 +19,10 @@ package com.raytheon.uf.viz.application; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; + import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; @@ -39,6 +43,7 @@ import com.raytheon.uf.viz.application.component.IStandaloneComponent; * Apr 18, 2007 chammack Initial Creation. * Dec 03, 2007 461 bphillip Added persistence of workstation time to localization * Oct 07, 2008 1433 chammack Added alertviz startup + * Jan 23, 2014 njensen Added shutdown hook and printout * * * @@ -54,6 +59,7 @@ public class VizApplication implements IApplication { * @seeorg.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app. * IApplicationContext) */ + @Override public Object start(IApplicationContext context) throws Exception { String appToRun = ProgramArguments.getInstance() @@ -78,6 +84,8 @@ public class VizApplication implements IApplication { return IApplication.EXIT_OK; } + addShutdownHook(); + return component.startComponent(appToRun); } @@ -86,6 +94,7 @@ public class VizApplication implements IApplication { * * @see org.eclipse.equinox.app.IApplication#stop() */ + @Override public void stop() { } @@ -123,4 +132,29 @@ public class VizApplication implements IApplication { return standalone; } + protected void addShutdownHook() { + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + @Override + public void run() { + /* + * This may seem pointless but is actually quite helpful to + * confirm how the process exited. If the process is killed by a + * kill command on a terminal, the console output will have this + * message but not the normal safe shutdown output (see + * com.raytheon.uf.viz.core.Activator's stop() and + * VizWorkbenchAdvisor's preShutdown()). In contrast, a + * spontaneous death of the process or force kill will not have + * this printout. + */ + SimpleDateFormat sdf = new SimpleDateFormat( + "yyyy-MM-dd HH:mm:ss"); + sdf.setTimeZone(TimeZone.getTimeZone("GMT")); + System.out.println(sdf.format(new Date()) + + " VizApplication's runtime shutdown hook triggered"); + } + }) { + + }); + } + }