Move init and destroy empty impl from Activator classes. Have only one
[controller.git] / opendaylight / 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.IfHostListener;
20 import org.opendaylight.controller.hosttracker.IfIptoHost;
21 import org.opendaylight.controller.hosttracker.IfNewHostNotify;
22 import org.opendaylight.controller.hosttracker.hostAware.IHostFinder;
23 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
24 import org.opendaylight.controller.switchmanager.IInventoryListener;
25 import org.opendaylight.controller.switchmanager.ISwitchManager;
26 import org.opendaylight.controller.switchmanager.ISwitchManagerAware;
27 import org.opendaylight.controller.topologymanager.ITopologyManager;
28 import org.opendaylight.controller.topologymanager.ITopologyManagerAware;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 public class Activator extends ComponentActivatorAbstractBase {
33     protected static final Logger logger = LoggerFactory
34             .getLogger(Activator.class);
35
36
37     /**
38      * Function that is used to communicate to dependency manager the list of
39      * known implementations for services inside a container
40      *
41      *
42      * @return An array containing all the CLASS objects that will be
43      *         instantiated in order to get an fully working implementation
44      *         Object
45      */
46     @Override
47     public Object[] getImplementations() {
48         Object[] res = { HostTracker.class };
49         return res;
50     }
51
52     /**
53      * Function that is called when configuration of the dependencies is
54      * required.
55      *
56      * @param c
57      *            dependency manager Component object, used for configuring the
58      *            dependencies exported and imported
59      * @param imp
60      *            Implementation class that is being configured, needed as long
61      *            as the same routine can configure multiple implementations
62      * @param containerName
63      *            The containerName being configured, this allow also optional
64      *            per-container different behavior if needed, usually should not
65      *            be the case though.
66      */
67     @Override
68     public void configureInstance(Component c, Object imp, String containerName) {
69         if (imp.equals(HostTracker.class)) {
70             Dictionary<String, Object> props = new Hashtable<String, Object>();
71             Set<String> propSet = new HashSet<String>();
72             propSet.add(HostTracker.ACTIVE_HOST_CACHE);
73             props.put("cachenames", propSet);
74
75             // export the service
76             c.setInterface(
77                     new String[] { ISwitchManagerAware.class.getName(),
78                             IInventoryListener.class.getName(),
79                             IfIptoHost.class.getName(),
80                             IfHostListener.class.getName(),
81                             ITopologyManagerAware.class.getName(),
82                             ICacheUpdateAware.class.getName() }, props);
83
84             c.add(createContainerServiceDependency(containerName)
85                     .setService(ISwitchManager.class)
86                     .setCallbacks("setSwitchManager", "unsetSwitchManager")
87                     .setRequired(false));
88             c.add(createContainerServiceDependency(containerName)
89                     .setService(IClusterContainerServices.class)
90                     .setCallbacks("setClusterContainerService",
91                             "unsetClusterContainerService").setRequired(true));
92             c.add(createContainerServiceDependency(containerName)
93                     .setService(IHostFinder.class)
94                     .setCallbacks("setArpHandler", "unsetArpHandler")
95                     .setRequired(false));
96             c.add(createContainerServiceDependency(containerName)
97                     .setService(ITopologyManager.class)
98                     .setCallbacks("setTopologyManager", "unsetTopologyManager")
99                     .setRequired(false));
100             c.add(createContainerServiceDependency(containerName)
101                     .setService(IfNewHostNotify.class)
102                     .setCallbacks("setnewHostNotify", "unsetnewHostNotify")
103                     .setRequired(false));
104         }
105     }
106 }