More checkstyle fixes

This commit is contained in:
Christian Schneider 2015-11-24 14:55:35 +01:00
parent b44290df75
commit 8cc6c2f5fc
8 changed files with 389 additions and 315 deletions

View File

@ -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> ~ Licensed to the Apache Software Foundation (ASF) under one or more
<parent> ~ contributor license agreements. See the NOTICE file distributed with
<groupId>org.apache.activemq</groupId> ~ this work for additional information regarding copyright ownership.
<artifactId>artemis-pom</artifactId> ~ The ASF licenses this file to You under the Apache License, Version 2.0
<version>1.1.1-SNAPSHOT</version> ~ (the "License"); you may not use this file except in compliance with
</parent> ~ the License. You may obtain a copy of the License at
<artifactId>artemis-features</artifactId> ~
<packaging>pom</packaging> ~ http://www.apache.org/licenses/LICENSE-2.0
~
<build> ~ Unless required by applicable law or agreed to in writing, software
<resources> ~ distributed under the License is distributed on an "AS IS" BASIS,
<resource> ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<directory>src/main/resources</directory> ~ See the License for the specific language governing permissions and
<filtering>true</filtering> ~ limitations under the License.
</resource> -->
</resources> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<plugins> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<plugin> <modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugins</groupId> <parent>
<artifactId>maven-resources-plugin</artifactId> <groupId>org.apache.activemq</groupId>
<executions> <artifactId>artemis-pom</artifactId>
<execution> <version>1.1.1-SNAPSHOT</version>
<id>filter</id> </parent>
<phase>generate-resources</phase> <artifactId>artemis-features</artifactId>
<goals> <packaging>pom</packaging>
<goal>resources</goal>
</goals> <build>
</execution> <resources>
</executions> <resource>
</plugin> <directory>src/main/resources</directory>
<plugin> <filtering>true</filtering>
<groupId>org.codehaus.mojo</groupId> </resource>
<artifactId>build-helper-maven-plugin</artifactId> </resources>
<executions> <plugins>
<execution> <plugin>
<id>attach-artifacts</id> <artifactId>maven-checkstyle-plugin</artifactId>
<phase>package</phase> <configuration>
<goals> <skip>true</skip>
<goal>attach-artifact</goal> </configuration>
</goals> </plugin>
<configuration> <plugin>
<artifacts> <groupId>org.apache.maven.plugins</groupId>
<artifact> <artifactId>maven-resources-plugin</artifactId>
<file>target/classes/features.xml</file> <executions>
<type>xml</type> <execution>
</artifact> <id>filter</id>
</artifacts> <phase>generate-resources</phase>
</configuration> <goals>
</execution> <goal>resources</goal>
</executions> </goals>
</plugin> </execution>
</plugins> </executions>
</build> </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> </project>

View File

@ -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"?> <?xml version="1.0" encoding="UTF-8"?>
<features name="artemis-${pom.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.3.0" <features name="artemis-${pom.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

View File

@ -27,7 +27,7 @@ import org.osgi.service.component.annotations.Component;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@Component(service=ProtocolManagerFactory.class) @Component(service = ProtocolManagerFactory.class)
public class ProtonProtocolManagerFactory extends AbstractProtocolManagerFactory<Interceptor> { public class ProtonProtocolManagerFactory extends AbstractProtocolManagerFactory<Interceptor> {
private static final String AMQP_PROTOCOL_NAME = "AMQP"; private static final String AMQP_PROTOCOL_NAME = "AMQP";

View File

@ -24,7 +24,7 @@ import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory; import org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory;
import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Component;
@Component(service=ProtocolManagerFactory.class) @Component(service = ProtocolManagerFactory.class)
public class MQTTProtocolManagerFactory implements ProtocolManagerFactory { public class MQTTProtocolManagerFactory implements ProtocolManagerFactory {
public static final String MQTT_PROTOCOL_NAME = "MQTT"; public static final String MQTT_PROTOCOL_NAME = "MQTT";

View File

@ -46,167 +46,167 @@ import org.osgi.service.component.annotations.Deactivate;
import org.osgi.util.tracker.ServiceTracker; import org.osgi.util.tracker.ServiceTracker;
@SuppressWarnings({"unchecked", "rawtypes"}) @SuppressWarnings({"unchecked", "rawtypes"})
@Component(configurationPid="org.apache.activemq.artemis") @Component(configurationPid = "org.apache.activemq.artemis")
public class OsgiBroker { public class OsgiBroker {
private String name; private String name;
private String configurationUrl; private String configurationUrl;
private Map<String, ActiveMQComponent> components; private Map<String, ActiveMQComponent> components;
private Map<String, ServiceRegistration<?>> registrations; private Map<String, ServiceRegistration<?>> registrations;
private ServiceTracker tracker; private ServiceTracker tracker;
@Activate @Activate
public void activate(ComponentContext cctx) throws Exception { public void activate(ComponentContext cctx) throws Exception {
final BundleContext context = cctx.getBundleContext(); final BundleContext context = cctx.getBundleContext();
final Dictionary<String, Object> properties = cctx.getProperties(); final Dictionary<String, Object> properties = cctx.getProperties();
configurationUrl = getMandatory(properties, "config"); configurationUrl = getMandatory(properties, "config");
name = getMandatory(properties, "name"); name = getMandatory(properties, "name");
String domain = getMandatory(properties, "domain"); String domain = getMandatory(properties, "domain");
ActiveMQJAASSecurityManager security = new ActiveMQJAASSecurityManager(domain); ActiveMQJAASSecurityManager security = new ActiveMQJAASSecurityManager(domain);
String brokerInstance = null; String brokerInstance = null;
String karafDataDir = System.getProperty("karaf.data"); String karafDataDir = System.getProperty("karaf.data");
if (karafDataDir != null) { if (karafDataDir != null) {
brokerInstance = karafDataDir + "/artemis/" + name; brokerInstance = karafDataDir + "/artemis/" + name;
} }
// todo if we start to pullout more configs from the main config then we // todo if we start to pullout more configs from the main config then we
// should pull out the configuration objects from factories if available // should pull out the configuration objects from factories if available
FileConfiguration configuration = new FileConfiguration(); FileConfiguration configuration = new FileConfiguration();
if (brokerInstance != null) { if (brokerInstance != null) {
configuration.setBrokerInstance(new File(brokerInstance)); configuration.setBrokerInstance(new File(brokerInstance));
} }
FileJMSConfiguration jmsConfiguration = new FileJMSConfiguration(); FileJMSConfiguration jmsConfiguration = new FileJMSConfiguration();
FileDeploymentManager fileDeploymentManager = new FileDeploymentManager(configurationUrl); FileDeploymentManager fileDeploymentManager = new FileDeploymentManager(configurationUrl);
fileDeploymentManager.addDeployable(configuration).addDeployable(jmsConfiguration).readConfiguration(); fileDeploymentManager.addDeployable(configuration).addDeployable(jmsConfiguration).readConfiguration();
components = fileDeploymentManager.buildService(security, ManagementFactory.getPlatformMBeanServer()); components = fileDeploymentManager.buildService(security, ManagementFactory.getPlatformMBeanServer());
final ActiveMQServer server = (ActiveMQServer)components.get("core"); final ActiveMQServer server = (ActiveMQServer)components.get("core");
String[] requiredProtocols = getRequiredProtocols(server.getConfiguration().getAcceptorConfigurations()); String[] requiredProtocols = getRequiredProtocols(server.getConfiguration().getAcceptorConfigurations());
ProtocolTrackerCallBack callback = new ProtocolTrackerCallBack() { ProtocolTrackerCallBack callback = new ProtocolTrackerCallBack() {
@Override @Override
public void addFactory(ProtocolManagerFactory<Interceptor> pmf) { public void addFactory(ProtocolManagerFactory<Interceptor> pmf) {
server.addProtocolManagerFactory(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();
} }
unregister();
}
@Override @Override
public void removeFactory(ProtocolManagerFactory<Interceptor> pmf) { public void start() throws Exception {
server.removeProtocolManagerFactory(pmf); List<ActiveMQComponent> componentsByStartOrder = getComponentsByStartOrder(components);
for (ActiveMQComponent component : componentsByStartOrder) {
component.start();
} }
register(context, properties);
@Override }
public void stop() throws Exception {
ActiveMQComponent[] mqComponents = new ActiveMQComponent[components.size()]; @Override
components.values().toArray(mqComponents); public boolean isStarted() {
for (int i = mqComponents.length - 1; i >= 0; i--) { return server.isStarted();
mqComponents[i].stop(); }
} };
unregister(); ProtocolTracker trackerCust = new ProtocolTracker(name, context, requiredProtocols, callback);
} tracker = new ServiceTracker(context, ProtocolManagerFactory.class, trackerCust);
tracker.open();
@Override }
public void start() throws Exception {
List<ActiveMQComponent> componentsByStartOrder = getComponentsByStartOrder(components); private String getMandatory(Dictionary<String, ?> properties, String key) {
for (ActiveMQComponent component : componentsByStartOrder) { String value = (String) properties.get(key);
component.start(); if (value == null) {
} throw new IllegalStateException("Property " + key + " must be set");
register(context, properties); }
} return value;
}
@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) { private String[] getRequiredProtocols(Set<TransportConfiguration> acceptors) {
ArrayList<String> protocols = new ArrayList<String>(); ArrayList<String> protocols = new ArrayList<String>();
for (TransportConfiguration acceptor : acceptors) { for (TransportConfiguration acceptor : acceptors) {
String protoName = acceptor.getName().toUpperCase(); String protoName = acceptor.getName().toUpperCase();
if (!"ARTEMIS".equals(protoName)) { if (!"ARTEMIS".equals(protoName)) {
protocols.add(protoName); protocols.add(protoName);
} }
} }
return protocols.toArray(new String[]{}); return protocols.toArray(new String[]{});
} }
@Deactivate @Deactivate
public void stop() throws Exception { public void stop() throws Exception {
tracker.close(); tracker.close();
} }
public Map<String, ActiveMQComponent> getComponents() { public Map<String, ActiveMQComponent> getComponents() {
return components; return components;
} }
/* /*
* this makes sure the components are started in the correct order. Its * 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 * simple at the mo as e only have core and jms but will need impproving if
* we get more. * we get more.
*/ */
public ArrayList<ActiveMQComponent> getComponentsByStartOrder(Map<String, ActiveMQComponent> components) { public ArrayList<ActiveMQComponent> getComponentsByStartOrder(Map<String, ActiveMQComponent> components) {
ArrayList<ActiveMQComponent> activeMQComponents = new ArrayList<ActiveMQComponent>(); ArrayList<ActiveMQComponent> activeMQComponents = new ArrayList<ActiveMQComponent>();
ActiveMQComponent jmsComponent = components.get("jms"); ActiveMQComponent jmsComponent = components.get("jms");
if (jmsComponent != null) { if (jmsComponent != null) {
activeMQComponents.add(jmsComponent); activeMQComponents.add(jmsComponent);
} }
activeMQComponents.add(components.get("core")); activeMQComponents.add(components.get("core"));
return activeMQComponents; return activeMQComponents;
} }
public void register(BundleContext context, Dictionary<String, ?> properties) { public void register(BundleContext context, Dictionary<String, ?> properties) {
registrations = new HashMap<>(); registrations = new HashMap<>();
for (Map.Entry<String, ActiveMQComponent> component : getComponents().entrySet()) { for (Map.Entry<String, ActiveMQComponent> component : getComponents().entrySet()) {
String[] classes = getInterfaces(component.getValue()); String[] classes = getInterfaces(component.getValue());
Hashtable<String, Object> props = new Hashtable<>(); Hashtable<String, Object> props = new Hashtable<>();
for (Enumeration<String> keyEnum = properties.keys(); keyEnum.hasMoreElements();) { for (Enumeration<String> keyEnum = properties.keys(); keyEnum.hasMoreElements();) {
String key = keyEnum.nextElement(); String key = keyEnum.nextElement();
Object val = properties.get(key); Object val = properties.get(key);
props.put(key, val); props.put(key, val);
} }
ServiceRegistration<?> registration = context.registerService(classes, component.getValue(), props); ServiceRegistration<?> registration = context.registerService(classes, component.getValue(), props);
registrations.put(component.getKey(), registration); registrations.put(component.getKey(), registration);
} }
} }
private String[] getInterfaces(ActiveMQComponent value) { private String[] getInterfaces(ActiveMQComponent value) {
Set<String> interfaces = new HashSet<>(); Set<String> interfaces = new HashSet<>();
getInterfaces(value.getClass(), interfaces); getInterfaces(value.getClass(), interfaces);
return interfaces.toArray(new String[interfaces.size()]); return interfaces.toArray(new String[interfaces.size()]);
} }
private void getInterfaces(Class<?> clazz, Set<String> interfaces) { private void getInterfaces(Class<?> clazz, Set<String> interfaces) {
for (Class<?> itf : clazz.getInterfaces()) { for (Class<?> itf : clazz.getInterfaces()) {
if (interfaces.add(itf.getName())) { if (interfaces.add(itf.getName())) {
getInterfaces(itf, interfaces); getInterfaces(itf, interfaces);
} }
} }
if (clazz.getSuperclass() != null) { if (clazz.getSuperclass() != null) {
getInterfaces(clazz.getSuperclass(), interfaces); getInterfaces(clazz.getSuperclass(), interfaces);
} }
} }
public void unregister() { public void unregister() {
if (registrations != null) { if (registrations != null) {
for (ServiceRegistration<?> reg : registrations.values()) { for (ServiceRegistration<?> reg : registrations.values()) {
reg.unregister(); reg.unregister();
} }
} }
} }
} }

View File

@ -34,96 +34,98 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer;
* Tracks the available ProtocolManagerFactory services as well as the required protocols. * Tracks the available ProtocolManagerFactory services as well as the required protocols.
* When a new service appears the factory is added to the server. * When a new service appears the factory is added to the server.
* When all needed protocols are present the server is started. * 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") @SuppressWarnings("rawtypes")
public class ProtocolTracker implements ServiceTrackerCustomizer<ProtocolManagerFactory<Interceptor>, ProtocolManagerFactory<Interceptor>> { public class ProtocolTracker implements ServiceTrackerCustomizer<ProtocolManagerFactory<Interceptor>, ProtocolManagerFactory<Interceptor>> {
private static Logger LOG = Logger.getLogger(ProtocolTracker.class.getName()); private static Logger LOG = Logger.getLogger(ProtocolTracker.class.getName());
private String name; private String name;
private BundleContext context; private BundleContext context;
private Map<String, Boolean> protocols; private Map<String, Boolean> protocols;
private ProtocolTrackerCallBack callback; private ProtocolTrackerCallBack callback;
public ProtocolTracker(String name, BundleContext context, String[] requiredProtocols, ProtocolTrackerCallBack callback) { public ProtocolTracker(String name, BundleContext context, String[] requiredProtocols, ProtocolTrackerCallBack callback) {
this.name = name; this.name = name;
this.context = context; this.context = context;
this.callback = callback; this.callback = callback;
this.protocols = new HashMap<String, Boolean>(); this.protocols = new HashMap<String, Boolean>();
for (String requiredProtocol : requiredProtocols) { for (String requiredProtocol : requiredProtocols) {
this.protocols.put(requiredProtocol, false); this.protocols.put(requiredProtocol, false);
} }
LOG.info("Broker config " + name + " found. Tracking protocols " + Arrays.asList(requiredProtocols)); LOG.info("Broker config " + name + " found. Tracking protocols " + Arrays.asList(requiredProtocols));
} }
@Override @Override
public ProtocolManagerFactory addingService(ServiceReference<ProtocolManagerFactory<Interceptor>> reference) { public ProtocolManagerFactory addingService(ServiceReference<ProtocolManagerFactory<Interceptor>> reference) {
ProtocolManagerFactory<Interceptor> pmf = context.getService(reference); ProtocolManagerFactory<Interceptor> pmf = context.getService(reference);
callback.addFactory(pmf); callback.addFactory(pmf);
for (String protocol : pmf.getProtocols()) { for (String protocol : pmf.getProtocols()) {
protocolAdded(protocol); protocolAdded(protocol);
} }
return pmf; return pmf;
} }
@Override @Override
public void modifiedService(ServiceReference<ProtocolManagerFactory<Interceptor>> reference, ProtocolManagerFactory<Interceptor> pmf) { public void modifiedService(ServiceReference<ProtocolManagerFactory<Interceptor>> reference, ProtocolManagerFactory<Interceptor> pmf) {
// Not supported // Not supported
} }
@Override @Override
public void removedService(ServiceReference<ProtocolManagerFactory<Interceptor>> reference, ProtocolManagerFactory<Interceptor> pmf) { public void removedService(ServiceReference<ProtocolManagerFactory<Interceptor>> reference, ProtocolManagerFactory<Interceptor> pmf) {
for (String protocol : pmf.getProtocols()) { for (String protocol : pmf.getProtocols()) {
protocolRemoved(protocol); protocolRemoved(protocol);
} }
callback.removeFactory(pmf); callback.removeFactory(pmf);
} }
private void protocolAdded(String protocol) { private void protocolAdded(String protocol) {
Boolean present = this.protocols.get(protocol); Boolean present = this.protocols.get(protocol);
if (present != null && !present) { if (present != null && !present) {
this.protocols.put(protocol, true); this.protocols.put(protocol, true);
List<String> missing = getMissing(); List<String> missing = getMissing();
LOG.info("Required protocol " + protocol + " was added for broker " + name + ". " + LOG.info("Required protocol " + protocol + " was added for broker " + name + ". " +
(missing.isEmpty() ? "Starting broker." : "Still waiting for " + missing)); (missing.isEmpty() ? "Starting broker." : "Still waiting for " + missing));
if (missing.isEmpty()) { if (missing.isEmpty()) {
try { try {
callback.start(); callback.start();
} catch (Exception e) {
LOG.log(Level.WARNING, "Error starting broker " + name, e);
}
} }
} catch (Exception e) {
} LOG.log(Level.WARNING, "Error starting broker " + name, e);
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);
}
} }
this.protocols.put(protocol, false); }
} }
} }
private List<String> getMissing() {
List<String> missing = new ArrayList<String>(); private void protocolRemoved(String protocol) {
for (String protocol : protocols.keySet()) { Boolean present = this.protocols.get(protocol);
Boolean present = protocols.get(protocol); if (present != null && present) {
if (!present) { List<String> missing = getMissing();
missing.add(protocol); LOG.info("Required protocol " + protocol + " was removed for broker " + name + ". "
+ (missing.isEmpty() ? "Stopping broker. " : ""));
if (missing.isEmpty()) {
try {
callback.stop();
} }
} catch (Exception e) {
return missing; 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;
}
} }

View File

@ -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; package org.apache.activemq.artemis.osgi;
import org.apache.activemq.artemis.api.core.Interceptor; 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; import org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory;
public interface ProtocolTrackerCallBack extends ActiveMQComponent { public interface ProtocolTrackerCallBack extends ActiveMQComponent {
void addFactory(ProtocolManagerFactory<Interceptor> pmf); void addFactory(ProtocolManagerFactory<Interceptor> pmf);
void removeFactory(ProtocolManagerFactory<Interceptor> pmf);
void removeFactory(ProtocolManagerFactory<Interceptor> pmf);
} }

View File

@ -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; package org.apache.activemq.artemis.osgi;
import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expect;
@ -13,47 +29,47 @@ import org.osgi.framework.ServiceReference;
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
public class ProtocolTrackerTest { public class ProtocolTrackerTest {
@Test @Test
public void testLifecycle() throws Exception { public void testLifecycle() throws Exception {
IMocksControl c = EasyMock.createControl(); IMocksControl c = EasyMock.createControl();
BundleContext context = c.createMock(BundleContext.class); BundleContext context = c.createMock(BundleContext.class);
String[] requiredProtocols = {"a", "b"}; String[] requiredProtocols = {"a", "b"};
ProtocolTrackerCallBack callback = c.createMock(ProtocolTrackerCallBack.class); ProtocolTrackerCallBack callback = c.createMock(ProtocolTrackerCallBack.class);
RefFact protA = new RefFact(c, context, new String[]{"a"}); RefFact protA = new RefFact(c, context, new String[]{"a"});
RefFact protB = new RefFact(c, context, new String[]{"b"}); RefFact protB = new RefFact(c, context, new String[]{"b"});
callback.addFactory(protA.factory); callback.addFactory(protA.factory);
EasyMock.expectLastCall(); EasyMock.expectLastCall();
callback.addFactory(protB.factory); callback.addFactory(protB.factory);
EasyMock.expectLastCall(); EasyMock.expectLastCall();
callback.start(); callback.start();
EasyMock.expectLastCall(); EasyMock.expectLastCall();
callback.removeFactory(protA.factory); callback.removeFactory(protA.factory);
EasyMock.expectLastCall(); EasyMock.expectLastCall();
callback.stop(); callback.stop();
EasyMock.expectLastCall(); EasyMock.expectLastCall();
c.replay(); c.replay();
ProtocolTracker tracker = new ProtocolTracker("test", context, requiredProtocols, callback); ProtocolTracker tracker = new ProtocolTracker("test", context, requiredProtocols, callback);
tracker.addingService(protA.ref); tracker.addingService(protA.ref);
tracker.addingService(protB.ref); tracker.addingService(protB.ref);
tracker.removedService(protA.ref, protA.factory); tracker.removedService(protA.ref, protA.factory);
c.verify(); c.verify();
} }
class RefFact { class RefFact {
ServiceReference<ProtocolManagerFactory<Interceptor>> ref; ServiceReference<ProtocolManagerFactory<Interceptor>> ref;
ProtocolManagerFactory factory; ProtocolManagerFactory factory;
public RefFact(IMocksControl c, BundleContext context, String[] protocols) { public RefFact(IMocksControl c, BundleContext context, String[] protocols) {
ref = c.createMock(ServiceReference.class); ref = c.createMock(ServiceReference.class);
factory = c.createMock(ProtocolManagerFactory.class); factory = c.createMock(ProtocolManagerFactory.class);
expect(factory.getProtocols()).andReturn(protocols).atLeastOnce(); expect(factory.getProtocols()).andReturn(protocols).atLeastOnce();
expect(context.getService(ref)).andReturn(factory).atLeastOnce(); expect(context.getService(ref)).andReturn(factory).atLeastOnce();
} }
} }
} }