Move init and destroy empty impl from Activator classes. Have only one
[controller.git] / opendaylight / sal / implementation / src / main / java / org / opendaylight / controller / sal / implementation / internal / Activator.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.sal.implementation.internal;
10
11 import java.util.Dictionary;
12 import java.util.Hashtable;
13
14 import org.apache.felix.dm.Component;
15 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
16 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
17 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
18 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
19 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
20 import org.opendaylight.controller.sal.inventory.IInventoryService;
21 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
22 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
23 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
24 import org.opendaylight.controller.sal.packet.IDataPacketService;
25 import org.opendaylight.controller.sal.packet.IListenDataPacket;
26 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
27 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
28 import org.opendaylight.controller.sal.reader.IPluginInReadService;
29 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
30 import org.opendaylight.controller.sal.reader.IReadService;
31 import org.opendaylight.controller.sal.reader.IReadServiceListener;
32 import org.opendaylight.controller.sal.topology.IListenTopoUpdates;
33 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
34 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
35 import org.opendaylight.controller.sal.topology.ITopologyService;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 public class Activator extends ComponentActivatorAbstractBase {
40     protected static final Logger logger = LoggerFactory
41             .getLogger(Activator.class);
42
43
44     /**
45      * Function that is used to communicate to dependency manager the list of
46      * known Global implementations
47      *
48      *
49      * @return An array containing all the CLASS objects that will be
50      *         instantiated in order to get an fully working implementation
51      *         Object
52      */
53     public Object[] getGlobalImplementations() {
54         Object[] res = { Inventory.class };
55         return res;
56     }
57
58     /**
59      * Function that is called when configuration of the dependencies is required.
60      *
61      * @param c
62      *            dependency manager Component object, used for configuring the
63      *            dependencies exported and imported
64      * @param imp
65      *            Implementation class that is being configured, needed as long
66      *            as the same routine can configure multiple implementations
67      */
68     public void configureGlobalInstance(Component c, Object imp) {
69         if (imp.equals(Inventory.class)) {
70             Dictionary<String, Object> props = new Hashtable<String, Object>();
71             props.put("scope", "Global");
72             // export the service
73             c.setInterface(
74                     new String[] { IPluginOutInventoryService.class.getName(),
75                             IInventoryService.class.getName() }, props);
76
77             // Now lets add a service dependency to make sure the
78             // provider of service exists
79             c.add(createServiceDependency()
80                     .setService(IListenInventoryUpdates.class, "(scope=Global)")
81                     .setCallbacks("setUpdateService", "unsetUpdateService")
82                     .setRequired(false));
83             c.add(createServiceDependency()
84                     .setService(IPluginInInventoryService.class, "(scope=Global)")
85                     .setCallbacks("setPluginService", "unsetPluginService")
86                     .setRequired(false));
87         }
88     }
89
90     /**
91      * Function that is used to communicate to dependency manager the list of
92      * known implementations for services inside a container
93      *
94      *
95      * @return An array containing all the CLASS objects that will be
96      *         instantiated in order to get an fully working implementation
97      *         Object
98      */
99     @Override
100     public Object[] getImplementations() {
101         Object[] res = { Topology.class, Inventory.class,
102                 FlowProgrammerService.class, ReadService.class,
103                 DataPacketService.class };
104         return res;
105     }
106
107     /**
108      * Function that is called when configuration of the dependencies is
109      * required.
110      *
111      * @param c
112      *            dependency manager Component object, used for configuring the
113      *            dependencies exported and imported
114      * @param imp
115      *            Implementation class that is being configured, needed as long
116      *            as the same routine can configure multiple implementations
117      * @param containerName
118      *            The containerName being configured, this allow also optional
119      *            per-container different behavior if needed, usually should not
120      *            be the case though.
121      */
122     @Override
123     public void configureInstance(Component c, Object imp, String containerName) {
124         if (imp.equals(Topology.class)) {
125             // export the service for Apps and Plugins
126             c.setInterface(
127                     new String[] { IPluginOutTopologyService.class.getName(),
128                             ITopologyService.class.getName() }, null);
129
130             // There can be multiple Topology listeners or there could
131             // be none, hence the dependency is optional
132             c.add(createContainerServiceDependency(containerName)
133                     .setService(IListenTopoUpdates.class)
134                     .setCallbacks("setUpdateService", "unsetUpdateService")
135                     .setRequired(false));
136
137             // There can be multiple southbound plugins or there could
138             // be none, the dependency is optional
139             c.add(createContainerServiceDependency(containerName)
140                     .setService(IPluginInTopologyService.class)
141                     .setCallbacks("setPluginService", "unsetPluginService")
142                     .setRequired(false));
143         }
144
145         if (imp.equals(Inventory.class)) {
146             // export the service
147             c.setInterface(
148                     new String[] { IPluginOutInventoryService.class.getName(),
149                             IInventoryService.class.getName() }, null);
150
151             // Now lets add a service dependency to make sure the
152             // provider of service exists
153             c.add(createContainerServiceDependency(containerName)
154                     .setService(IListenInventoryUpdates.class)
155                     .setCallbacks("setUpdateService", "unsetUpdateService")
156                     .setRequired(false));
157             c.add(createContainerServiceDependency(containerName)
158                     .setService(IPluginInInventoryService.class)
159                     .setCallbacks("setPluginService", "unsetPluginService")
160                     .setRequired(false));
161         }
162
163         if (imp.equals(FlowProgrammerService.class)) {
164             c.setInterface(
165                     new String[] { IFlowProgrammerService.class.getName(),
166                             IPluginOutFlowProgrammerService.class.getName() },
167                     null);
168
169             c.add(createServiceDependency()
170                     .setService(IPluginInFlowProgrammerService.class)
171                     .setCallbacks("setService", "unsetService")
172                     .setRequired(false));
173             c.add(createContainerServiceDependency(containerName)
174                     .setService(IFlowProgrammerListener.class)
175                     .setCallbacks("setListener", "unsetListener")
176                     .setRequired(false));
177         }
178
179         if (imp.equals(ReadService.class)) {
180             // export services
181             c.setInterface(new String[] {
182                     IReadService.class.getName(),IPluginOutReadService.class.getName()}, null);
183
184             // It is also the consumer of IPluginInReadService
185             c.add(createContainerServiceDependency(containerName)
186                     .setService(IPluginInReadService.class)
187                     .setCallbacks("setService", "unsetService")
188                     .setRequired(false));
189
190             //consumes plugins' reader updates
191             c.add(createContainerServiceDependency(containerName)
192                     .setService(IReadServiceListener.class)
193                     .setCallbacks("setReaderListener", "unsetReaderListener")
194                     .setRequired(false));
195
196         }
197
198         /************************/
199         /* DATA PACKET SERVICES */
200         /************************/
201         if (imp.equals(DataPacketService.class)) {
202             c.setInterface(
203                     new String[] { IPluginOutDataPacketService.class.getName(),
204                             IDataPacketService.class.getName() }, null);
205
206             // Optionally use PluginInDataService if any southbound
207             // protocol plugin exists
208             c.add(createContainerServiceDependency(containerName)
209                     .setService(IPluginInDataPacketService.class)
210                     .setCallbacks("setPluginInDataService",
211                             "unsetPluginInDataService").setRequired(false));
212
213             // Optionally listed to IListenDataPacket services
214             c.add(createContainerServiceDependency(containerName)
215                     .setService(IListenDataPacket.class)
216                     .setCallbacks("setListenDataPacket",
217                             "unsetListenDataPacket").setRequired(false));
218         }
219     }
220 }