b2a096aa7b36c3d3c85a2a54a9bbefe5b05e2836
[controller.git] / opendaylight / topologymanager / implementation / src / main / java / org / opendaylight / controller / topologymanager / 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.topologymanager.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.topology.IListenTopoUpdates;
23 import org.opendaylight.controller.sal.topology.ITopologyService;
24 import org.opendaylight.controller.switchmanager.ISwitchManager;
25 import org.opendaylight.controller.topologymanager.ITopologyManager;
26 import org.opendaylight.controller.topologymanager.ITopologyManagerAware;
27 import org.opendaylight.controller.topologymanager.ITopologyManagerClusterWideAware;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
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 = { TopologyManagerImpl.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(TopologyManagerImpl.class)) {
67             // export the service needed to listen to topology updates
68             Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
69             Set<String> propSet = new HashSet<String>();
70             propSet.add(TopologyManagerImpl.TOPOEDGESDB);
71             props.put("cachenames", propSet);
72
73             c.setInterface(new String[] { IListenTopoUpdates.class.getName(),
74                     ITopologyManager.class.getName(),
75                     IConfigurationContainerAware.class.getName(),
76                     ICacheUpdateAware.class.getName() }, props);
77
78             c.add(createContainerServiceDependency(containerName).setService(
79                     ITopologyService.class).setCallbacks("setTopoService",
80                     "unsetTopoService").setRequired(true));
81
82             c.add(createContainerServiceDependency(containerName).setService(
83                     ISwitchManager.class).setCallbacks("setSwitchManager",
84                     "unsetSwitchManager").setRequired(true));
85
86             // These are all the listeners for a topology manager
87             // updates, there could be many or none
88             c.add(createContainerServiceDependency(containerName).setService(
89                     ITopologyManagerAware.class).setCallbacks(
90                     "setTopologyManagerAware", "unsetTopologyManagerAware")
91                     .setRequired(false));
92
93             // These are all the listeners for a topology manager for the
94             // cluster wide events
95             // updates, there could be many or none
96             c.add(createContainerServiceDependency(containerName).setService(ITopologyManagerClusterWideAware.class)
97                     .setCallbacks("setTopologyManagerClusterWideAware", "unsetTopologyManagerClusterWideAware")
98                     .setRequired(false));
99
100             c.add(createContainerServiceDependency(containerName).setService(
101                     IClusterContainerServices.class).setCallbacks(
102                     "setClusterContainerService",
103                     "unsetClusterContainerService").setRequired(true));
104         }
105     }
106 }