2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.sal.implementation.internal;
11 import java.util.Dictionary;
12 import java.util.Hashtable;
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;
39 public class Activator extends ComponentActivatorAbstractBase {
40 protected static final Logger logger = LoggerFactory
41 .getLogger(Activator.class);
44 * Function called when the activator starts just after some initializations
45 * are done by the ComponentActivatorAbstractBase.
54 * Function called when the activator stops just before the cleanup done by
55 * ComponentActivatorAbstractBase
59 public void destroy() {
64 * Function that is used to communicate to dependency manager the list of
65 * known Global implementations
68 * @return An array containing all the CLASS objects that will be
69 * instantiated in order to get an fully working implementation
72 public Object[] getGlobalImplementations() {
73 Object[] res = { Inventory.class };
78 * Function that is called when configuration of the dependencies is required.
81 * dependency manager Component object, used for configuring the
82 * dependencies exported and imported
84 * Implementation class that is being configured, needed as long
85 * as the same routine can configure multiple implementations
87 public void configureGlobalInstance(Component c, Object imp) {
88 if (imp.equals(Inventory.class)) {
89 Dictionary<String, Object> props = new Hashtable<String, Object>();
90 props.put("scope", "Global");
93 new String[] { IPluginOutInventoryService.class.getName(),
94 IInventoryService.class.getName() }, props);
96 // Now lets add a service dependency to make sure the
97 // provider of service exists
98 c.add(createServiceDependency()
99 .setService(IListenInventoryUpdates.class, "(scope=Global)")
100 .setCallbacks("setUpdateService", "unsetUpdateService")
101 .setRequired(false));
102 c.add(createServiceDependency()
103 .setService(IPluginInInventoryService.class, "(scope=Global)")
104 .setCallbacks("setPluginService", "unsetPluginService")
105 .setRequired(false));
110 * Function that is used to communicate to dependency manager the list of
111 * known implementations for services inside a container
114 * @return An array containing all the CLASS objects that will be
115 * instantiated in order to get an fully working implementation
119 public Object[] getImplementations() {
120 Object[] res = { Topology.class, Inventory.class,
121 FlowProgrammerService.class, ReadService.class,
122 DataPacketService.class };
127 * Function that is called when configuration of the dependencies is
131 * dependency manager Component object, used for configuring the
132 * dependencies exported and imported
134 * Implementation class that is being configured, needed as long
135 * as the same routine can configure multiple implementations
136 * @param containerName
137 * The containerName being configured, this allow also optional
138 * per-container different behavior if needed, usually should not
139 * be the case though.
142 public void configureInstance(Component c, Object imp, String containerName) {
143 if (imp.equals(Topology.class)) {
144 // export the service for Apps and Plugins
146 new String[] { IPluginOutTopologyService.class.getName(),
147 ITopologyService.class.getName() }, null);
149 // There can be multiple Topology listeners or there could
150 // be none, hence the dependency is optional
151 c.add(createContainerServiceDependency(containerName)
152 .setService(IListenTopoUpdates.class)
153 .setCallbacks("setUpdateService", "unsetUpdateService")
154 .setRequired(false));
156 // There can be multiple southbound plugins or there could
157 // be none, the dependency is optional
158 c.add(createContainerServiceDependency(containerName)
159 .setService(IPluginInTopologyService.class)
160 .setCallbacks("setPluginService", "unsetPluginService")
161 .setRequired(false));
164 if (imp.equals(Inventory.class)) {
165 // export the service
167 new String[] { IPluginOutInventoryService.class.getName(),
168 IInventoryService.class.getName() }, null);
170 // Now lets add a service dependency to make sure the
171 // provider of service exists
172 c.add(createContainerServiceDependency(containerName)
173 .setService(IListenInventoryUpdates.class)
174 .setCallbacks("setUpdateService", "unsetUpdateService")
175 .setRequired(false));
176 c.add(createContainerServiceDependency(containerName)
177 .setService(IPluginInInventoryService.class)
178 .setCallbacks("setPluginService", "unsetPluginService")
179 .setRequired(false));
182 if (imp.equals(FlowProgrammerService.class)) {
184 new String[] { IFlowProgrammerService.class.getName(),
185 IPluginOutFlowProgrammerService.class.getName() },
188 c.add(createServiceDependency()
189 .setService(IPluginInFlowProgrammerService.class)
190 .setCallbacks("setService", "unsetService")
191 .setRequired(false));
192 c.add(createContainerServiceDependency(containerName)
193 .setService(IFlowProgrammerListener.class)
194 .setCallbacks("setListener", "unsetListener")
195 .setRequired(false));
198 if (imp.equals(ReadService.class)) {
200 c.setInterface(new String[] {
201 IReadService.class.getName(),IPluginOutReadService.class.getName()}, null);
203 // It is also the consumer of IPluginInReadService
204 c.add(createContainerServiceDependency(containerName)
205 .setService(IPluginInReadService.class)
206 .setCallbacks("setService", "unsetService")
207 .setRequired(false));
209 //consumes plugins' reader updates
210 c.add(createContainerServiceDependency(containerName)
211 .setService(IReadServiceListener.class)
212 .setCallbacks("setReaderListener", "unsetReaderListener")
213 .setRequired(false));
217 /************************/
218 /* DATA PACKET SERVICES */
219 /************************/
220 if (imp.equals(DataPacketService.class)) {
222 new String[] { IPluginOutDataPacketService.class.getName(),
223 IDataPacketService.class.getName() }, null);
225 // Optionally use PluginInDataService if any southbound
226 // protocol plugin exists
227 c.add(createContainerServiceDependency(containerName)
228 .setService(IPluginInDataPacketService.class)
229 .setCallbacks("setPluginInDataService",
230 "unsetPluginInDataService").setRequired(false));
232 // Optionally listed to IListenDataPacket services
233 c.add(createContainerServiceDependency(containerName)
234 .setService(IListenDataPacket.class)
235 .setCallbacks("setListenDataPacket",
236 "unsetListenDataPacket").setRequired(false));