6cab6b9b4f8b0cf8c774f021e8487fd13365aedc
[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 org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
12 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
13 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
14 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
15 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
16 import org.opendaylight.controller.sal.inventory.IInventoryService;
17 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
18 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
19 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
20 import org.opendaylight.controller.sal.packet.IDataPacketService;
21 import org.opendaylight.controller.sal.packet.IListenDataPacket;
22 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
23 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
24 import org.opendaylight.controller.sal.reader.IPluginInReadService;
25 import org.opendaylight.controller.sal.reader.IReadService;
26 import org.opendaylight.controller.sal.topology.IListenTopoUpdates;
27 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
28 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
29 import org.opendaylight.controller.sal.topology.ITopologyService;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.apache.felix.dm.Component;
33
34 public class Activator extends ComponentActivatorAbstractBase {
35     protected static final Logger logger = LoggerFactory
36             .getLogger(Activator.class);
37
38     /**
39      * Function called when the activator starts just after some initializations
40      * are done by the ComponentActivatorAbstractBase.
41      *
42      */
43     @Override
44     public void init() {
45
46     }
47
48     /**
49      * Function called when the activator stops just before the cleanup done by
50      * ComponentActivatorAbstractBase
51      *
52      */
53     @Override
54     public void destroy() {
55
56     }
57
58     /**
59      * Function that is used to communicate to dependency manager the list of
60      * known implementations for services inside a container
61      *
62      *
63      * @return An array containing all the CLASS objects that will be
64      *         instantiated in order to get an fully working implementation
65      *         Object
66      */
67     @Override
68     public Object[] getImplementations() {
69         Object[] res = { Topology.class, Inventory.class,
70                 FlowProgrammerService.class, ReadService.class,
71                 DataPacketService.class };
72         return res;
73     }
74
75     /**
76      * Function that is called when configuration of the dependencies is
77      * required.
78      *
79      * @param c
80      *            dependency manager Component object, used for configuring the
81      *            dependencies exported and imported
82      * @param imp
83      *            Implementation class that is being configured, needed as long
84      *            as the same routine can configure multiple implementations
85      * @param containerName
86      *            The containerName being configured, this allow also optional
87      *            per-container different behavior if needed, usually should not
88      *            be the case though.
89      */
90     @Override
91     public void configureInstance(Component c, Object imp, String containerName) {
92         if (imp.equals(Topology.class)) {
93             // export the service for Apps and Plugins
94             c.setInterface(
95                     new String[] { IPluginOutTopologyService.class.getName(),
96                             ITopologyService.class.getName() }, null);
97
98             // There can be multiple Topology listeners or there could
99             // be none, hence the dependency is optional
100             c.add(createContainerServiceDependency(containerName)
101                     .setService(IListenTopoUpdates.class)
102                     .setCallbacks("setUpdateService", "unsetUpdateService")
103                     .setRequired(false));
104
105             // There can be multiple southbound plugins or there could
106             // be none, the dependency is optional
107             c.add(createContainerServiceDependency(containerName)
108                     .setService(IPluginInTopologyService.class)
109                     .setCallbacks("setPluginService", "unsetPluginService")
110                     .setRequired(false));
111         }
112
113         if (imp.equals(Inventory.class)) {
114             // export the service
115             c.setInterface(
116                     new String[] { IPluginOutInventoryService.class.getName(),
117                             IInventoryService.class.getName() }, null);
118
119             // Now lets add a service dependency to make sure the
120             // provider of service exists
121             c.add(createContainerServiceDependency(containerName)
122                     .setService(IListenInventoryUpdates.class)
123                     .setCallbacks("setUpdateService", "unsetUpdateService")
124                     .setRequired(false));
125             c.add(createContainerServiceDependency(containerName)
126                     .setService(IPluginInInventoryService.class)
127                     .setCallbacks("setPluginService", "unsetPluginService")
128                     .setRequired(true));
129         }
130
131         if (imp.equals(FlowProgrammerService.class)) {
132             c.setInterface(
133                     new String[] { IFlowProgrammerService.class.getName(),
134                             IPluginOutFlowProgrammerService.class.getName() },
135                     null);
136
137             c.add(createServiceDependency()
138                     .setService(IPluginInFlowProgrammerService.class)
139                     .setCallbacks("setService", "unsetService")
140                     .setRequired(false));
141             c.add(createServiceDependency()
142                     .setService(IFlowProgrammerListener.class)
143                     .setCallbacks("setListener", "unsetListener")
144                     .setRequired(false));
145         }
146
147         if (imp.equals(ReadService.class)) {
148             // It is the provider of IReadService
149             c.setInterface(IReadService.class.getName(), null);
150
151             // It is also the consumer of IPluginInReadService
152             c.add(createContainerServiceDependency(containerName)
153                     .setService(IPluginInReadService.class)
154                     .setCallbacks("setService", "unsetService")
155                     .setRequired(true));
156         }
157
158         /************************/
159         /* DATA PACKET SERVICES */
160         /************************/
161         if (imp.equals(DataPacketService.class)) {
162             c.setInterface(
163                     new String[] { IPluginOutDataPacketService.class.getName(),
164                             IDataPacketService.class.getName() }, null);
165
166             // Optionally use PluginInDataService if any southbound
167             // protocol plugin exists
168             c.add(createContainerServiceDependency(containerName)
169                     .setService(IPluginInDataPacketService.class)
170                     .setCallbacks("setPluginInDataService",
171                             "unsetPluginInDataService").setRequired(false));
172
173             // Optionally listed to IListenDataPacket services
174             c.add(createContainerServiceDependency(containerName)
175                     .setService(IListenDataPacket.class)
176                     .setCallbacks("setListenDataPacket",
177                             "unsetListenDataPacket").setRequired(false));
178         }
179     }
180 }