diff --git a/artemis-features/pom.xml b/artemis-features/pom.xml index fc91689d6c..3ff8de790f 100644 --- a/artemis-features/pom.xml +++ b/artemis-features/pom.xml @@ -1,55 +1,78 @@ - - 4.0.0 - - org.apache.activemq - artemis-pom - 1.1.1-SNAPSHOT - - artemis-features - pom - - - - - src/main/resources - true - - - - - org.apache.maven.plugins - maven-resources-plugin - - - filter - generate-resources - - resources - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - attach-artifacts - package - - attach-artifact - - - - - target/classes/features.xml - xml - - - - - - - - + + + 4.0.0 + + org.apache.activemq + artemis-pom + 1.1.1-SNAPSHOT + + artemis-features + pom + + + + + src/main/resources + true + + + + + maven-checkstyle-plugin + + true + + + + org.apache.maven.plugins + maven-resources-plugin + + + filter + generate-resources + + resources + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + attach-artifacts + package + + attach-artifact + + + + + target/classes/features.xml + xml + + + + + + + + \ No newline at end of file diff --git a/artemis-features/src/main/resources/features.xml b/artemis-features/src/main/resources/features.xml index 0a4f05fb25..c7cdd32d77 100644 --- a/artemis-features/src/main/resources/features.xml +++ b/artemis-features/src/main/resources/features.xml @@ -1,3 +1,19 @@ + { private static final String AMQP_PROTOCOL_NAME = "AMQP"; 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 ffbe6e93ff..5bb34b5fd5 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"; 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 5373007d40..55f7c4154e 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 components; - private Map> registrations; - private ServiceTracker tracker; + private String name; + private String configurationUrl; + private Map components; + private Map> registrations; + private ServiceTracker tracker; - @Activate - public void activate(ComponentContext cctx) throws Exception { - final BundleContext context = cctx.getBundleContext(); - final Dictionary 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; - } + @Activate + public void activate(ComponentContext cctx) throws Exception { + final BundleContext context = cctx.getBundleContext(); + final Dictionary 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(); + // 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(); + FileDeploymentManager fileDeploymentManager = new FileDeploymentManager(configurationUrl); + 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()); - ProtocolTrackerCallBack callback = new ProtocolTrackerCallBack() { + String[] requiredProtocols = getRequiredProtocols(server.getConfiguration().getAcceptorConfigurations()); + ProtocolTrackerCallBack callback = new ProtocolTrackerCallBack() { - @Override - public void addFactory(ProtocolManagerFactory pmf) { - server.addProtocolManagerFactory(pmf); + @Override + public void addFactory(ProtocolManagerFactory pmf) { + server.addProtocolManagerFactory(pmf); + } + + + @Override + public void removeFactory(ProtocolManagerFactory 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 removeFactory(ProtocolManagerFactory pmf) { - server.removeProtocolManagerFactory(pmf); + @Override + public void start() throws Exception { + List componentsByStartOrder = getComponentsByStartOrder(components); + for (ActiveMQComponent component : componentsByStartOrder) { + component.start(); } - - @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 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 properties, String key) { - String value = (String) properties.get(key); - if (value == null) { - throw new IllegalStateException("Property " + key + " must be set"); - } - return value; - } + 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 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 acceptors) { - ArrayList protocols = new ArrayList(); - for (TransportConfiguration acceptor : acceptors) { - String protoName = acceptor.getName().toUpperCase(); - if (!"ARTEMIS".equals(protoName)) { - protocols.add(protoName); - } - } - return protocols.toArray(new String[]{}); - } + private String[] getRequiredProtocols(Set acceptors) { + ArrayList protocols = new ArrayList(); + 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(); - } + @Deactivate + public void stop() throws Exception { + tracker.close(); + } - public Map getComponents() { - return components; - } + public Map 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 getComponentsByStartOrder(Map components) { - ArrayList activeMQComponents = new ArrayList(); - ActiveMQComponent jmsComponent = components.get("jms"); - if (jmsComponent != null) { - activeMQComponents.add(jmsComponent); - } - activeMQComponents.add(components.get("core")); - return activeMQComponents; - } + /* + * 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 getComponentsByStartOrder(Map components) { + ArrayList activeMQComponents = new ArrayList(); + ActiveMQComponent jmsComponent = components.get("jms"); + if (jmsComponent != null) { + activeMQComponents.add(jmsComponent); + } + activeMQComponents.add(components.get("core")); + return activeMQComponents; + } - public void register(BundleContext context, Dictionary properties) { - registrations = new HashMap<>(); - for (Map.Entry component : getComponents().entrySet()) { - String[] classes = getInterfaces(component.getValue()); - Hashtable props = new Hashtable<>(); - for (Enumeration 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); - } - } + public void register(BundleContext context, Dictionary properties) { + registrations = new HashMap<>(); + for (Map.Entry component : getComponents().entrySet()) { + String[] classes = getInterfaces(component.getValue()); + Hashtable props = new Hashtable<>(); + for (Enumeration 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 interfaces = new HashSet<>(); - getInterfaces(value.getClass(), interfaces); - return interfaces.toArray(new String[interfaces.size()]); - } + private String[] getInterfaces(ActiveMQComponent value) { + Set interfaces = new HashSet<>(); + getInterfaces(value.getClass(), interfaces); + return interfaces.toArray(new String[interfaces.size()]); + } - private void getInterfaces(Class clazz, Set interfaces) { - for (Class itf : clazz.getInterfaces()) { - if (interfaces.add(itf.getName())) { - getInterfaces(itf, interfaces); - } - } - if (clazz.getSuperclass() != null) { - getInterfaces(clazz.getSuperclass(), interfaces); - } - } + private void getInterfaces(Class clazz, Set 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(); - } - } - } + public void unregister() { + if (registrations != null) { + for (ServiceRegistration reg : registrations.values()) { + reg.unregister(); + } + } + } } 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 44bad5ef85..36430b141e 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> { - private static Logger LOG = Logger.getLogger(ProtocolTracker.class.getName()); - private String name; - private BundleContext context; - private Map protocols; - private ProtocolTrackerCallBack callback; + private static Logger LOG = Logger.getLogger(ProtocolTracker.class.getName()); + private String name; + private BundleContext context; + private Map 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(); - 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(); + 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> reference) { - ProtocolManagerFactory pmf = context.getService(reference); - callback.addFactory(pmf); - for (String protocol : pmf.getProtocols()) { - protocolAdded(protocol); - } + @Override + public ProtocolManagerFactory addingService(ServiceReference> reference) { + ProtocolManagerFactory pmf = context.getService(reference); + callback.addFactory(pmf); + for (String protocol : pmf.getProtocols()) { + protocolAdded(protocol); + } - return pmf; - } + return pmf; + } - @Override - public void modifiedService(ServiceReference> reference, ProtocolManagerFactory pmf) { - // Not supported - } + @Override + public void modifiedService(ServiceReference> reference, ProtocolManagerFactory pmf) { + // Not supported + } - @Override - public void removedService(ServiceReference> reference, ProtocolManagerFactory 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 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> reference, ProtocolManagerFactory 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 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(); } - } - } - - - private void protocolRemoved(String protocol) { - Boolean present = this.protocols.get(protocol); - if (present != null && present) { - List 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); - } + catch (Exception e) { + LOG.log(Level.WARNING, "Error starting broker " + name, e); } - this.protocols.put(protocol, false); - } - } + } + } + } - private List getMissing() { - List missing = new ArrayList(); - 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 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 getMissing() { + List missing = new ArrayList(); + for (String protocol : protocols.keySet()) { + Boolean present = protocols.get(protocol); + if (!present) { + missing.add(protocol); + } + } + return missing; + } } 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 adcdd6a051..9614b5323c 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 pmf); - void removeFactory(ProtocolManagerFactory pmf); + void addFactory(ProtocolManagerFactory pmf); + + void removeFactory(ProtocolManagerFactory pmf); } 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 5fd7d8b094..46435cdd1d 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); + @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"}); + 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(protA.factory); + EasyMock.expectLastCall(); - callback.addFactory(protB.factory); - EasyMock.expectLastCall(); - callback.start(); - EasyMock.expectLastCall(); + callback.addFactory(protB.factory); + EasyMock.expectLastCall(); + callback.start(); + EasyMock.expectLastCall(); - callback.removeFactory(protA.factory); - EasyMock.expectLastCall(); - callback.stop(); - 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(); - } + 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> 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(); - } - } + class RefFact { + ServiceReference> 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(); + } + } }