f55fc8e5ee9d574be44cbf907d9e075b50a6f4dd
[controller.git] / opendaylight / switchmanager / implementation / src / main / java / org / opendaylight / controller / switchmanager / 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.switchmanager.internal;
11
12 import org.apache.felix.dm.Component;
13 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
14 import org.opendaylight.controller.configuration.IConfigurationContainerAware;
15 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
16 import org.opendaylight.controller.sal.inventory.IInventoryService;
17 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
18 import org.opendaylight.controller.statisticsmanager.IStatisticsManager;
19 import org.opendaylight.controller.switchmanager.IInventoryListener;
20 import org.opendaylight.controller.switchmanager.ISpanAware;
21 import org.opendaylight.controller.switchmanager.ISwitchManager;
22 import org.opendaylight.controller.switchmanager.ISwitchManagerAware;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * SwitchManager Bundle Activator
28  *
29  *
30  */
31 public class Activator extends ComponentActivatorAbstractBase {
32     protected static final Logger logger = LoggerFactory
33             .getLogger(Activator.class);
34
35
36     /**
37      * Function that is used to communicate to dependency manager the
38      * list of known implementations for services inside a container
39      *
40      *
41      * @return An array containing all the CLASS objects that will be
42      * instantiated in order to get an fully working implementation
43      * Object
44      */
45     @Override
46     public Object[] getImplementations() {
47         Object[] res = { SwitchManager.class };
48         return res;
49     }
50
51     /**
52      * Function that is called when configuration of the dependencies
53      * is required.
54      *
55      * @param c dependency manager Component object, used for
56      * configuring the dependencies exported and imported
57      * @param imp Implementation class that is being configured,
58      * needed as long as the same routine can configure multiple
59      * implementations
60      * @param containerName The containerName being configured, this allow
61      * also optional per-container different behavior if needed, usually
62      * should not be the case though.
63      */
64     @Override
65     public void configureInstance(Component c, Object imp, String containerName) {
66         if (imp.equals(SwitchManager.class)) {
67             // export the service
68             c.setInterface(new String[] {
69                     IListenInventoryUpdates.class.getName(),
70                     ISwitchManager.class.getName(),
71                     IConfigurationContainerAware.class.getName() }, null);
72
73             // Now lets add a service dependency to make sure the
74             // provider of service exists
75             c.add(createContainerServiceDependency(containerName).setService(
76                     IInventoryService.class).setCallbacks(
77                     "setInventoryService", "unsetInventoryService")
78                     .setRequired(false));
79             c.add(createContainerServiceDependency(containerName).setService(
80                     IStatisticsManager.class).setCallbacks(
81                     "setStatisticsManager", "unsetStatisticsManager")
82                     .setRequired(false));
83             c.add(createContainerServiceDependency(containerName).setService(
84                     ISwitchManagerAware.class).setCallbacks(
85                     "setSwitchManagerAware", "unsetSwitchManagerAware")
86                     .setRequired(false));
87             c.add(createContainerServiceDependency(containerName).setService(
88                     IInventoryListener.class).setCallbacks(
89                     "setInventoryListener", "unsetInventoryListener")
90                     .setRequired(false));
91             c.add(createContainerServiceDependency(containerName).setService(
92                     ISpanAware.class).setCallbacks("setSpanAware",
93                     "unsetSpanAware").setRequired(false));
94             c.add(createContainerServiceDependency(containerName).setService(
95                     IClusterContainerServices.class).setCallbacks(
96                     "setClusterContainerService",
97                     "unsetClusterContainerService").setRequired(true));
98         }
99     }
100
101     @Override
102     protected Object[] getGlobalImplementations() {
103         final Object[] res = { SwitchManagerCLI.class };
104         return res;
105     }
106 }