Mercurial > hg > release > thermostat-1.6
changeset 1945:0bcf2b7b82b7
Make AgentApplication handle interrupt exception as SIGINT
PR3041
Reviewed-by: jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-June/019757.html
author | Anirudhan Mukundan <amukunda@redhat.com> |
---|---|
date | Thu, 23 Jun 2016 14:00:52 -0400 |
parents | 328d0595e5ee |
children | f2baa291edde |
files | agent/cli/src/main/java/com/redhat/thermostat/agent/cli/impl/AgentApplication.java |
diffstat | 1 files changed, 11 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/impl/AgentApplication.java Mon Jun 27 14:30:03 2016 +0200 +++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/impl/AgentApplication.java Thu Jun 23 14:00:52 2016 -0400 @@ -89,7 +89,10 @@ // when you change those! private static final String VERBOSE_MODE_AGENT_STOPPED_MSG = "Agent stopped."; private static final String VERBOSE_MODE_AGENT_STARTED_MSG = "Agent started."; - + + private static final String SIGINT_NAME = "INT"; + private static final String SIGTERM_NAME = "TERM"; + private static final Logger logger = LoggingUtils.getLogger(AgentApplication.class); private final BundleContext bundleContext; @@ -105,6 +108,8 @@ private final WriterID writerId; private CountDownLatch shutdownLatch; + private CustomSignalHandler handler; + public AgentApplication(BundleContext bundleContext, ExitStatus exitStatus, WriterID writerId) { this(bundleContext, exitStatus, writerId, new ConfigurationCreator(), new DbServiceFactory()); } @@ -203,6 +208,8 @@ shutdownLatch.await(); logger.fine("terminating agent cmd"); } catch (InterruptedException e) { + // Ensure proper shutdown if interrupted + handler.handle(new Signal(SIGINT_NAME)); return; } } @@ -323,9 +330,9 @@ .get(BackendInfoDAO.class.getName()); Agent agent = startAgent(storage, agentInfoDAO, backendInfoDAO); - SignalHandler handler = new CustomSignalHandler(agent, configServer); - Signal.handle(new Signal("INT"), handler); - Signal.handle(new Signal("TERM"), handler); + handler = new CustomSignalHandler(agent, configServer); + Signal.handle(new Signal(SIGINT_NAME), handler); + Signal.handle(new Signal(SIGTERM_NAME), handler); } @Override