Gracefully stop HT threads when the bundle is being stopped (cache terminated exception)
[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     @Override
42     public void init() {
43     }
44
45     /**
46      * Function called when the activator stops just before the cleanup done by
47      * ComponentActivatorAbstractBase
48      *
49      */
50     @Override
51     public void destroy() {
52     }
53
54     /**
55      * Function that is used to communicate to dependency manager the list of
56      * known implementations for services inside a container
57      *
58      *
59      * @return An array containing all the CLASS objects that will be
60      *         instantiated in order to get an fully working implementation
61      *         Object
62      */
63     @Override
64     public Object[] getImplementations() {
65         Object[] res = { HostTracker.class };
66         return res;
67     }
68
69     /**
70      * Function that is called when configuration of the dependencies is
71      * required.
72      *
73      * @param c
74      *            dependency manager Component object, used for configuring the
75      *            dependencies exported and imported
76      * @param imp
77      *            Implementation class that is being configured, needed as long
78      *            as the same routine can configure multiple implementations
79      * @param containerName
80      *            The containerName being configured, this allow also optional
81      *            per-container different behavior if needed, usually should not
82      *            be the case though.
83      */
84     @Override
85     public void configureInstance(Component c, Object imp, String containerName) {
86         if (imp.equals(HostTracker.class)) {
87             Dictionary<String, Object> props = new Hashtable<String, Object>();
88             Set<String> propSet = new HashSet<String>();
89             propSet.add(HostTracker.ACTIVE_HOST_CACHE);
90             props.put("cachenames", propSet);
91
92             // export the service
93             c.setInterface(
94                     new String[] { ISwitchManagerAware.class.getName(),
95                             IInventoryListener.class.getName(),
96                             IfIptoHost.class.getName(),
97                             IfHostListener.class.getName(),
98                             ITopologyManagerAware.class.getName(),
99                             ICacheUpdateAware.class.getName() }, props);
100
101             c.add(createContainerServiceDependency(containerName)
102                     .setService(ISwitchManager.class)
103                     .setCallbacks("setSwitchManager", "unsetSwitchManager")
104                     .setRequired(false));
105             c.add(createContainerServiceDependency(containerName)
106                     .setService(IClusterContainerServices.class)
107                     .setCallbacks("setClusterContainerService",
108                             "unsetClusterContainerService").setRequired(true));
109             c.add(createContainerServiceDependency(containerName)
110                     .setService(IHostFinder.class)
111                     .setCallbacks("setArpHandler", "unsetArpHandler")
112                     .setRequired(false));
113             c.add(createContainerServiceDependency(containerName)
114                     .setService(ITopologyManager.class)
115                     .setCallbacks("setTopologyManager", "unsetTopologyManager")
116                     .setRequired(false));
117             c.add(createContainerServiceDependency(containerName)
118                     .setService(IfNewHostNotify.class)
119                     .setCallbacks("setnewHostNotify", "unsetnewHostNotify")
120                     .setRequired(false));
121         }
122     }
123 }