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