Add container context debug osgi cli command to Switch Manager
[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.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             Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
93             Set<String> propSet = new HashSet<String>();
94             propSet.add("switchmanager.configSaveEvent");
95             props.put("cachenames", propSet);
96             // export the service
97             c.setInterface(new String[] {
98                     IListenInventoryUpdates.class.getName(),
99                     ISwitchManager.class.getName(),
100                     ICacheUpdateAware.class.getName(),
101                     IConfigurationContainerAware.class.getName() }, props);
102
103             // Now lets add a service dependency to make sure the
104             // provider of service exists
105             c.add(createContainerServiceDependency(containerName).setService(
106                     IInventoryService.class).setCallbacks(
107                     "setInventoryService", "unsetInventoryService")
108                     .setRequired(false));
109             c.add(createContainerServiceDependency(containerName).setService(
110                     ISwitchManagerAware.class).setCallbacks(
111                     "setSwitchManagerAware", "unsetSwitchManagerAware")
112                     .setRequired(false));
113             c.add(createContainerServiceDependency(containerName).setService(
114                     IInventoryListener.class).setCallbacks(
115                     "setInventoryListener", "unsetInventoryListener")
116                     .setRequired(false));
117             c.add(createContainerServiceDependency(containerName).setService(
118                     ISpanAware.class).setCallbacks("setSpanAware",
119                     "unsetSpanAware").setRequired(false));
120             c.add(createContainerServiceDependency(containerName).setService(
121                     IClusterContainerServices.class).setCallbacks(
122                     "setClusterContainerService",
123                     "unsetClusterContainerService").setRequired(true));
124         }
125     }
126
127     @Override
128     protected Object[] getGlobalImplementations() {
129         final Object[] res = { SwitchManagerCLI.class };
130         return res;
131     }
132 }