Resubmitted with source code synchronized. Added integration test for hosttracker...
[controller.git] / opendaylight / hosttracker / implementation / src / main / java / org / opendaylight / controller / hosttracker / 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.hosttracker.internal;
11
12 import org.apache.felix.dm.Component;
13 import org.opendaylight.controller.hosttracker.internal.HostTracker;
14 import org.opendaylight.controller.hosttracker.IfHostListener;
15 import org.opendaylight.controller.hosttracker.IfIptoHost;
16 import org.opendaylight.controller.hosttracker.IfNewHostNotify;
17 import org.opendaylight.controller.hosttracker.hostAware.IHostFinder;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
22 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
23 import org.opendaylight.controller.switchmanager.IInventoryListener;
24 import org.opendaylight.controller.switchmanager.ISwitchManager;
25 import org.opendaylight.controller.switchmanager.ISwitchManagerAware;
26 import org.opendaylight.controller.topologymanager.ITopologyManager;
27 import org.opendaylight.controller.topologymanager.ITopologyManagerAware;
28
29 public class Activator extends ComponentActivatorAbstractBase {
30     protected static final Logger logger = LoggerFactory
31             .getLogger(Activator.class);
32
33     /**
34      * Function called when the activator starts just after some
35      * initializations are done by the
36      * ComponentActivatorAbstractBase.
37      *
38      */
39     public void init() {
40     }
41
42     /**
43      * Function called when the activator stops just before the
44      * cleanup done by ComponentActivatorAbstractBase
45      *
46      */
47     public void destroy() {
48     }
49
50     /**
51      * Function that is used to communicate to dependency manager the
52      * list of known implementations for services inside a container
53      *
54      *
55      * @return An array containing all the CLASS objects that will be
56      * instantiated in order to get an fully working implementation
57      * Object
58      */
59     public Object[] getImplementations() {
60         Object[] res = { HostTracker.class };
61         return res;
62     }
63
64     /**
65      * Function that is called when configuration of the dependencies
66      * is required.
67      *
68      * @param c dependency manager Component object, used for
69      * configuring the dependencies exported and imported
70      * @param imp Implementation class that is being configured,
71      * needed as long as the same routine can configure multiple
72      * implementations
73      * @param containerName The containerName being configured, this allow
74      * also optional per-container different behavior if needed, usually
75      * should not be the case though.
76      */
77     public void configureInstance(Component c, Object imp, String containerName) {
78         if (imp.equals(HostTracker.class)) {
79             // export the service
80             c.setInterface(new String[] { ISwitchManagerAware.class.getName(),
81                     IInventoryListener.class.getName(),
82                     IfIptoHost.class.getName(), IfHostListener.class.getName(),
83                     ITopologyManagerAware.class.getName() }, null);
84
85             c.add(createContainerServiceDependency(containerName).setService(
86                     ISwitchManager.class).setCallbacks("setSwitchManager",
87                     "unsetSwitchManager").setRequired(false));
88             c.add(createContainerServiceDependency(containerName).setService(
89                     IClusterContainerServices.class).setCallbacks(
90                     "setClusterContainerService",
91                     "unsetClusterContainerService").setRequired(true));
92             c.add(createContainerServiceDependency(containerName).setService(
93                     IHostFinder.class).setCallbacks("setArpHandler",
94                     "unsetArpHandler").setRequired(false));
95             c.add(createContainerServiceDependency(containerName).setService(
96                     ITopologyManager.class).setCallbacks("setTopologyManager",
97                     "unsetTopologyManager").setRequired(false));
98             c.add(createContainerServiceDependency(containerName).setService(
99                     IfNewHostNotify.class).setCallbacks("setnewHostNotify",
100                     "unsetnewHostNotify").setRequired(false));
101         }
102     }
103
104     /**
105      * Method which tells how many Global implementations are
106      * supported by the bundle. This way we can tune the number of
107      * components created. This components will be created ONLY at the
108      * time of bundle startup and will be destroyed only at time of
109      * bundle destruction, this is the major difference with the
110      * implementation retrieved via getImplementations where all of
111      * them are assumed to be in a container !
112      *
113      *
114      * @return The list of implementations the bundle will support,
115      * in Global version
116      */
117     protected Object[] getGlobalImplementations() {
118         return null;
119     }
120
121     /**
122      * Configure the dependency for a given instance Global
123      *
124      * @param c Component assigned for this instance, this will be
125      * what will be used for configuration
126      * @param imp implementation to be configured
127      * @param containerName container on which the configuration happens
128      */
129     protected void configureGlobalInstance(Component c, Object imp) {
130         if (imp.equals(HostTracker.class)) {
131         }
132     }
133 }