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