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