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