From a462a9efaffbfe98040ff46740ed071aeb3e511d Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 28 May 2014 10:19:31 +0200 Subject: [PATCH] BUG-625: migrate ComponentActivator This migrates ComponentActivator from xtend to pure Java, simplifying and clarifying it bit. Change-Id: If293cd0c99d931a5a16500b2e72c9afd631ccc02 Signed-off-by: Robert Varga --- .../sal/compatibility/ComponentActivator.java | 238 ++++++++++++++++++ .../compatibility/ComponentActivator.xtend | 194 -------------- 2 files changed, 238 insertions(+), 194 deletions(-) create mode 100644 opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.java delete mode 100644 opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.xtend diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.java new file mode 100644 index 0000000000..b3a89a4ff9 --- /dev/null +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.java @@ -0,0 +1,238 @@ +/** + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.sal.compatibility; + +import java.util.Dictionary; +import java.util.Hashtable; + +import org.apache.felix.dm.Component; +import org.opendaylight.controller.clustering.services.IClusterGlobalServices; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; +import org.opendaylight.controller.sal.compatibility.adsal.DataPacketServiceAdapter; +import org.opendaylight.controller.sal.compatibility.topology.TopologyAdapter; +import org.opendaylight.controller.sal.compatibility.topology.TopologyProvider; +import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; +import org.opendaylight.controller.sal.core.Node.NodeIDType; +import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType; +import org.opendaylight.controller.sal.discovery.IDiscoveryService; +import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService; +import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService; +import org.opendaylight.controller.sal.inventory.IPluginInInventoryService; +import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService; +import org.opendaylight.controller.sal.packet.IPluginInDataPacketService; +import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService; +import org.opendaylight.controller.sal.reader.IPluginInReadService; +import org.opendaylight.controller.sal.reader.IPluginOutReadService; +import org.opendaylight.controller.sal.topology.IPluginInTopologyService; +import org.opendaylight.controller.sal.topology.IPluginOutTopologyService; +import org.opendaylight.controller.sal.utils.GlobalConstants; +import org.opendaylight.controller.sal.utils.INodeConnectorFactory; +import org.opendaylight.controller.sal.utils.INodeFactory; +import org.osgi.framework.BundleContext; + +import com.google.common.base.Preconditions; + +public class ComponentActivator extends ComponentActivatorAbstractBase { + private final INodeConnectorFactory nodeConnectorFactory = new MDSalNodeConnectorFactory(); + private final DataPacketServiceAdapter dataPacketService = new DataPacketServiceAdapter(); + private final InventoryAndReadAdapter inventory = new InventoryAndReadAdapter(); + private final FlowProgrammerAdapter flow = new FlowProgrammerAdapter(); + private final DataPacketAdapter dataPacket = new DataPacketAdapter(); + private final TopologyProvider tpProvider = new TopologyProvider(); + private final INodeFactory nodeFactory = new MDSalNodeFactory(); + private final TopologyAdapter topology = new TopologyAdapter(); + private BundleContext context; + + public INodeConnectorFactory getNodeConnectorFactory() { + return nodeConnectorFactory; + } + + public DataPacketServiceAdapter getDataPacketService() { + return dataPacketService; + } + + public InventoryAndReadAdapter getInventory() { + return inventory; + } + + public FlowProgrammerAdapter getFlow() { + return flow; + } + + public DataPacketAdapter getDataPacket() { + return dataPacket; + } + + public TopologyProvider getTpProvider() { + return tpProvider; + } + + public INodeFactory getNodeFactory() { + return nodeFactory; + } + + public TopologyAdapter getTopology() { + return topology; + } + + @Override + protected void init() { + NodeIDType.registerIDType(NodeMapping.MD_SAL_TYPE, String.class); + NodeConnectorIDType.registerIDType(NodeMapping.MD_SAL_TYPE, String.class, NodeMapping.MD_SAL_TYPE); + } + + @Override + public void start(final BundleContext context) { + super.start(context); + this.context = Preconditions.checkNotNull(context); + } + + public ProviderContext setBroker(final BindingAwareBroker broker) { + return broker.registerProvider(new SalCompatibilityProvider(this), context); + } + + @Override + protected Object[] getGlobalImplementations() { + return new Object[] { + flow, + inventory, + dataPacket, + nodeFactory, + nodeConnectorFactory, + topology, + tpProvider, + }; + } + + @Override + protected void configureGlobalInstance(final Component c, final Object imp) { + if (imp instanceof DataPacketAdapter) { + _configure((DataPacketAdapter)imp, c); + } else if (imp instanceof FlowProgrammerAdapter) { + _configure((FlowProgrammerAdapter)imp, c); + } else if (imp instanceof InventoryAndReadAdapter) { + _configure((InventoryAndReadAdapter)imp, c); + } else if (imp instanceof ComponentActivator) { + _configure((ComponentActivator)imp, c); + } else if (imp instanceof MDSalNodeConnectorFactory) { + _configure((MDSalNodeConnectorFactory)imp, c); + } else if (imp instanceof MDSalNodeFactory) { + _configure((MDSalNodeFactory)imp, c); + } else if (imp instanceof TopologyAdapter) { + _configure((TopologyAdapter)imp, c); + } else if (imp instanceof TopologyProvider) { + _configure((TopologyProvider)imp, c); + } else { + throw new IllegalArgumentException(String.format("Unhandled implementation class %s", imp.getClass())); + } + } + + @Override + protected Object[] getImplementations() { + return new Object[] { + dataPacketService, + }; + } + + @Override + protected void configureInstance(final Component c, final Object imp, final String containerName) { + if (imp instanceof ComponentActivator) { + _instanceConfigure((ComponentActivator)imp, c, containerName); + } else if (imp instanceof DataPacketServiceAdapter) { + _instanceConfigure((DataPacketServiceAdapter)imp, c, containerName); + } else { + throw new IllegalArgumentException(String.format("Unhandled implementation class %s", imp.getClass())); + } + } + + private void _configure(final MDSalNodeFactory imp, final Component it) { + it.setInterface(INodeFactory.class.getName(), properties()); + } + + private void _configure(final MDSalNodeConnectorFactory imp, final Component it) { + it.setInterface(INodeConnectorFactory.class.getName(), properties()); + } + + private void _configure(final ComponentActivator imp, final Component it) { + it.add(createServiceDependency() + .setService(BindingAwareBroker.class) + .setCallbacks("setBroker", "setBroker") + .setRequired(true)); + } + + private void _configure(final DataPacketAdapter imp, final Component it) { + it.add(createServiceDependency() + .setService(IPluginOutDataPacketService.class) + .setCallbacks("setDataPacketPublisher", "setDataPacketPublisher") + .setRequired(false)); + } + + private void _configure(final FlowProgrammerAdapter imp, final Component it) { + it.setInterface(IPluginInFlowProgrammerService.class.getName(), properties()); + it.add(createServiceDependency() + .setService(IPluginOutFlowProgrammerService.class) + .setCallbacks("setFlowProgrammerPublisher", "setFlowProgrammerPublisher") + .setRequired(false)); + it.add(createServiceDependency() + .setService(IClusterGlobalServices.class) + .setCallbacks("setClusterGlobalServices", "unsetClusterGlobalServices") + .setRequired(false)); + } + + private void _instanceConfigure(final DataPacketServiceAdapter imp, final Component it, final String containerName) { + it.setInterface(IPluginInDataPacketService.class.getName(), properties()); + } + + private void _instanceConfigure(final ComponentActivator imp, final Component it, final String containerName) { + // No-op + } + + private void _configure(final InventoryAndReadAdapter imp, final Component it) { + it.setInterface(new String[] { + IPluginInInventoryService.class.getName(), + IPluginInReadService.class.getName(), + }, properties()); + + it.add(createServiceDependency() + .setService(IPluginOutReadService.class) + .setCallbacks("setReadPublisher", "unsetReadPublisher") + .setRequired(false)); + it.add(createServiceDependency() + .setService(IPluginOutInventoryService.class) + .setCallbacks("setInventoryPublisher", "unsetInventoryPublisher") + .setRequired(false)); + it.add(createServiceDependency() + .setService(IDiscoveryService.class) + .setCallbacks("setDiscoveryPublisher", "setDiscoveryPublisher") + .setRequired(false)); + } + + private void _configure(final TopologyAdapter imp, final Component it) { + it.setInterface(IPluginInTopologyService.class.getName(), properties()); + + it.add(createServiceDependency() + .setService(IPluginOutTopologyService.class) + .setCallbacks("setTopologyPublisher", "setTopologyPublisher") + .setRequired(false)); + } + + private void _configure(final TopologyProvider imp, final Component it) { + it.add(createServiceDependency() + .setService(IPluginOutTopologyService.class) + .setCallbacks("setTopologyPublisher", "setTopologyPublisher") + .setRequired(false)); + } + + private Dictionary properties() { + final Hashtable props = new Hashtable(); + props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), NodeMapping.MD_SAL_TYPE); + props.put("protocolName", NodeMapping.MD_SAL_TYPE); + return props; + } +} diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.xtend b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.xtend deleted file mode 100644 index d65dee6571..0000000000 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.xtend +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.compatibility - -import java.util.Arrays -import java.util.Dictionary -import java.util.Hashtable -import org.apache.felix.dm.Component -import org.opendaylight.controller.clustering.services.IClusterGlobalServices -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker -import org.opendaylight.controller.sal.compatibility.adsal.DataPacketServiceAdapter -import org.opendaylight.controller.sal.compatibility.topology.TopologyAdapter -import org.opendaylight.controller.sal.compatibility.topology.TopologyProvider -import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase -import org.opendaylight.controller.sal.core.Node -import org.opendaylight.controller.sal.core.NodeConnector -import org.opendaylight.controller.sal.discovery.IDiscoveryService -import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService -import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService -import org.opendaylight.controller.sal.inventory.IPluginInInventoryService -import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService -import org.opendaylight.controller.sal.packet.IPluginInDataPacketService -import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService -import org.opendaylight.controller.sal.reader.IPluginInReadService -import org.opendaylight.controller.sal.reader.IPluginOutReadService -import org.opendaylight.controller.sal.topology.IPluginInTopologyService -import org.opendaylight.controller.sal.topology.IPluginOutTopologyService -import org.opendaylight.controller.sal.utils.GlobalConstants -import org.opendaylight.controller.sal.utils.INodeConnectorFactory -import org.opendaylight.controller.sal.utils.INodeFactory -import org.osgi.framework.BundleContext - -import static org.opendaylight.controller.sal.compatibility.NodeMapping.* - -class ComponentActivator extends ComponentActivatorAbstractBase { - - private BundleContext context; - - @Property - FlowProgrammerAdapter flow = new FlowProgrammerAdapter; - - @Property - InventoryAndReadAdapter inventory = new InventoryAndReadAdapter; - - @Property - DataPacketAdapter dataPacket = new DataPacketAdapter; - - @Property - INodeFactory nodeFactory = new MDSalNodeFactory - - @Property - INodeConnectorFactory nodeConnectorFactory = new MDSalNodeConnectorFactory - - @Property - TopologyAdapter topology = new TopologyAdapter - - @Property - TopologyProvider tpProvider = new TopologyProvider() - - @Property - DataPacketServiceAdapter dataPacketService = new DataPacketServiceAdapter() - - - - override protected init() { - Node.NodeIDType.registerIDType(MD_SAL_TYPE, String); - NodeConnector.NodeConnectorIDType.registerIDType(MD_SAL_TYPE, String, MD_SAL_TYPE); - } - - override start(BundleContext context) { - super.start(context) - this.context = context; - } - - def setBroker(BindingAwareBroker broker) { - broker.registerProvider(new SalCompatibilityProvider(this), context) - } - - - override protected getGlobalImplementations() { - return Arrays.asList(this, flow, inventory, dataPacket, nodeFactory, nodeConnectorFactory,topology,tpProvider) - } - - override protected configureGlobalInstance(Component c, Object imp) { - configure(imp, c); - } - - override protected getImplementations() { - return Arrays.asList(dataPacketService) - } - - override protected configureInstance(Component c, Object imp, String containerName) { - instanceConfigure(imp, c, containerName); - } - - private def dispatch configure(MDSalNodeFactory imp, Component it) { - setInterface(INodeFactory.name, properties); - } - - private def dispatch configure(MDSalNodeConnectorFactory imp, Component it) { - setInterface(INodeConnectorFactory.name, properties); - } - - private def dispatch configure(ComponentActivator imp, Component it) { - add( - createServiceDependency().setService(BindingAwareBroker) // - .setCallbacks("setBroker", "setBroker") // - .setRequired(true)) - - - } - - private def dispatch configure(DataPacketAdapter imp, Component it) { - add( - createServiceDependency() // - .setService(IPluginOutDataPacketService) // - .setCallbacks("setDataPacketPublisher", "setDataPacketPublisher") // - .setRequired(false)) - } - - private def dispatch configure(FlowProgrammerAdapter imp, Component it) { - setInterface(IPluginInFlowProgrammerService.name, properties) - add( - createServiceDependency() // - .setService(IPluginOutFlowProgrammerService) // - .setCallbacks("setFlowProgrammerPublisher", "setFlowProgrammerPublisher") // - .setRequired(false)) - - add( - createServiceDependency() // - .setService(IClusterGlobalServices) // - .setCallbacks("setClusterGlobalServices", "unsetClusterGlobalServices") // - .setRequired(false)) - - } - - private def dispatch instanceConfigure(DataPacketServiceAdapter imp, Component it, String containerName) { - setInterface(IPluginInDataPacketService.name, properties) - } - - private def dispatch instanceConfigure(ComponentActivator imp, Component it, String containerName) { - } - - - private def dispatch configure(InventoryAndReadAdapter imp, Component it) { - setInterface(Arrays.asList(IPluginInInventoryService.name, IPluginInReadService.name), properties) - add( - createServiceDependency() // - .setService(IPluginOutReadService) // - .setCallbacks("setReadPublisher", "unsetReadPublisher") // - .setRequired(false)) - add( - createServiceDependency() // - .setService(IPluginOutInventoryService) // - .setCallbacks("setInventoryPublisher", "unsetInventoryPublisher") // - .setRequired(false)) - add( - createServiceDependency() // - .setService(IDiscoveryService) // - .setCallbacks("setDiscoveryPublisher", "setDiscoveryPublisher") // - .setRequired(false)) - - - } - - private def dispatch configure (TopologyAdapter imp, Component it) { - setInterface(Arrays.asList(IPluginInTopologyService.name), properties) - add( - createServiceDependency() // - .setService(IPluginOutTopologyService) // - .setCallbacks("setTopologyPublisher", "setTopologyPublisher") // - .setRequired(false)) - } - - private def dispatch configure (TopologyProvider imp, Component it) { - add( - createServiceDependency() // - .setService(IPluginOutTopologyService) // - .setCallbacks("setTopologyPublisher", "setTopologyPublisher") // - .setRequired(false)) - } - - private def Dictionary properties() { - val props = new Hashtable(); - props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString, MD_SAL_TYPE) - props.put("protocolName", MD_SAL_TYPE); - return props; - } -} -- 2.36.6