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