diff --git a/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerService.java b/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerService.java index f07c72b44b..446445a8f4 100644 --- a/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerService.java +++ b/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerService.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ConfigurableApplicationContext; /** * An ActiveMQ Message Broker. It consists of a number of transport @@ -41,6 +42,7 @@ public class XBeanBrokerService extends BrokerService implements InitializingBea private boolean start = true; private ApplicationContext applicationContext = null; + private boolean destroyApplicationContextOnShutdown = false; public XBeanBrokerService() { } @@ -49,6 +51,15 @@ public class XBeanBrokerService extends BrokerService implements InitializingBea if (start) { start(); } + if (destroyApplicationContextOnShutdown) { + addShutdownHook(new Runnable() { + public void run() { + if (applicationContext instanceof ConfigurableApplicationContext) { + ((ConfigurableApplicationContext) applicationContext).close(); + } + } + }); + } } public void destroy() throws Exception { @@ -68,6 +79,14 @@ public class XBeanBrokerService extends BrokerService implements InitializingBea this.start = start; } + /** + * Sets whether the broker should shutdown the ApplicationContext when the broker is stopped. + * The broker can be stopped because the underlying JDBC store is unavailable for example. + */ + public void setDestroyApplicationContextOnShutdown(boolean destroy) { + this.destroyApplicationContextOnShutdown = destroy; + } + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; diff --git a/activemq-core/src/main/resources/activemq.xsd b/activemq-core/src/main/resources/activemq.xsd index 8b4e98118f..83dbb6bea6 100644 --- a/activemq-core/src/main/resources/activemq.xsd +++ b/activemq-core/src/main/resources/activemq.xsd @@ -824,6 +824,14 @@ with JUnit tests you may wish to start and stop the broker explicitly yourself. ]]> + + + + + diff --git a/activemq-core/src/main/resources/activemq.xsd.html b/activemq-core/src/main/resources/activemq.xsd.html index 595d886331..7c853ea26c 100644 --- a/activemq-core/src/main/resources/activemq.xsd.html +++ b/activemq-core/src/main/resources/activemq.xsd.html @@ -401,6 +401,8 @@ the JDBC and Journal persistence adaptors. dedicatedTaskRunnerxs:boolean deleteAllMessagesOnStartupxs:booleanSets whether or not all messages are deleted on startup - mostly only useful for testing. + destroyApplicationContextOnShutdownxs:boolean Sets whether the broker should shutdown the ApplicationContext when the broker is stopped. +The broker can be stopped because the underlying JDBC store is unavailable for example. enableStatisticsxs:booleanSets whether or not the Broker's services enable statistics or not. keepDurableSubsActivexs:boolean masterConnectorURIxs:string diff --git a/activemq-core/src/main/resources/activemq.xsd.wiki b/activemq-core/src/main/resources/activemq.xsd.wiki index be0add4e41..4452b64bad 100644 --- a/activemq-core/src/main/resources/activemq.xsd.wiki +++ b/activemq-core/src/main/resources/activemq.xsd.wiki @@ -642,6 +642,8 @@ useful for testing.{html} | | destinationPolicy | _[org.apache.activemq.broker.region.policy.PolicyMap|#org.apache.activemq.broker.region.policy.PolicyMap-types]_ | {html}Sets the destination specific policies available either for exact destinations or for wildcard areas of destinations.{html} | | destinations | (_[org.apache.activemq.command.ActiveMQDestination|#org.apache.activemq.command.ActiveMQDestination-types]_)\* | {html}Sets the destinations which should be loaded/created on startup{html} | + | destroyApplicationContextOnShutdown | _boolean_ | {html}Sets whether the broker should shutdown the ApplicationContext when the broker is stopped. + The broker can be stopped because the underlying JDBC store is unavailable for example.{html} | | enableStatistics | _boolean_ | {html}Sets whether or not the Broker's services enable statistics or not.{html} | | jmsBridgeConnectors | (_[org.apache.activemq.network.jms.JmsConnector|#org.apache.activemq.network.jms.JmsConnector-types]_)\* | {html}{html} | | keepDurableSubsActive | _boolean_ | {html}{html} |