Merge "Move adsal into its own subdirectory."
[controller.git] / opendaylight / adsal / hosttracker / implementation / src / main / java / org / opendaylight / controller / hosttracker / internal / Activator.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.hosttracker.internal;
10
11 import java.util.Dictionary;
12 import java.util.HashSet;
13 import java.util.Hashtable;
14 import java.util.Set;
15
16 import org.apache.felix.dm.Component;
17 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
18 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
19 import org.opendaylight.controller.hosttracker.IHostTrackerShell;
20 import org.opendaylight.controller.hosttracker.IfHostListener;
21 import org.opendaylight.controller.hosttracker.IfIptoHost;
22 import org.opendaylight.controller.hosttracker.IfNewHostNotify;
23 import org.opendaylight.controller.hosttracker.hostAware.IHostFinder;
24 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
25 import org.opendaylight.controller.switchmanager.IInventoryListener;
26 import org.opendaylight.controller.switchmanager.ISwitchManager;
27 import org.opendaylight.controller.switchmanager.ISwitchManagerAware;
28 import org.opendaylight.controller.topologymanager.ITopologyManager;
29 import org.opendaylight.controller.topologymanager.ITopologyManagerAware;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class Activator extends ComponentActivatorAbstractBase {
34     protected static final Logger logger = LoggerFactory
35             .getLogger(Activator.class);
36
37
38     /**
39      * Function that is used to communicate to dependency manager the list of
40      * known implementations for services inside a container
41      *
42      *
43      * @return An array containing all the CLASS objects that will be
44      *         instantiated in order to get an fully working implementation
45      *         Object
46      */
47     @Override
48     public Object[] getImplementations() {
49         Object[] res = { HostTracker.class };
50         return res;
51     }
52
53     /**
54      * Function that is called when configuration of the dependencies is
55      * required.
56      *
57      * @param c
58      *            dependency manager Component object, used for configuring the
59      *            dependencies exported and imported
60      * @param imp
61      *            Implementation class that is being configured, needed as long
62      *            as the same routine can configure multiple implementations
63      * @param containerName
64      *            The containerName being configured, this allow also optional
65      *            per-container different behavior if needed, usually should not
66      *            be the case though.
67      */
68     @Override
69     public void configureInstance(Component c, Object imp, String containerName) {
70         if (imp.equals(HostTracker.class)) {
71             Dictionary<String, Object> props = new Hashtable<String, Object>();
72             Set<String> propSet = new HashSet<String>();
73             propSet.add(HostTracker.ACTIVE_HOST_CACHE);
74             props.put("cachenames", propSet);
75
76             // export the service
77             c.setInterface(
78                     new String[] { ISwitchManagerAware.class.getName(),
79                             IInventoryListener.class.getName(),
80                             IfIptoHost.class.getName(),
81                             IfHostListener.class.getName(),
82                             IHostTrackerShell.class.getName(),
83                             ITopologyManagerAware.class.getName(),
84                             ICacheUpdateAware.class.getName() }, props);
85
86             c.add(createContainerServiceDependency(containerName)
87                     .setService(ISwitchManager.class)
88                     .setCallbacks("setSwitchManager", "unsetSwitchManager")
89                     .setRequired(true));
90             c.add(createContainerServiceDependency(containerName)
91                     .setService(IClusterContainerServices.class)
92                     .setCallbacks("setClusterContainerService",
93                             "unsetClusterContainerService").setRequired(true));
94             c.add(createContainerServiceDependency(containerName)
95                     .setService(IHostFinder.class)
96                     .setCallbacks("setArpHandler", "unsetArpHandler")
97                     .setRequired(false));
98             c.add(createContainerServiceDependency(containerName)
99                     .setService(ITopologyManager.class)
100                     .setCallbacks("setTopologyManager", "unsetTopologyManager")
101                     .setRequired(false));
102             c.add(createContainerServiceDependency(containerName)
103                     .setService(IfNewHostNotify.class)
104                     .setCallbacks("setnewHostNotify", "unsetnewHostNotify")
105                     .setRequired(false));
106         }
107     }
108 }