git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@964847 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2010-07-16 16:20:21 +00:00
parent f2517c01b8
commit 145c80a298
10 changed files with 90 additions and 62 deletions

View File

@ -99,29 +99,6 @@
<artifactId>org.osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.aop</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>

View File

@ -1941,6 +1941,17 @@ public class BrokerService implements Service {
}
}
/**
* Sets hooks to be executed when broker shut down
*
* @org.apache.xbean.Property
*/
public void setShutdownHooks(List<Runnable> hooks) throws Exception {
for (Runnable hook : hooks) {
addShutdownHook(hook);
}
}
/**
* Causes a clean shutdown of the container when the VM is being shut down
*/

View File

@ -25,12 +25,9 @@ import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.usage.SystemUsage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleException;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
/**
* An ActiveMQ Message Broker. It consists of a number of transport
@ -51,24 +48,6 @@ public class XBeanBrokerService extends BrokerService implements ApplicationCont
private boolean start = true;
private ApplicationContext applicationContext = null;
private boolean destroyApplicationContextOnShutdown = false;
private boolean destroyApplicationContextOnStop = false;
Runnable stopContextRunnable = new Runnable() {
public void run() {
if (applicationContext instanceof ConfigurableApplicationContext) {
((ConfigurableApplicationContext) applicationContext).close();
}
if (applicationContext instanceof OsgiBundleXmlApplicationContext){
try {
((OsgiBundleXmlApplicationContext)applicationContext).getBundle().stop();
} catch (BundleException e) {
LOG.info("Error stopping OSGi bundle " + e, e);
}
}
}
};
public XBeanBrokerService() {
}
@ -84,9 +63,6 @@ public class XBeanBrokerService extends BrokerService implements ApplicationCont
if (start) {
start();
}
if (destroyApplicationContextOnShutdown) {
addShutdownHook(stopContextRunnable);
}
}
private void ensureSystemUsageHasStore() throws IOException {
@ -108,15 +84,6 @@ public class XBeanBrokerService extends BrokerService implements ApplicationCont
public void destroy() throws Exception {
stop();
}
@Override
public void stop() throws Exception {
if (destroyApplicationContextOnStop) {
stopContextRunnable.run();
}
super.stop();
}
/**
@ -132,16 +99,18 @@ public class XBeanBrokerService extends BrokerService implements ApplicationCont
* Sets whether the broker should shutdown the ApplicationContext when the broker jvm is shutdown.
* The broker can be stopped because the underlying JDBC store is unavailable for example.
*/
@Deprecated
public void setDestroyApplicationContextOnShutdown(boolean destroy) {
this.destroyApplicationContextOnShutdown = destroy;
LOG.warn("destroyApplicationContextOnShutdown parameter is deprecated, please use shutdown hooks instead");
}
/**
* 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.
*/
@Deprecated
public void setDestroyApplicationContextOnStop(boolean destroy) {
this.destroyApplicationContextOnStop = destroy;
LOG.warn("destroyApplicationContextOnStop parameter is deprecated, please use shutdown hooks instead");
}
public void setApplicationContext(ApplicationContext applicationContext)

View File

@ -23,6 +23,7 @@
<feature name="activemq-spring" version="${activemq-version}">
<feature version="1.2.0">spring-dm</feature>
<feature version="${activemq-version}">activemq</feature>
<bundle>mvn:org.apache.activemq/activemq-spring/${activemq-version}</bundle>
<bundle>mvn:org.apache.xbean/xbean-spring/${xbean-version}</bundle>
</feature>

View File

@ -100,6 +100,10 @@
</systemUsage>
-->
<shutdownHooks>
<bean xmlns="http://www.springframework.org/schema/beans" id="hook" class="org.apache.activemq.hooks.SpringContextHook" />
</shutdownHooks>
<!-- The transport connectors ActiveMQ will listen to -->
<transportConnectors>
<transportConnector name="openwire" uri="tcp://localhost:61616"/>

View File

@ -39,7 +39,8 @@
</activemq.osgi.import.pkg>
<activemq.osgi.export>
org.apache.activemq.pool*;version=${project.version};-noimport:=;-split-package:=merge-last,
org.apache.activemq.xbean*;version=${project.version};-noimport:=true;-split-package:=merge-last
org.apache.activemq.xbean*;version=${project.version};-noimport:=true;-split-package:=merge-last,
org.apache.activemq.hooks*;version=${project.version};-noimport:=;-split-package:=merge-last
</activemq.osgi.export>
</properties>
@ -108,6 +109,29 @@
<artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.aop</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,35 @@
package org.apache.activemq.hooks;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleException;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
public class SpringContextHook implements Runnable, ApplicationContextAware {
private static final transient Log LOG = LogFactory.getLog(SpringContextHook.class);
ApplicationContext applicationContext;
public void run() {
if (applicationContext instanceof ConfigurableApplicationContext) {
((ConfigurableApplicationContext) applicationContext).close();
}
if (applicationContext instanceof OsgiBundleXmlApplicationContext){
try {
((OsgiBundleXmlApplicationContext)applicationContext).getBundle().stop();
} catch (BundleException e) {
LOG.info("Error stopping OSGi bundle " + e, e);
}
}
}
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}

View File

@ -92,6 +92,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>activemq-xmpp</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-spring</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-web-demo</artifactId>

View File

@ -180,6 +180,7 @@
<include>${pom.groupId}:activemq-optional</include>
<include>${pom.groupId}:activemq-pool</include>
<include>${pom.groupId}:activemq-xmpp</include>
<include>${pom.groupId}:activemq-spring</include>
<include>${pom.groupId}:activeio-core</include>
<include>${pom.groupId}:activemq-jmdns_1.0</include>
<include>commons-beanutils:commons-beanutils</include>
@ -209,8 +210,6 @@
<include>org.codehaus.jettison:jettison</include>
<include>org.apache.velocity:velocity</include>
<include>net.sf.josql:josql</include>
<include>org.osgi:org.osgi.core</include>
<include>org.springframework.osgi:spring-osgi-core</include>
</includes>
</dependencySet>
<dependencySet>
@ -230,7 +229,6 @@
<include>org.mortbay.jetty:jsp-2.1-glassfish</include>
<include>org.mortbay.jetty:jsp-api-2.1-glassfish</include>
<include>org.eclipse.jdt:core</include>
<include>org.apache.ant:ant</include>
<!-- JSTL and other web stuff -->
<include>opensymphony:sitemesh</include>

View File

@ -229,6 +229,11 @@
<artifactId>activemq-pool</artifactId>
<version>${activemq-version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-spring</artifactId>
<version>${activemq-version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-web</artifactId>