Initial opendaylight infrastructure commit!!
[controller.git] / opendaylight / sal / implementation / src / main / java / org / opendaylight / controller / sal / implementation / internal / Activator.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.sal.implementation.internal;
11
12 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
13 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
14 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
15 import org.opendaylight.controller.sal.inventory.IInventoryService;
16 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
17 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
18 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
19 import org.opendaylight.controller.sal.packet.IDataPacketService;
20 import org.opendaylight.controller.sal.packet.IListenDataPacket;
21 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
22 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
23 import org.opendaylight.controller.sal.reader.IPluginInReadService;
24 import org.opendaylight.controller.sal.reader.IReadService;
25 import org.opendaylight.controller.sal.topology.IListenTopoUpdates;
26 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
27 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
28 import org.opendaylight.controller.sal.topology.ITopologyService;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.apache.felix.dm.Component;
32
33 public class Activator extends ComponentActivatorAbstractBase {
34     protected static final Logger logger = LoggerFactory
35             .getLogger(Activator.class);
36
37     /**
38      * Function called when the activator starts just after some
39      * initializations are done by the
40      * ComponentActivatorAbstractBase.
41      *
42      */
43     public void init() {
44
45     }
46
47     /**
48      * Function called when the activator stops just before the
49      * cleanup done by ComponentActivatorAbstractBase
50      *
51      */
52     public void destroy() {
53
54     }
55
56     /**
57      * Function that is used to communicate to dependency manager the
58      * list of 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
74      * is required.
75      *
76      * @param c dependency manager Component object, used for
77      * configuring the dependencies exported and imported
78      * @param imp Implementation class that is being configured,
79      * needed as long as the same routine can configure multiple
80      * implementations
81      * @param containerName The containerName being configured, this allow
82      * also optional per-container different behavior if needed, usually
83      * should not be the case though.
84      */
85     public void configureInstance(Component c, Object imp, String containerName) {
86         if (imp.equals(Topology.class)) {
87             // export the service for Apps and Plugins
88             c.setInterface(new String[] {
89                     IPluginOutTopologyService.class.getName(),
90                     ITopologyService.class.getName() }, null);
91
92             // There can be multiple Topology listeners or there could
93             // be none, hence the dependency is optional
94             c.add(createContainerServiceDependency(containerName).setService(
95                     IListenTopoUpdates.class).setCallbacks("setUpdateService",
96                     "unsetUpdateService").setRequired(false));
97
98             // There can be multiple southbound plugins or there could
99             // be none, the dependency is optional
100             c.add(createContainerServiceDependency(containerName).setService(
101                     IPluginInTopologyService.class).setCallbacks(
102                     "setPluginService", "unsetPluginService")
103                     .setRequired(false));
104         }
105
106         if (imp.equals(Inventory.class)) {
107             // export the service
108             c.setInterface(new String[] {
109                     IPluginOutInventoryService.class.getName(),
110                     IInventoryService.class.getName() }, null);
111
112             // Now lets add a service dependency to make sure the
113             // provider of service exists
114             c.add(createContainerServiceDependency(containerName).setService(
115                     IListenInventoryUpdates.class).setCallbacks(
116                     "setUpdateService", "unsetUpdateService")
117                     .setRequired(false));
118             c
119                     .add(createContainerServiceDependency(containerName)
120                             .setService(IPluginInInventoryService.class)
121                             .setCallbacks("setPluginService",
122                                     "unsetPluginService").setRequired(true));
123         }
124
125         if (imp.equals(FlowProgrammerService.class)) {
126             // It is the provider of IFlowProgrammerService
127             c.setInterface(IFlowProgrammerService.class.getName(), null);
128             //It is also the consumer of IPluginInFlowProgrammerService
129             c.add(createServiceDependency().setService(
130                     IPluginInFlowProgrammerService.class).setCallbacks(
131                     "setService", "unsetService").setRequired(true));
132         }
133
134         if (imp.equals(ReadService.class)) {
135             // It is the provider of IReadService
136             c.setInterface(IReadService.class.getName(), null);
137
138             //It is also the consumer of IPluginInReadService
139             c.add(createContainerServiceDependency(containerName).setService(
140                     IPluginInReadService.class).setCallbacks("setService",
141                     "unsetService").setRequired(true));
142         }
143
144         /************************/
145         /* DATA PACKET SERVICES */
146         /************************/
147         if (imp.equals(DataPacketService.class)) {
148             c.setInterface(new String[] {
149                     IPluginOutDataPacketService.class.getName(),
150                     IDataPacketService.class.getName() }, null);
151
152             // Optionally use PluginInDataService if any southbound
153             // protocol plugin exists
154             c.add(createContainerServiceDependency(containerName).setService(
155                     IPluginInDataPacketService.class).setCallbacks(
156                     "setPluginInDataService", "unsetPluginInDataService")
157                     .setRequired(false));
158
159             // Optionally listed to IListenDataPacket services
160             c.add(createContainerServiceDependency(containerName).setService(
161                     IListenDataPacket.class).setCallbacks(
162                     "setListenDataPacket", "unsetListenDataPacket")
163                     .setRequired(false));
164         }
165     }
166 }