You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2015/11/24 21:17:45 UTC
[5/6] activemq-artemis git commit: More checkstyle fixes
More checkstyle fixes
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/8cc6c2f5
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/8cc6c2f5
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/8cc6c2f5
Branch: refs/heads/master
Commit: 8cc6c2f5fc59692b349b4e24fdd3bd0f36893d26
Parents: b44290d
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Tue Nov 24 14:55:35 2015 +0100
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Tue Nov 24 14:55:35 2015 +0100
----------------------------------------------------------------------
artemis-features/pom.xml | 131 ++++----
.../src/main/resources/features.xml | 16 +
.../proton/ProtonProtocolManagerFactory.java | 2 +-
.../mqtt/MQTTProtocolManagerFactory.java | 2 +-
.../activemq/artemis/osgi/OsgiBroker.java | 320 +++++++++----------
.../activemq/artemis/osgi/ProtocolTracker.java | 158 ++++-----
.../artemis/osgi/ProtocolTrackerCallBack.java | 21 +-
.../artemis/osgi/ProtocolTrackerTest.java | 100 +++---
8 files changed, 412 insertions(+), 338 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/8cc6c2f5/artemis-features/pom.xml
----------------------------------------------------------------------
diff --git a/artemis-features/pom.xml b/artemis-features/pom.xml
index fc91689..3ff8de7 100644
--- a/artemis-features/pom.xml
+++ b/artemis-features/pom.xml
@@ -1,55 +1,78 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-pom</artifactId>
- <version>1.1.1-SNAPSHOT</version>
- </parent>
- <artifactId>artemis-features</artifactId>
- <packaging>pom</packaging>
-
- <build>
- <resources>
- <resource>
- <directory>src/main/resources</directory>
- <filtering>true</filtering>
- </resource>
- </resources>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <executions>
- <execution>
- <id>filter</id>
- <phase>generate-resources</phase>
- <goals>
- <goal>resources</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-artifacts</id>
- <phase>package</phase>
- <goals>
- <goal>attach-artifact</goal>
- </goals>
- <configuration>
- <artifacts>
- <artifact>
- <file>target/classes/features.xml</file>
- <type>xml</type>
- </artifact>
- </artifacts>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>artemis-pom</artifactId>
+ <version>1.1.1-SNAPSHOT</version>
+ </parent>
+ <artifactId>artemis-features</artifactId>
+ <packaging>pom</packaging>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>filter</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>resources</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-artifacts</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>target/classes/features.xml</file>
+ <type>xml</type>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/8cc6c2f5/artemis-features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/artemis-features/src/main/resources/features.xml b/artemis-features/src/main/resources/features.xml
index 0a4f05f..c7cdd32 100644
--- a/artemis-features/src/main/resources/features.xml
+++ b/artemis-features/src/main/resources/features.xml
@@ -1,3 +1,19 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
<?xml version="1.0" encoding="UTF-8"?>
<features name="artemis-${pom.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/8cc6c2f5/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ProtonProtocolManagerFactory.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ProtonProtocolManagerFactory.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ProtonProtocolManagerFactory.java
index 3bcd87b..c11e05b 100644
--- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ProtonProtocolManagerFactory.java
+++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/proton/ProtonProtocolManagerFactory.java
@@ -27,7 +27,7 @@ import org.osgi.service.component.annotations.Component;
import java.util.Collections;
import java.util.List;
-@Component(service=ProtocolManagerFactory.class)
+@Component(service = ProtocolManagerFactory.class)
public class ProtonProtocolManagerFactory extends AbstractProtocolManagerFactory<Interceptor> {
private static final String AMQP_PROTOCOL_NAME = "AMQP";
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/8cc6c2f5/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTProtocolManagerFactory.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTProtocolManagerFactory.java b/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTProtocolManagerFactory.java
index ffbe6e9..5bb34b5 100644
--- a/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTProtocolManagerFactory.java
+++ b/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTProtocolManagerFactory.java
@@ -24,7 +24,7 @@ import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory;
import org.osgi.service.component.annotations.Component;
-@Component(service=ProtocolManagerFactory.class)
+@Component(service = ProtocolManagerFactory.class)
public class MQTTProtocolManagerFactory implements ProtocolManagerFactory {
public static final String MQTT_PROTOCOL_NAME = "MQTT";
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/8cc6c2f5/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/OsgiBroker.java
----------------------------------------------------------------------
diff --git a/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/OsgiBroker.java b/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/OsgiBroker.java
index 5373007..55f7c41 100644
--- a/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/OsgiBroker.java
+++ b/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/OsgiBroker.java
@@ -46,167 +46,167 @@ import org.osgi.service.component.annotations.Deactivate;
import org.osgi.util.tracker.ServiceTracker;
@SuppressWarnings({"unchecked", "rawtypes"})
-@Component(configurationPid="org.apache.activemq.artemis")
+@Component(configurationPid = "org.apache.activemq.artemis")
public class OsgiBroker {
- private String name;
- private String configurationUrl;
- private Map<String, ActiveMQComponent> components;
- private Map<String, ServiceRegistration<?>> registrations;
- private ServiceTracker tracker;
-
- @Activate
- public void activate(ComponentContext cctx) throws Exception {
- final BundleContext context = cctx.getBundleContext();
- final Dictionary<String, Object> properties = cctx.getProperties();
- configurationUrl = getMandatory(properties, "config");
- name = getMandatory(properties, "name");
- String domain = getMandatory(properties, "domain");
- ActiveMQJAASSecurityManager security = new ActiveMQJAASSecurityManager(domain);
- String brokerInstance = null;
- String karafDataDir = System.getProperty("karaf.data");
- if (karafDataDir != null) {
- brokerInstance = karafDataDir + "/artemis/" + name;
- }
-
- // todo if we start to pullout more configs from the main config then we
- // should pull out the configuration objects from factories if available
- FileConfiguration configuration = new FileConfiguration();
- if (brokerInstance != null) {
- configuration.setBrokerInstance(new File(brokerInstance));
- }
- FileJMSConfiguration jmsConfiguration = new FileJMSConfiguration();
-
- FileDeploymentManager fileDeploymentManager = new FileDeploymentManager(configurationUrl);
- fileDeploymentManager.addDeployable(configuration).addDeployable(jmsConfiguration).readConfiguration();
-
- components = fileDeploymentManager.buildService(security, ManagementFactory.getPlatformMBeanServer());
-
- final ActiveMQServer server = (ActiveMQServer)components.get("core");
-
- String[] requiredProtocols = getRequiredProtocols(server.getConfiguration().getAcceptorConfigurations());
- ProtocolTrackerCallBack callback = new ProtocolTrackerCallBack() {
-
- @Override
- public void addFactory(ProtocolManagerFactory<Interceptor> pmf) {
- server.addProtocolManagerFactory(pmf);
+ private String name;
+ private String configurationUrl;
+ private Map<String, ActiveMQComponent> components;
+ private Map<String, ServiceRegistration<?>> registrations;
+ private ServiceTracker tracker;
+
+ @Activate
+ public void activate(ComponentContext cctx) throws Exception {
+ final BundleContext context = cctx.getBundleContext();
+ final Dictionary<String, Object> properties = cctx.getProperties();
+ configurationUrl = getMandatory(properties, "config");
+ name = getMandatory(properties, "name");
+ String domain = getMandatory(properties, "domain");
+ ActiveMQJAASSecurityManager security = new ActiveMQJAASSecurityManager(domain);
+ String brokerInstance = null;
+ String karafDataDir = System.getProperty("karaf.data");
+ if (karafDataDir != null) {
+ brokerInstance = karafDataDir + "/artemis/" + name;
+ }
+
+ // todo if we start to pullout more configs from the main config then we
+ // should pull out the configuration objects from factories if available
+ FileConfiguration configuration = new FileConfiguration();
+ if (brokerInstance != null) {
+ configuration.setBrokerInstance(new File(brokerInstance));
+ }
+ FileJMSConfiguration jmsConfiguration = new FileJMSConfiguration();
+
+ FileDeploymentManager fileDeploymentManager = new FileDeploymentManager(configurationUrl);
+ fileDeploymentManager.addDeployable(configuration).addDeployable(jmsConfiguration).readConfiguration();
+
+ components = fileDeploymentManager.buildService(security, ManagementFactory.getPlatformMBeanServer());
+
+ final ActiveMQServer server = (ActiveMQServer)components.get("core");
+
+ String[] requiredProtocols = getRequiredProtocols(server.getConfiguration().getAcceptorConfigurations());
+ ProtocolTrackerCallBack callback = new ProtocolTrackerCallBack() {
+
+ @Override
+ public void addFactory(ProtocolManagerFactory<Interceptor> pmf) {
+ server.addProtocolManagerFactory(pmf);
+ }
+
+
+ @Override
+ public void removeFactory(ProtocolManagerFactory<Interceptor> pmf) {
+ server.removeProtocolManagerFactory(pmf);
+ }
+
+ @Override
+ public void stop() throws Exception {
+ ActiveMQComponent[] mqComponents = new ActiveMQComponent[components.size()];
+ components.values().toArray(mqComponents);
+ for (int i = mqComponents.length - 1; i >= 0; i--) {
+ mqComponents[i].stop();
}
-
-
- @Override
- public void removeFactory(ProtocolManagerFactory<Interceptor> pmf) {
- server.removeProtocolManagerFactory(pmf);
- }
-
- @Override
- public void stop() throws Exception {
- ActiveMQComponent[] mqComponents = new ActiveMQComponent[components.size()];
- components.values().toArray(mqComponents);
- for (int i = mqComponents.length - 1; i >= 0; i--) {
- mqComponents[i].stop();
- }
- unregister();
- }
-
- @Override
- public void start() throws Exception {
- List<ActiveMQComponent> componentsByStartOrder = getComponentsByStartOrder(components);
- for (ActiveMQComponent component : componentsByStartOrder) {
- component.start();
- }
- register(context, properties);
- }
-
- @Override
- public boolean isStarted() {
- return server.isStarted();
- }
- };
- ProtocolTracker trackerCust = new ProtocolTracker(name, context, requiredProtocols, callback);
- tracker = new ServiceTracker(context, ProtocolManagerFactory.class, trackerCust);
- tracker.open();
- }
-
- private String getMandatory(Dictionary<String, ?> properties, String key) {
- String value = (String) properties.get(key);
- if (value == null) {
- throw new IllegalStateException("Property " + key + " must be set");
- }
- return value;
- }
-
-
- private String[] getRequiredProtocols(Set<TransportConfiguration> acceptors) {
- ArrayList<String> protocols = new ArrayList<String>();
- for (TransportConfiguration acceptor : acceptors) {
- String protoName = acceptor.getName().toUpperCase();
- if (!"ARTEMIS".equals(protoName)) {
- protocols.add(protoName);
- }
- }
- return protocols.toArray(new String[]{});
- }
-
- @Deactivate
- public void stop() throws Exception {
- tracker.close();
- }
-
- public Map<String, ActiveMQComponent> getComponents() {
- return components;
- }
-
- /*
- * this makes sure the components are started in the correct order. Its
- * simple at the mo as e only have core and jms but will need impproving if
- * we get more.
- */
- public ArrayList<ActiveMQComponent> getComponentsByStartOrder(Map<String, ActiveMQComponent> components) {
- ArrayList<ActiveMQComponent> activeMQComponents = new ArrayList<ActiveMQComponent>();
- ActiveMQComponent jmsComponent = components.get("jms");
- if (jmsComponent != null) {
- activeMQComponents.add(jmsComponent);
- }
- activeMQComponents.add(components.get("core"));
- return activeMQComponents;
- }
-
- public void register(BundleContext context, Dictionary<String, ?> properties) {
- registrations = new HashMap<>();
- for (Map.Entry<String, ActiveMQComponent> component : getComponents().entrySet()) {
- String[] classes = getInterfaces(component.getValue());
- Hashtable<String, Object> props = new Hashtable<>();
- for (Enumeration<String> keyEnum = properties.keys(); keyEnum.hasMoreElements();) {
- String key = keyEnum.nextElement();
- Object val = properties.get(key);
- props.put(key, val);
- }
- ServiceRegistration<?> registration = context.registerService(classes, component.getValue(), props);
- registrations.put(component.getKey(), registration);
- }
- }
-
- private String[] getInterfaces(ActiveMQComponent value) {
- Set<String> interfaces = new HashSet<>();
- getInterfaces(value.getClass(), interfaces);
- return interfaces.toArray(new String[interfaces.size()]);
- }
-
- private void getInterfaces(Class<?> clazz, Set<String> interfaces) {
- for (Class<?> itf : clazz.getInterfaces()) {
- if (interfaces.add(itf.getName())) {
- getInterfaces(itf, interfaces);
- }
- }
- if (clazz.getSuperclass() != null) {
- getInterfaces(clazz.getSuperclass(), interfaces);
- }
- }
-
- public void unregister() {
- if (registrations != null) {
- for (ServiceRegistration<?> reg : registrations.values()) {
- reg.unregister();
+ unregister();
+ }
+
+ @Override
+ public void start() throws Exception {
+ List<ActiveMQComponent> componentsByStartOrder = getComponentsByStartOrder(components);
+ for (ActiveMQComponent component : componentsByStartOrder) {
+ component.start();
}
- }
- }
+ register(context, properties);
+ }
+
+ @Override
+ public boolean isStarted() {
+ return server.isStarted();
+ }
+ };
+ ProtocolTracker trackerCust = new ProtocolTracker(name, context, requiredProtocols, callback);
+ tracker = new ServiceTracker(context, ProtocolManagerFactory.class, trackerCust);
+ tracker.open();
+ }
+
+ private String getMandatory(Dictionary<String, ?> properties, String key) {
+ String value = (String) properties.get(key);
+ if (value == null) {
+ throw new IllegalStateException("Property " + key + " must be set");
+ }
+ return value;
+ }
+
+
+ private String[] getRequiredProtocols(Set<TransportConfiguration> acceptors) {
+ ArrayList<String> protocols = new ArrayList<String>();
+ for (TransportConfiguration acceptor : acceptors) {
+ String protoName = acceptor.getName().toUpperCase();
+ if (!"ARTEMIS".equals(protoName)) {
+ protocols.add(protoName);
+ }
+ }
+ return protocols.toArray(new String[]{});
+ }
+
+ @Deactivate
+ public void stop() throws Exception {
+ tracker.close();
+ }
+
+ public Map<String, ActiveMQComponent> getComponents() {
+ return components;
+ }
+
+ /*
+ * this makes sure the components are started in the correct order. Its
+ * simple at the mo as e only have core and jms but will need impproving if
+ * we get more.
+ */
+ public ArrayList<ActiveMQComponent> getComponentsByStartOrder(Map<String, ActiveMQComponent> components) {
+ ArrayList<ActiveMQComponent> activeMQComponents = new ArrayList<ActiveMQComponent>();
+ ActiveMQComponent jmsComponent = components.get("jms");
+ if (jmsComponent != null) {
+ activeMQComponents.add(jmsComponent);
+ }
+ activeMQComponents.add(components.get("core"));
+ return activeMQComponents;
+ }
+
+ public void register(BundleContext context, Dictionary<String, ?> properties) {
+ registrations = new HashMap<>();
+ for (Map.Entry<String, ActiveMQComponent> component : getComponents().entrySet()) {
+ String[] classes = getInterfaces(component.getValue());
+ Hashtable<String, Object> props = new Hashtable<>();
+ for (Enumeration<String> keyEnum = properties.keys(); keyEnum.hasMoreElements();) {
+ String key = keyEnum.nextElement();
+ Object val = properties.get(key);
+ props.put(key, val);
+ }
+ ServiceRegistration<?> registration = context.registerService(classes, component.getValue(), props);
+ registrations.put(component.getKey(), registration);
+ }
+ }
+
+ private String[] getInterfaces(ActiveMQComponent value) {
+ Set<String> interfaces = new HashSet<>();
+ getInterfaces(value.getClass(), interfaces);
+ return interfaces.toArray(new String[interfaces.size()]);
+ }
+
+ private void getInterfaces(Class<?> clazz, Set<String> interfaces) {
+ for (Class<?> itf : clazz.getInterfaces()) {
+ if (interfaces.add(itf.getName())) {
+ getInterfaces(itf, interfaces);
+ }
+ }
+ if (clazz.getSuperclass() != null) {
+ getInterfaces(clazz.getSuperclass(), interfaces);
+ }
+ }
+
+ public void unregister() {
+ if (registrations != null) {
+ for (ServiceRegistration<?> reg : registrations.values()) {
+ reg.unregister();
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/8cc6c2f5/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/ProtocolTracker.java
----------------------------------------------------------------------
diff --git a/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/ProtocolTracker.java b/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/ProtocolTracker.java
index 44bad5e..36430b1 100644
--- a/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/ProtocolTracker.java
+++ b/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/ProtocolTracker.java
@@ -34,96 +34,98 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer;
* Tracks the available ProtocolManagerFactory services as well as the required protocols.
* When a new service appears the factory is added to the server.
* When all needed protocols are present the server is started.
- * When required a service disappears the server is stopped.
+ * When required a service disappears the server is stopped.
*/
@SuppressWarnings("rawtypes")
public class ProtocolTracker implements ServiceTrackerCustomizer<ProtocolManagerFactory<Interceptor>, ProtocolManagerFactory<Interceptor>> {
- private static Logger LOG = Logger.getLogger(ProtocolTracker.class.getName());
- private String name;
- private BundleContext context;
- private Map<String, Boolean> protocols;
- private ProtocolTrackerCallBack callback;
+ private static Logger LOG = Logger.getLogger(ProtocolTracker.class.getName());
+ private String name;
+ private BundleContext context;
+ private Map<String, Boolean> protocols;
+ private ProtocolTrackerCallBack callback;
- public ProtocolTracker(String name, BundleContext context, String[] requiredProtocols, ProtocolTrackerCallBack callback) {
- this.name = name;
- this.context = context;
- this.callback = callback;
- this.protocols = new HashMap<String, Boolean>();
- for (String requiredProtocol : requiredProtocols) {
- this.protocols.put(requiredProtocol, false);
- }
- LOG.info("Broker config " + name + " found. Tracking protocols " + Arrays.asList(requiredProtocols));
- }
+ public ProtocolTracker(String name, BundleContext context, String[] requiredProtocols, ProtocolTrackerCallBack callback) {
+ this.name = name;
+ this.context = context;
+ this.callback = callback;
+ this.protocols = new HashMap<String, Boolean>();
+ for (String requiredProtocol : requiredProtocols) {
+ this.protocols.put(requiredProtocol, false);
+ }
+ LOG.info("Broker config " + name + " found. Tracking protocols " + Arrays.asList(requiredProtocols));
+ }
- @Override
- public ProtocolManagerFactory addingService(ServiceReference<ProtocolManagerFactory<Interceptor>> reference) {
- ProtocolManagerFactory<Interceptor> pmf = context.getService(reference);
- callback.addFactory(pmf);
- for (String protocol : pmf.getProtocols()) {
- protocolAdded(protocol);
- }
+ @Override
+ public ProtocolManagerFactory addingService(ServiceReference<ProtocolManagerFactory<Interceptor>> reference) {
+ ProtocolManagerFactory<Interceptor> pmf = context.getService(reference);
+ callback.addFactory(pmf);
+ for (String protocol : pmf.getProtocols()) {
+ protocolAdded(protocol);
+ }
- return pmf;
- }
+ return pmf;
+ }
- @Override
- public void modifiedService(ServiceReference<ProtocolManagerFactory<Interceptor>> reference, ProtocolManagerFactory<Interceptor> pmf) {
- // Not supported
- }
+ @Override
+ public void modifiedService(ServiceReference<ProtocolManagerFactory<Interceptor>> reference, ProtocolManagerFactory<Interceptor> pmf) {
+ // Not supported
+ }
- @Override
- public void removedService(ServiceReference<ProtocolManagerFactory<Interceptor>> reference, ProtocolManagerFactory<Interceptor> pmf) {
- for (String protocol : pmf.getProtocols()) {
- protocolRemoved(protocol);
- }
- callback.removeFactory(pmf);
- }
-
- private void protocolAdded(String protocol) {
- Boolean present = this.protocols.get(protocol);
- if (present != null && !present) {
- this.protocols.put(protocol, true);
- List<String> missing = getMissing();
- LOG.info("Required protocol " + protocol + " was added for broker " + name + ". " +
- (missing.isEmpty() ? "Starting broker." : "Still waiting for " + missing));
- if (missing.isEmpty()) {
- try {
- callback.start();
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Error starting broker " + name, e);
- }
- }
- }
- }
-
+ @Override
+ public void removedService(ServiceReference<ProtocolManagerFactory<Interceptor>> reference, ProtocolManagerFactory<Interceptor> pmf) {
+ for (String protocol : pmf.getProtocols()) {
+ protocolRemoved(protocol);
+ }
+ callback.removeFactory(pmf);
+ }
- private void protocolRemoved(String protocol) {
- Boolean present = this.protocols.get(protocol);
- if (present != null && present) {
- List<String> missing = getMissing();
- LOG.info("Required protocol " + protocol + " was removed for broker " + name + ". "
- + (missing.isEmpty() ? "Stopping broker. " : ""));
- if (missing.isEmpty()) {
- try {
- callback.stop();
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Error stopping broker " + name, e);
- }
+ private void protocolAdded(String protocol) {
+ Boolean present = this.protocols.get(protocol);
+ if (present != null && !present) {
+ this.protocols.put(protocol, true);
+ List<String> missing = getMissing();
+ LOG.info("Required protocol " + protocol + " was added for broker " + name + ". " +
+ (missing.isEmpty() ? "Starting broker." : "Still waiting for " + missing));
+ if (missing.isEmpty()) {
+ try {
+ callback.start();
+ }
+ catch (Exception e) {
+ LOG.log(Level.WARNING, "Error starting broker " + name, e);
}
- this.protocols.put(protocol, false);
- }
- }
+ }
+ }
+ }
+
- private List<String> getMissing() {
- List<String> missing = new ArrayList<String>();
- for (String protocol : protocols.keySet()) {
- Boolean present = protocols.get(protocol);
- if (!present) {
- missing.add(protocol);
+ private void protocolRemoved(String protocol) {
+ Boolean present = this.protocols.get(protocol);
+ if (present != null && present) {
+ List<String> missing = getMissing();
+ LOG.info("Required protocol " + protocol + " was removed for broker " + name + ". "
+ + (missing.isEmpty() ? "Stopping broker. " : ""));
+ if (missing.isEmpty()) {
+ try {
+ callback.stop();
}
- }
- return missing;
- }
+ catch (Exception e) {
+ LOG.log(Level.WARNING, "Error stopping broker " + name, e);
+ }
+ }
+ this.protocols.put(protocol, false);
+ }
+ }
+
+ private List<String> getMissing() {
+ List<String> missing = new ArrayList<String>();
+ for (String protocol : protocols.keySet()) {
+ Boolean present = protocols.get(protocol);
+ if (!present) {
+ missing.add(protocol);
+ }
+ }
+ return missing;
+ }
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/8cc6c2f5/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/ProtocolTrackerCallBack.java
----------------------------------------------------------------------
diff --git a/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/ProtocolTrackerCallBack.java b/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/ProtocolTrackerCallBack.java
index adcdd6a..9614b53 100644
--- a/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/ProtocolTrackerCallBack.java
+++ b/artemis-server-osgi/src/main/java/org/apache/activemq/artemis/osgi/ProtocolTrackerCallBack.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.activemq.artemis.osgi;
import org.apache.activemq.artemis.api.core.Interceptor;
@@ -5,6 +21,7 @@ import org.apache.activemq.artemis.core.server.ActiveMQComponent;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory;
public interface ProtocolTrackerCallBack extends ActiveMQComponent {
- void addFactory(ProtocolManagerFactory<Interceptor> pmf);
- void removeFactory(ProtocolManagerFactory<Interceptor> pmf);
+ void addFactory(ProtocolManagerFactory<Interceptor> pmf);
+
+ void removeFactory(ProtocolManagerFactory<Interceptor> pmf);
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/8cc6c2f5/artemis-server-osgi/src/test/java/org/apache/activemq/artemis/osgi/ProtocolTrackerTest.java
----------------------------------------------------------------------
diff --git a/artemis-server-osgi/src/test/java/org/apache/activemq/artemis/osgi/ProtocolTrackerTest.java b/artemis-server-osgi/src/test/java/org/apache/activemq/artemis/osgi/ProtocolTrackerTest.java
index 5fd7d8b..46435cd 100644
--- a/artemis-server-osgi/src/test/java/org/apache/activemq/artemis/osgi/ProtocolTrackerTest.java
+++ b/artemis-server-osgi/src/test/java/org/apache/activemq/artemis/osgi/ProtocolTrackerTest.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.activemq.artemis.osgi;
import static org.easymock.EasyMock.expect;
@@ -13,47 +29,47 @@ import org.osgi.framework.ServiceReference;
@SuppressWarnings({"rawtypes", "unchecked"})
public class ProtocolTrackerTest {
- @Test
- public void testLifecycle() throws Exception {
- IMocksControl c = EasyMock.createControl();
- BundleContext context = c.createMock(BundleContext.class);
- String[] requiredProtocols = {"a", "b"};
- ProtocolTrackerCallBack callback = c.createMock(ProtocolTrackerCallBack.class);
-
- RefFact protA = new RefFact(c, context, new String[]{"a"});
- RefFact protB = new RefFact(c, context, new String[]{"b"});
-
- callback.addFactory(protA.factory);
- EasyMock.expectLastCall();
-
- callback.addFactory(protB.factory);
- EasyMock.expectLastCall();
- callback.start();
- EasyMock.expectLastCall();
-
- callback.removeFactory(protA.factory);
- EasyMock.expectLastCall();
- callback.stop();
- EasyMock.expectLastCall();
-
- c.replay();
- ProtocolTracker tracker = new ProtocolTracker("test", context, requiredProtocols, callback);
- tracker.addingService(protA.ref);
- tracker.addingService(protB.ref);
- tracker.removedService(protA.ref, protA.factory);
- c.verify();
- }
-
- class RefFact {
- ServiceReference<ProtocolManagerFactory<Interceptor>> ref;
- ProtocolManagerFactory factory;
-
- public RefFact(IMocksControl c, BundleContext context, String[] protocols) {
- ref = c.createMock(ServiceReference.class);
- factory = c.createMock(ProtocolManagerFactory.class);
- expect(factory.getProtocols()).andReturn(protocols).atLeastOnce();
- expect(context.getService(ref)).andReturn(factory).atLeastOnce();
- }
- }
+ @Test
+ public void testLifecycle() throws Exception {
+ IMocksControl c = EasyMock.createControl();
+ BundleContext context = c.createMock(BundleContext.class);
+ String[] requiredProtocols = {"a", "b"};
+ ProtocolTrackerCallBack callback = c.createMock(ProtocolTrackerCallBack.class);
+
+ RefFact protA = new RefFact(c, context, new String[]{"a"});
+ RefFact protB = new RefFact(c, context, new String[]{"b"});
+
+ callback.addFactory(protA.factory);
+ EasyMock.expectLastCall();
+
+ callback.addFactory(protB.factory);
+ EasyMock.expectLastCall();
+ callback.start();
+ EasyMock.expectLastCall();
+
+ callback.removeFactory(protA.factory);
+ EasyMock.expectLastCall();
+ callback.stop();
+ EasyMock.expectLastCall();
+
+ c.replay();
+ ProtocolTracker tracker = new ProtocolTracker("test", context, requiredProtocols, callback);
+ tracker.addingService(protA.ref);
+ tracker.addingService(protB.ref);
+ tracker.removedService(protA.ref, protA.factory);
+ c.verify();
+ }
+
+ class RefFact {
+ ServiceReference<ProtocolManagerFactory<Interceptor>> ref;
+ ProtocolManagerFactory factory;
+
+ public RefFact(IMocksControl c, BundleContext context, String[] protocols) {
+ ref = c.createMock(ServiceReference.class);
+ factory = c.createMock(ProtocolManagerFactory.class);
+ expect(factory.getProtocols()).andReturn(protocols).atLeastOnce();
+ expect(context.getService(ref)).andReturn(factory).atLeastOnce();
+ }
+ }
}