mirror of
https://github.com/apache/activemq.git
synced 2025-02-16 23:16:52 +00:00
Add a getter for the BrokerService map.
This commit is contained in:
parent
bbd61084e0
commit
d9b03acffb
@ -16,6 +16,13 @@
|
||||
*/
|
||||
package org.apache.activemq.osgi;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.spring.SpringBrokerContext;
|
||||
import org.apache.activemq.spring.Utils;
|
||||
@ -29,8 +36,6 @@ import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ActiveMQServiceFactory.class);
|
||||
@ -43,17 +48,22 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
||||
return "ActiveMQ Server Controller";
|
||||
}
|
||||
|
||||
public Map<String, BrokerService> getBrokersMap() {
|
||||
return Collections.unmodifiableMap(brokers);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
synchronized public void updated(String pid, Dictionary properties) throws ConfigurationException {
|
||||
|
||||
// First stop currently running broker (if any)
|
||||
deleted(pid);
|
||||
|
||||
String config = (String)properties.get("config");
|
||||
String config = (String) properties.get("config");
|
||||
if (config == null) {
|
||||
throw new ConfigurationException("config", "Property must be set");
|
||||
}
|
||||
String name = (String)properties.get("broker-name");
|
||||
String name = (String) properties.get("broker-name");
|
||||
if (name == null) {
|
||||
throw new ConfigurationException("broker-name", "Property must be set");
|
||||
}
|
||||
@ -65,18 +75,18 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
||||
Resource resource = Utils.resourceFromString(config);
|
||||
|
||||
ResourceXmlApplicationContext ctx = new ResourceXmlApplicationContext(resource, Collections.EMPTY_LIST, null, Collections.EMPTY_LIST, false) {
|
||||
@Override
|
||||
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
|
||||
reader.setValidating(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Handle properties in configuration
|
||||
PropertyPlaceholderConfigurer configurator =
|
||||
new PropertyPlaceholderConfigurer();
|
||||
PropertyPlaceholderConfigurer configurator = new PropertyPlaceholderConfigurer();
|
||||
|
||||
//convert dictionary to properties. Is there a better way?
|
||||
// convert dictionary to properties. Is there a better way?
|
||||
Properties props = new Properties();
|
||||
Enumeration elements = properties.keys();
|
||||
Enumeration<?> elements = properties.keys();
|
||||
while (elements.hasMoreElements()) {
|
||||
Object key = elements.nextElement();
|
||||
props.put(key, properties.get(key));
|
||||
@ -94,7 +104,7 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
||||
if (broker == null) {
|
||||
throw new ConfigurationException(null, "Broker not defined");
|
||||
}
|
||||
//TODO deal with multiple brokers
|
||||
// TODO deal with multiple brokers
|
||||
|
||||
SpringBrokerContext brokerContext = new SpringBrokerContext();
|
||||
brokerContext.setConfigurationUrl(resource.getURL().toExternalForm());
|
||||
@ -104,8 +114,6 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
||||
broker.start();
|
||||
broker.waitUntilStarted();
|
||||
brokers.put(pid, broker);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ConfigurationException(null, "Cannot start the broker", e);
|
||||
}
|
||||
@ -127,7 +135,7 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
||||
}
|
||||
|
||||
synchronized public void destroy() {
|
||||
for (String broker: brokers.keySet()) {
|
||||
for (String broker : brokers.keySet()) {
|
||||
deleted(broker);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user