You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cs...@apache.org on 2019/02/21 15:34:57 UTC
[activemq] branch master updated: AMQ-7153 - Publish BrokerService
as OSGi service
This is an automated email from the ASF dual-hosted git repository.
cschneider pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq.git
The following commit(s) were added to refs/heads/master by this push:
new 7c872af AMQ-7153 - Publish BrokerService as OSGi service
7c872af is described below
commit 7c872afa222dac97fa139e607a0bac0a71f49111
Author: Christian Schneider <cs...@adobe.com>
AuthorDate: Thu Feb 21 16:34:45 2019 +0100
AMQ-7153 - Publish BrokerService as OSGi service
---
.../activemq/osgi/ActiveMQServiceFactory.java | 25 +++++++++++++++-------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/activemq-osgi/src/main/java/org/apache/activemq/osgi/ActiveMQServiceFactory.java b/activemq-osgi/src/main/java/org/apache/activemq/osgi/ActiveMQServiceFactory.java
index c57d65c..066c05d 100644
--- a/activemq-osgi/src/main/java/org/apache/activemq/osgi/ActiveMQServiceFactory.java
+++ b/activemq-osgi/src/main/java/org/apache/activemq/osgi/ActiveMQServiceFactory.java
@@ -28,6 +28,7 @@ import org.apache.activemq.spring.SpringBrokerContext;
import org.apache.activemq.spring.Utils;
import org.apache.camel.blueprint.CamelContextFactoryBean;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedServiceFactory;
import org.slf4j.Logger;
@@ -45,7 +46,8 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
private static final Logger LOG = LoggerFactory.getLogger(ActiveMQServiceFactory.class);
BundleContext bundleContext;
- HashMap<String, BrokerService> brokers = new HashMap<String, BrokerService>();
+ Map<String, BrokerService> brokers = new HashMap<>();
+ Map<String, ServiceRegistration<BrokerService>> brokerRegs = new HashMap<>();
@Override
public String getName() {
@@ -56,9 +58,8 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
return Collections.unmodifiableMap(brokers);
}
- @SuppressWarnings("rawtypes")
@Override
- synchronized public void updated(String pid, Dictionary properties) throws ConfigurationException {
+ synchronized public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException {
// First stop currently running broker (if any)
deleted(pid);
@@ -143,6 +144,7 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
if (!broker.isSlave())
broker.waitUntilStarted();
brokers.put(pid, broker);
+ brokerRegs.put(pid, bundleContext.registerService(BrokerService.class, broker, properties));
} catch (Exception e) {
throw new ConfigurationException(null, "Cannot start the broker", e);
}
@@ -159,18 +161,25 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
@Override
synchronized public void deleted(String pid) {
- BrokerService broker = brokers.get(pid);
- if (broker == null) {
- return;
+ ServiceRegistration<BrokerService> reg = brokerRegs.remove(pid);
+ if (reg != null) {
+ reg.unregister();
}
- try {
+ BrokerService broker = brokers.remove(pid);
+ if (broker != null) {
+ stop(pid, broker);
+ }
+ }
+
+ private void stop(String pid, BrokerService broker) {
+ try {
LOG.info("Stopping broker " + pid);
broker.stop();
broker.waitUntilStopped();
} catch (Exception e) {
LOG.error("Exception on stopping broker", e);
}
- }
+ }
synchronized public void destroy() {
for (String broker : brokers.keySet()) {