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