# HG changeset patch # User Severin Gehwolf # Date 1348840459 -7200 # Node ID 394f8798ad69bee09a9843ff5090a6ebd7f68759 # Parent b1f98c2a17d55d8459217819aba9d670bae4bc40 Handle SIGTERM/SIGINT in Swing GUI. This fixes PR1181. It allows us to kill ourself - via the "Kill Application" context menu - without nasty sideeffects such as throwing exceptions. Also, CTRL+C in the terminal where client started is properly handled with this. Reviewed-by: vanaltj, omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-September/003468.html diff -r b1f98c2a17d5 -r 394f8798ad69 client/core/src/main/java/com/redhat/thermostat/client/ui/MainWindow.java --- a/client/core/src/main/java/com/redhat/thermostat/client/ui/MainWindow.java Fri Sep 28 16:40:23 2012 +0200 +++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/MainWindow.java Fri Sep 28 15:54:19 2012 +0200 @@ -91,6 +91,8 @@ import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; +import sun.misc.Signal; + import com.redhat.thermostat.client.internal.MainView; import com.redhat.thermostat.client.locale.LocaleResources; import com.redhat.thermostat.client.osgi.service.BasicView; @@ -325,6 +327,7 @@ new DefaultMutableTreeNode(localize(LocaleResources.MAIN_WINDOW_TREE_ROOT_NAME)); private final DefaultTreeModel publishedTreeModel = new DefaultTreeModel(publishedRoot); + @SuppressWarnings("restriction") public MainWindow() { super(); @@ -376,6 +379,10 @@ setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(shutdownAction); + // Handle SIGTERM/SIGINT properly + Signal.handle(new Signal("TERM"), shutdownAction); + Signal.handle(new Signal("INT"), shutdownAction); + addComponentListener(new ComponentAdapter() { @Override @@ -536,7 +543,8 @@ return result; } - public class ShutdownClient extends WindowAdapter implements java.awt.event.ActionListener { + @SuppressWarnings("restriction") + public class ShutdownClient extends WindowAdapter implements java.awt.event.ActionListener, sun.misc.SignalHandler { @Override public void windowClosing(WindowEvent e) { @@ -547,11 +555,17 @@ public void actionPerformed(java.awt.event.ActionEvent e) { shutdown(); } + + @Override + public void handle(Signal arg0) { + shutdown(); + } private void shutdown() { dispose(); fireViewAction(Action.SHUTDOWN); } + } private static class AgentVmTreeCellRenderer extends DefaultTreeCellRenderer {