Prevent ConfigPusher from killing its thread
[controller.git] / opendaylight / forwardingrulesmanager / implementation / src / main / java / org / opendaylight / controller / forwardingrulesmanager / 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.forwardingrulesmanager.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.configuration.IConfigurationContainerAware;
20 import org.opendaylight.controller.connectionmanager.IConnectionManager;
21 import org.opendaylight.controller.containermanager.IContainerManager;
22 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
23 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManagerAware;
24 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
25 import org.opendaylight.controller.sal.core.IContainer;
26 import org.opendaylight.controller.sal.core.IContainerLocalListener;
27 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
28 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
29 import org.opendaylight.controller.sal.utils.GlobalConstants;
30 import org.opendaylight.controller.switchmanager.IInventoryListener;
31 import org.opendaylight.controller.switchmanager.ISwitchManager;
32 import org.opendaylight.controller.switchmanager.ISwitchManagerAware;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class Activator extends ComponentActivatorAbstractBase {
37     protected static final Logger logger = LoggerFactory.getLogger(Activator.class);
38
39
40     /**
41      * Function that is used to communicate to dependency manager the list of
42      * known implementations for services inside a container
43      *
44      *
45      * @return An array containing all the CLASS objects that will be
46      *         instantiated in order to get an fully working implementation
47      *         Object
48      */
49     @Override
50     public Object[] getImplementations() {
51         Object[] res = { ForwardingRulesManager.class };
52         return res;
53     }
54
55     /**
56      * Function that is called when configuration of the dependencies is
57      * required.
58      *
59      * @param c
60      *            dependency manager Component object, used for configuring the
61      *            dependencies exported and imported
62      * @param imp
63      *            Implementation class that is being configured, needed as long
64      *            as the same routine can configure multiple implementations
65      * @param containerName
66      *            The containerName being configured, this allow also optional
67      *            per-container different behavior if needed, usually should not
68      *            be the case though.
69      */
70     @Override
71     public void configureInstance(Component c, Object imp, String containerName) {
72         if (imp.equals(ForwardingRulesManager.class)) {
73             String interfaces[] = null;
74             Dictionary<String, Object> props = new Hashtable<String, Object>();
75             Set<String> propSet = new HashSet<String>();
76             propSet.add(ForwardingRulesManager.WORK_STATUS_CACHE);
77             propSet.add(ForwardingRulesManager.WORK_ORDER_CACHE);
78             propSet.add(ForwardingRulesManager.INSTALLED_SW_VIEW_CACHE);
79             props.put("cachenames", propSet);
80
81             // export the service
82             interfaces = new String[] { IContainerLocalListener.class.getName(), ISwitchManagerAware.class.getName(),
83                     IForwardingRulesManager.class.getName(), IInventoryListener.class.getName(),
84                     IConfigurationContainerAware.class.getName(), ICacheUpdateAware.class.getName(),
85                     IFlowProgrammerListener.class.getName() };
86
87             c.setInterface(interfaces, props);
88
89             c.add(createContainerServiceDependency(containerName).setService(IFlowProgrammerService.class)
90                     .setCallbacks("setFlowProgrammerService", "unsetFlowProgrammerService").setRequired(true));
91             c.add(createContainerServiceDependency(containerName).setService(IClusterContainerServices.class)
92                     .setCallbacks("setClusterContainerService", "unsetClusterContainerService").setRequired(true));
93             c.add(createContainerServiceDependency(containerName).setService(ISwitchManager.class)
94                     .setCallbacks("setSwitchManager", "unsetSwitchManager").setRequired(true));
95             c.add(createContainerServiceDependency(containerName).setService(IForwardingRulesManagerAware.class)
96                     .setCallbacks("setFrmAware", "unsetFrmAware").setRequired(false));
97             c.add(createContainerServiceDependency(containerName).setService(IContainer.class)
98                     .setCallbacks("setIContainer", "unsetIContainer").setRequired(true));
99             c.add(createServiceDependency().setService(IConnectionManager.class)
100                     .setCallbacks("setIConnectionManager", "unsetIConnectionManager").setRequired(true));
101             if (GlobalConstants.DEFAULT.toString().equals(containerName)) {
102                 c.add(createServiceDependency().setService(IContainerManager.class)
103                         .setCallbacks("setIContainerManager", "unsetIContainerManager").setRequired(true));
104             }
105         }
106     }
107
108     @Override
109     protected Object[] getGlobalImplementations() {
110         final Object[] res = { ForwardingRulesManagerCLI.class };
111         return res;
112     }
113 }