Process host pending list on a Cache sync update.
[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      * Function called when the activator starts just after some initializations
38      * are done by the ComponentActivatorAbstractBase.
39      *
40      */
41     public void init() {
42     }
43
44     /**
45      * Function called when the activator stops just before the cleanup done by
46      * ComponentActivatorAbstractBase
47      *
48      */
49     public void destroy() {
50     }
51
52     /**
53      * Function that is used to communicate to dependency manager the list of
54      * known implementations for services inside a container
55      *
56      *
57      * @return An array containing all the CLASS objects that will be
58      *         instantiated in order to get an fully working implementation
59      *         Object
60      */
61     public Object[] getImplementations() {
62         Object[] res = { HostTracker.class };
63         return res;
64     }
65
66     /**
67      * Function that is called when configuration of the dependencies is
68      * required.
69      *
70      * @param c
71      *            dependency manager Component object, used for configuring the
72      *            dependencies exported and imported
73      * @param imp
74      *            Implementation class that is being configured, needed as long
75      *            as the same routine can configure multiple implementations
76      * @param containerName
77      *            The containerName being configured, this allow also optional
78      *            per-container different behavior if needed, usually should not
79      *            be the case though.
80      */
81     public void configureInstance(Component c, Object imp, String containerName) {
82         if (imp.equals(HostTracker.class)) {
83             Dictionary<String, Object> props = new Hashtable<String, Object>();
84             Set<String> propSet = new HashSet<String>();
85             propSet.add(HostTracker.ACTIVE_HOST_CACHE);
86             props.put("cachenames", propSet);
87
88             // export the service
89             c.setInterface(
90                     new String[] { ISwitchManagerAware.class.getName(),
91                             IInventoryListener.class.getName(),
92                             IfIptoHost.class.getName(),
93                             IfHostListener.class.getName(),
94                             ITopologyManagerAware.class.getName(),
95                             ICacheUpdateAware.class.getName() }, props);
96
97             c.add(createContainerServiceDependency(containerName)
98                     .setService(ISwitchManager.class)
99                     .setCallbacks("setSwitchManager", "unsetSwitchManager")
100                     .setRequired(false));
101             c.add(createContainerServiceDependency(containerName)
102                     .setService(IClusterContainerServices.class)
103                     .setCallbacks("setClusterContainerService",
104                             "unsetClusterContainerService").setRequired(true));
105             c.add(createContainerServiceDependency(containerName)
106                     .setService(IHostFinder.class)
107                     .setCallbacks("setArpHandler", "unsetArpHandler")
108                     .setRequired(false));
109             c.add(createContainerServiceDependency(containerName)
110                     .setService(ITopologyManager.class)
111                     .setCallbacks("setTopologyManager", "unsetTopologyManager")
112                     .setRequired(false));
113             c.add(createContainerServiceDependency(containerName)
114                     .setService(IfNewHostNotify.class)
115                     .setCallbacks("setnewHostNotify", "unsetnewHostNotify")
116                     .setRequired(false));
117         }
118     }
119
120     /**
121      * Method which tells how many Global implementations are supported by the
122      * bundle. This way we can tune the number of components created. This
123      * components will be created ONLY at the time of bundle startup and will be
124      * destroyed only at time of bundle destruction, this is the major
125      * difference with the implementation retrieved via getImplementations where
126      * all of them are assumed to be in a container !
127      *
128      *
129      * @return The list of implementations the bundle will support, in Global
130      *         version
131      */
132     protected Object[] getGlobalImplementations() {
133         return null;
134     }
135
136     /**
137      * Configure the dependency for a given instance Global
138      *
139      * @param c
140      *            Component assigned for this instance, this will be what will
141      *            be used for configuration
142      * @param imp
143      *            implementation to be configured
144      * @param containerName
145      *            container on which the configuration happens
146      */
147     protected void configureGlobalInstance(Component c, Object imp) {
148         if (imp.equals(HostTracker.class)) {
149         }
150     }
151 }