summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2012-02-23 14:20:07 +0000
committerRobert Gemmell <robbie@apache.org>2012-02-23 14:20:07 +0000
commit79c70c772bd35bb24bc64d98eb8cc1b42577e1d1 (patch)
tree812e957349f3264e9f0709f20d4058e33fba54d5
parent375bc332fb0fd497707d9ceb9901c87bc686538d (diff)
downloadqpid-python-79c70c772bd35bb24bc64d98eb8cc1b42577e1d1.tar.gz
QPID-3325: move shutdown hook handling into Broker, set the thread name
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1292811 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java66
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java60
2 files changed, 66 insertions, 60 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java
index 072f8dc132..18f69853e6 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java
@@ -20,6 +20,7 @@
*/
package org.apache.qpid.server;
+import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.QpidLog4JConfigurator;
@@ -59,8 +60,11 @@ import java.util.Set;
public class Broker
{
+ private static final Logger LOGGER = Logger.getLogger(Broker.class);
+
private static final int IPV4_ADDRESS_LENGTH = 4;
private static final char IPV4_LITERAL_SEPARATOR = '.';
+ private volatile Thread _shutdownHookThread;
protected static class InitException extends RuntimeException
{
@@ -74,7 +78,14 @@ public class Broker
public void shutdown()
{
- ApplicationRegistry.remove();
+ try
+ {
+ removeShutdownHook();
+ }
+ finally
+ {
+ ApplicationRegistry.remove();
+ }
}
public void startup() throws Exception
@@ -88,6 +99,7 @@ public class Broker
{
CurrentActor.set(new BrokerActor(new SystemOutMessageLogger()));
startupImpl(options);
+ addShutdownHook();
}
finally
{
@@ -441,4 +453,56 @@ public class Broker
blm.register();
}
+
+ private void addShutdownHook()
+ {
+ Thread shutdownHookThread = new Thread(new ShutdownService());
+ shutdownHookThread.setName("QpidBrokerShutdownHook");
+
+ Runtime.getRuntime().addShutdownHook(shutdownHookThread);
+ _shutdownHookThread = shutdownHookThread;
+
+ LOGGER.debug("Added shutdown hook");
+ }
+
+ private void removeShutdownHook()
+ {
+ Thread shutdownThread = _shutdownHookThread;
+
+ //if there is a shutdown thread and we aren't it, we should remove it
+ if(shutdownThread != null && !(Thread.currentThread() == shutdownThread))
+ {
+ LOGGER.debug("Removing shutdown hook");
+
+ _shutdownHookThread = null;
+
+ boolean removed = false;
+ try
+ {
+ removed = Runtime.getRuntime().removeShutdownHook(shutdownThread);
+ }
+ catch(IllegalStateException ise)
+ {
+ //ignore, means the JVM is already shutting down
+ }
+
+ if(LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Removed shutdown hook: " + removed);
+ }
+ }
+ else
+ {
+ LOGGER.debug("Skipping shutdown hook removal as there either isnt one, or we are it.");
+ }
+ }
+
+ private class ShutdownService implements Runnable
+ {
+ public void run()
+ {
+ LOGGER.debug("Shutdown hook running");
+ Broker.this.shutdown();
+ }
+ }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
index 3ca6dc1dc5..9951f7d3c8 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
@@ -82,8 +82,6 @@ public abstract class ApplicationRegistry implements IApplicationRegistry
private static AtomicReference<IApplicationRegistry> _instance = new AtomicReference<IApplicationRegistry>(null);
- private volatile Thread _shutdownHookThread;
-
private final ServerConfiguration _configuration;
private final Map<InetSocketAddress, QpidAcceptor> _acceptors = new HashMap<InetSocketAddress, QpidAcceptor>();
@@ -188,14 +186,6 @@ public abstract class ApplicationRegistry implements IApplicationRegistry
_qmfService = qmfService;
}
- private static class ShutdownService implements Runnable
- {
- public void run()
- {
- remove();
- }
- }
-
public static void initialise(IApplicationRegistry instance) throws Exception
{
if(instance == null)
@@ -243,45 +233,6 @@ public abstract class ApplicationRegistry implements IApplicationRegistry
}
}
- private void addShutdownHook()
- {
- Thread shutdownHookThread = new Thread(new ShutdownService());
- Runtime.getRuntime().addShutdownHook(shutdownHookThread);
- _shutdownHookThread = shutdownHookThread;
- }
-
- private void removeShutdownHook()
- {
- Thread shutdownThread = _shutdownHookThread;
-
- //if there is a shutdown thread and we aren't it, we should remove it
- if(shutdownThread != null && !(Thread.currentThread() == shutdownThread))
- {
- _logger.debug("Removing shutdown hook");
-
- _shutdownHookThread = null;
-
- boolean removed = false;
- try
- {
- removed = Runtime.getRuntime().removeShutdownHook(shutdownThread);
- }
- catch(IllegalStateException ise)
- {
- //ignore, means the JVM is already shutting down
- }
-
- if(_logger.isDebugEnabled())
- {
- _logger.debug("Removed shutdown hook: " + removed);
- }
- }
- else
- {
- _logger.debug("Skipping shutdown hook removal as there either isnt one, or we are it.");
- }
- }
-
public ConfigStore getConfigStore()
{
return _configStore;
@@ -390,8 +341,6 @@ public abstract class ApplicationRegistry implements IApplicationRegistry
// Startup complete, so pop the current actor
CurrentActor.remove();
}
-
- addShutdownHook();
}
@@ -614,14 +563,7 @@ public abstract class ApplicationRegistry implements IApplicationRegistry
}
finally
{
- try
- {
- CurrentActor.remove();
- }
- finally
- {
- removeShutdownHook();
- }
+ CurrentActor.remove();
}
}