Add test for generated code checking list of dependencies.
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / main / java / org / opendaylight / controller / sal / compatibility / ComponentActivator.xtend
1 package org.opendaylight.controller.sal.compatibility
2
3 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase
4 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
5 import org.opendaylight.controller.sal.core.Node
6 import org.opendaylight.controller.sal.core.NodeConnector
7 import static org.opendaylight.controller.sal.compatibility.NodeMapping.*
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey
9 import org.apache.felix.dm.Component
10 import java.util.Arrays
11 import org.opendaylight.yangtools.yang.binding.NotificationListener
12 import java.util.Dictionary
13 import java.util.Hashtable
14 import org.opendaylight.controller.sal.utils.GlobalConstants
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker
16 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService
17 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService
18 import org.opendaylight.controller.sal.reader.IPluginInReadService
19 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService
20 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer
21 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService
23 import org.opendaylight.controller.sal.binding.api.NotificationService
24 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService
26 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService
27 import org.osgi.framework.BundleContext
28 import org.opendaylight.controller.sal.reader.IPluginOutReadService
29 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService
30 import org.opendaylight.controller.sal.discovery.IDiscoveryService
31 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryService
33
34 class ComponentActivator extends ComponentActivatorAbstractBase implements BindingAwareConsumer {
35
36     private BundleContext context;
37
38     @Property
39     FlowProgrammerAdapter flow = new FlowProgrammerAdapter;
40
41     @Property
42     InventoryAndReadAdapter inventory = new InventoryAndReadAdapter;
43
44     @Property
45     DataPacketAdapter dataPacket = new DataPacketAdapter;
46
47     override protected init() {
48         Node.NodeIDType.registerIDType(MD_SAL_TYPE, NodeKey);
49         NodeConnector.NodeConnectorIDType.registerIDType(MD_SAL_TYPE, NodeConnectorKey, MD_SAL_TYPE);
50     }
51
52     override start(BundleContext context) {
53         super.start(context)
54         this.context = context;
55     }
56
57     def setBroker(BindingAwareBroker broker) {
58         broker.registerConsumer(this, context)
59     }
60
61     override onSessionInitialized(ConsumerContext session) {
62         val subscribe = session.getSALService(NotificationService)
63
64         // Registration of Flow Service
65         flow.delegate = session.getRpcService(SalFlowService)
66         subscribe.registerNotificationListener(flow);
67
68         // Data Packet Service
69         subscribe.registerNotificationListener(inventory);
70
71         // Inventory Service
72         inventory.dataService = session.getSALService(DataBrokerService);
73         inventory.flowStatisticsService = session.getRpcService(OpendaylightFlowStatisticsService);
74         inventory.topologyDiscovery = session.getRpcService(FlowTopologyDiscoveryService);
75
76         subscribe.registerNotificationListener(dataPacket)
77
78     }
79
80     override protected getGlobalImplementations() {
81         return Arrays.asList(this, flow, inventory, dataPacket)
82     }
83
84     override protected configureGlobalInstance(Component c, Object imp) {
85         configure(imp, c);
86     }
87
88     private def dispatch configure(ComponentActivator imp, Component it) {
89         add(
90             createServiceDependency().setService(BindingAwareBroker) //
91             .setCallbacks("setBroker", "setBroker") //
92             .setRequired(true))
93     }
94
95     private def dispatch configure(DataPacketAdapter imp, Component it) {
96         add(
97             createServiceDependency() //
98             .setService(IPluginOutDataPacketService) //
99             .setCallbacks("setDataPacketPublisher", "setDataPacketPublisher") //
100             .setRequired(false))
101     }
102
103     private def dispatch configure(FlowProgrammerAdapter imp, Component it) {
104         setInterface(IPluginInFlowProgrammerService.name, properties)
105         add(
106             createServiceDependency() //
107             .setService(IPluginOutFlowProgrammerService) //
108             .setCallbacks("setFlowProgrammerPublisher", "setFlowProgrammerPublisher") //
109             .setRequired(false))
110     }
111
112     private def dispatch configure(InventoryAndReadAdapter imp, Component it) {
113         setInterface(Arrays.asList(IPluginInInventoryService.name, IPluginInReadService.name), properties)
114         add(
115             createServiceDependency() //
116             .setService(IPluginOutReadService) //
117             .setCallbacks("setReadPublisher", "setReadPublisher") //
118             .setRequired(false))
119         add(
120             createServiceDependency() //
121             .setService(IPluginOutInventoryService) //
122             .setCallbacks("setInventoryPublisher", "setInventoryPublisher") //
123             .setRequired(false))
124         add(
125             createServiceDependency() //
126             .setService(IPluginOutTopologyService) //
127             .setCallbacks("setTopologyPublisher", "setTopologyPublisher") //
128             .setRequired(false))
129         add(
130             createServiceDependency() //
131             .setService(IDiscoveryService) //
132             .setCallbacks("setDiscoveryPublisher", "setDiscoveryPublisher") //
133             .setRequired(false))
134         
135     }
136
137     private def Dictionary<String, Object> properties() {
138         val props = new Hashtable<String, Object>();
139         props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString, MD_SAL_TYPE)
140         return props;
141     }
142 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.