Merge "Issue #2359 printout shutdown of application to try and detect kills" into omaha_14.2.1

Former-commit-id: 3c68312dc8 [formerly af00a8b522160a498d168b88dc519d9cc006f21e]
Former-commit-id: 519c0a44c0
This commit is contained in:
Richard Peter 2014-01-24 12:32:51 -06:00 committed by Gerrit Code Review
commit fa5336f508

View file

@ -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
*
* </pre>
*
@ -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");
}
}) {
});
}
}