AMQ-1733: Add an option to allow the xbean broker to destroy the spring application context when the broker is stopped

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@657059 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Guillaume Nodet 2008-05-16 13:38:29 +00:00
parent 2076f452e7
commit b609bdb95b
4 changed files with 31 additions and 0 deletions

View File

@ -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;

View File

@ -824,6 +824,14 @@ with JUnit tests you may wish to start and stop the broker explicitly yourself.
]]></xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name='destroyApplicationContextOnShutdown' type='xs:boolean'>
<xs:annotation>
<xs:documentation><![CDATA[
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.
]]></xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name='supportFailOver' type='xs:boolean'/>
<xs:attribute name='systemExitOnShutdown' type='xs:boolean'/>
<xs:attribute name='systemExitOnShutdownExitCode' type='xs:integer'/>

View File

@ -401,6 +401,8 @@ the JDBC and Journal persistence adaptors.</td></tr>
<tr><td>dedicatedTaskRunner</td><td>xs:boolean</td><td></td></tr>
<tr><td>deleteAllMessagesOnStartup</td><td>xs:boolean</td><td>Sets whether or not all messages are deleted on startup - mostly only
useful for testing.</td></tr>
<tr><td>destroyApplicationContextOnShutdown</td><td>xs:boolean</td><td> 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.</td></tr>
<tr><td>enableStatistics</td><td>xs:boolean</td><td>Sets whether or not the Broker's services enable statistics or not.</td></tr>
<tr><td>keepDurableSubsActive</td><td>xs:boolean</td><td></td></tr>
<tr><td>masterConnectorURI</td><td>xs:string</td><td></td></tr>

View File

@ -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} |