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