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