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