Added composed Activator for MD-SAL to AD-SAL translation 76/1876/8
authorTony Tkacik <ttkacik@cisco.com>
Mon, 14 Oct 2013 12:48:59 +0000 (14:48 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 15 Oct 2013 01:04:42 +0000 (01:04 +0000)
Activator implements both ComponentBase Activator from AD-SAL
and uses Felix DM to retrieve Binding-Aware Broker which
then treats Activator as BindingAwareConsumer.

Change-Id: I24b414d8b9d0846d12cff55d5a3b54fa6b697c05
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
opendaylight/md-sal/sal-compability/pom.xml
opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/ComponentActivator.xtend [new file with mode: 0644]

index 525e7a4..613033a 100644 (file)
@@ -73,6 +73,7 @@
         <configuration>
           <instructions>
             <Bundle-Name>${project.name}</Bundle-Name>
+            <Bundle-Activator>org.opendaylight.controller.sal.compability.ComponentActivator</Bundle-Activator>
             <Private-Package>
               org.eclipse.xtend2.lib,
               org.eclipse.xtend.lib,
diff --git a/opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/ComponentActivator.xtend b/opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/ComponentActivator.xtend
new file mode 100644 (file)
index 0000000..0ef349c
--- /dev/null
@@ -0,0 +1,127 @@
+package org.opendaylight.controller.sal.compability
+
+import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
+import org.opendaylight.controller.sal.core.Node
+import org.opendaylight.controller.sal.core.NodeConnector
+import static org.opendaylight.controller.sal.compability.NodeMapping.*
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey
+import org.apache.felix.dm.Component
+import java.util.Arrays
+import org.opendaylight.yangtools.yang.binding.NotificationListener
+import java.util.Dictionary
+import java.util.Hashtable
+import org.opendaylight.controller.sal.utils.GlobalConstants
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker
+import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService
+import org.opendaylight.controller.sal.inventory.IPluginInInventoryService
+import org.opendaylight.controller.sal.reader.IPluginInReadService
+import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService
+import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService
+import org.opendaylight.controller.sal.binding.api.NotificationService
+import org.opendaylight.controller.sal.binding.api.data.DataBrokerService
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService
+import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService
+import org.osgi.framework.BundleContext
+import org.opendaylight.controller.sal.reader.IPluginOutReadService
+import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService
+
+class ComponentActivator extends ComponentActivatorAbstractBase implements BindingAwareConsumer {
+
+    private BundleContext context;
+
+    @Property
+    FlowProgrammerAdapter flow = new FlowProgrammerAdapter;
+
+    @Property
+    InventoryAndReadAdapter inventory = new InventoryAndReadAdapter;
+
+    @Property
+    DataPacketAdapter dataPacket = new DataPacketAdapter;
+
+    override protected init() {
+        Node.NodeIDType.registerIDType(MD_SAL_TYPE, NodeKey);
+        NodeConnector.NodeConnectorIDType.registerIDType(MD_SAL_TYPE, NodeConnectorKey, MD_SAL_TYPE);
+    }
+
+    override start(BundleContext context) {
+        super.start(context)
+        this.context = context;
+    }
+
+    def setBroker(BindingAwareBroker broker) {
+        broker.registerConsumer(this, context)
+    }
+
+    override onSessionInitialized(ConsumerContext session) {
+        val subscribe = session.getSALService(NotificationService)
+
+        // Registration of Flow Service
+        flow.delegate = session.getRpcService(SalFlowService)
+        subscribe.registerNotificationListener(flow);
+
+        // Data Packet Service
+        subscribe.registerNotificationListener(inventory);
+
+        // Inventory Service
+        inventory.dataService = session.getSALService(DataBrokerService);
+        inventory.flowStatisticsService = session.getRpcService(OpendaylightFlowStatisticsService);
+
+        subscribe.registerNotificationListener(dataPacket)
+
+    }
+
+    override protected getGlobalImplementations() {
+        return Arrays.asList(this, flow, inventory, dataPacket)
+    }
+
+    override protected configureGlobalInstance(Component c, Object imp) {
+        configure(imp, c);
+    }
+
+    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(true))
+    }
+
+    private def dispatch configure(FlowProgrammerAdapter imp, Component it) {
+        setInterface(IPluginInFlowProgrammerService.name, properties)
+        add(
+            createServiceDependency() //
+            .setService(IPluginOutFlowProgrammerService) //
+            .setCallbacks("setFlowProgrammerPublisher", "setFlowProgrammerPublisher") //
+            .setRequired(true))
+    }
+
+    private def dispatch configure(InventoryAndReadAdapter imp, Component it) {
+        setInterface(Arrays.asList(IPluginInInventoryService.name, IPluginInReadService.name), properties)
+        add(
+            createServiceDependency() //
+            .setService(IPluginOutReadService) //
+            .setCallbacks("setReadPublisher", "setReadPublisher") //
+            .setRequired(true))
+        add(
+            createServiceDependency() //
+            .setService(IPluginOutInventoryService) //
+            .setCallbacks("setInventoryPublisher", "setInventoryPublisher") //
+            .setRequired(true))
+    }
+
+    private def Dictionary<String, Object> properties() {
+        val props = new Hashtable<String, Object>();
+        props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString, MD_SAL_TYPE)
+        return props;
+    }
+}