https://issues.apache.org/jira/browse/AMQ-4034 - adding logging and proper shutdown on destroy

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1436827 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2013-01-22 10:07:36 +00:00
parent a30dd30114
commit fd46439e7e
3 changed files with 16 additions and 7 deletions

View File

@ -55,7 +55,6 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>

View File

@ -22,6 +22,8 @@ import org.apache.xbean.spring.context.ResourceXmlApplicationContext;
import org.osgi.framework.BundleContext;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedServiceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource;
@ -32,6 +34,8 @@ import java.util.Map;
public class ActiveMQServiceFactory implements ManagedServiceFactory {
private static final Logger LOG = LoggerFactory.getLogger(ActiveMQServiceFactory.class);
BundleContext bundleContext;
HashMap<String, BrokerService> brokers = new HashMap<String, BrokerService>();
@ -41,7 +45,7 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
}
@Override
public void updated(String pid, Dictionary properties) throws ConfigurationException {
synchronized public void updated(String pid, Dictionary properties) throws ConfigurationException {
String config = (String)properties.get("config");
if (config == null) {
throw new ConfigurationException("config", "Property must be set");
@ -77,18 +81,24 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
}
@Override
public void deleted(String pid) {
synchronized public void deleted(String pid) {
LOG.info("Stopping broker " + pid);
BrokerService broker = brokers.get(pid);
if (broker == null) {
//TODO LOG
LOG.warn("Broker " + pid + " not found");
return;
}
try {
broker.stop();
broker.waitUntilStopped();
} catch (Exception e) {
//TODO LOG
e.printStackTrace();
LOG.error("Exception on stopping broker", e);
}
}
synchronized public void destroy() {
for (String broker: brokers.keySet()) {
deleted(broker);
}
}

View File

@ -20,7 +20,7 @@
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:shell="http://karaf.apache.org/xmlns/shell/v1.0.0">
<bean id="activeMQServiceFactory" class="org.apache.activemq.karaf.ActiveMQServiceFactory">
<bean id="activeMQServiceFactory" class="org.apache.activemq.karaf.ActiveMQServiceFactory" destroy-method="destroy">
<property name="bundleContext" ref="blueprintBundleContext"/>
</bean>