Merge "Switch to using yangtools version of mockito-configuration"
[controller.git] / opendaylight / networkconfiguration / neutron / implementation / src / main / java / org / opendaylight / controller / networkconfig / neutron / implementation / Activator.java
1 /*
2  * Copyright IBM Corporation, 2013.  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.networkconfig.neutron.implementation;
10
11 import java.util.Hashtable;
12 import java.util.Dictionary;
13
14 import org.apache.felix.dm.Component;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
18 import org.opendaylight.controller.configuration.IConfigurationContainerAware;
19 import org.opendaylight.controller.networkconfig.neutron.INeutronFloatingIPCRUD;
20 import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
21 import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
22 import org.opendaylight.controller.networkconfig.neutron.INeutronRouterCRUD;
23 import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;
24 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
25
26 public class Activator extends ComponentActivatorAbstractBase {
27     protected static final Logger logger = LoggerFactory
28     .getLogger(Activator.class);
29
30     /**
31      * Function called when the activator starts just after some
32      * initializations are done by the
33      * ComponentActivatorAbstractBase.
34      *
35      */
36     @Override
37     public void init() {
38
39     }
40
41     /**
42      * Function called when the activator stops just before the
43      * cleanup done by ComponentActivatorAbstractBase
44      *
45      */
46     @Override
47     public void destroy() {
48
49     }
50
51     /**
52      * Function that is used to communicate to dependency manager the
53      * list of known implementations for services inside a container
54      *
55      *
56      * @return An array containing all the CLASS objects that will be
57      * instantiated in order to get an fully working implementation
58      * Object
59      */
60     @Override
61     public Object[] getImplementations() {
62         Object[] res = { NeutronFloatingIPInterface.class,
63                 NeutronRouterInterface.class,
64                 NeutronPortInterface.class,
65                 NeutronSubnetInterface.class,
66                 NeutronNetworkInterface.class };
67         return res;
68     }
69
70     /**
71      * Function that is called when configuration of the dependencies
72      * is required.
73      *
74      * @param c dependency manager Component object, used for
75      * configuring the dependencies exported and imported
76      * @param imp Implementation class that is being configured,
77      * needed as long as the same routine can configure multiple
78      * implementations
79      * @param containerName The containerName being configured, this allow
80      * also optional per-container different behavior if needed, usually
81      * should not be the case though.
82      */
83     @Override
84     public void configureInstance(Component c, Object imp, String containerName) {
85         if (imp.equals(NeutronFloatingIPInterface.class)) {
86             // export the service
87             c.setInterface(
88                     new String[] { INeutronFloatingIPCRUD.class.getName(),
89                                    IConfigurationContainerAware.class.getName()}, null);
90             Dictionary<String, String> props = new Hashtable<String, String>();
91             props.put("salListenerName", "neutron");
92             c.add(createContainerServiceDependency(containerName)
93                     .setService(IClusterContainerServices.class)
94                     .setCallbacks("setClusterContainerService",
95                     "unsetClusterContainerService").setRequired(true));
96         }
97         if (imp.equals(NeutronRouterInterface.class)) {
98             // export the service
99             c.setInterface(
100                     new String[] { INeutronRouterCRUD.class.getName(),
101                                    IConfigurationContainerAware.class.getName()}, null);
102             Dictionary<String, String> props = new Hashtable<String, String>();
103             props.put("salListenerName", "neutron");
104             c.add(createContainerServiceDependency(containerName)
105                     .setService(IClusterContainerServices.class)
106                     .setCallbacks("setClusterContainerService",
107                     "unsetClusterContainerService").setRequired(true));
108         }
109         if (imp.equals(NeutronPortInterface.class)) {
110             // export the service
111             c.setInterface(
112                     new String[] { INeutronPortCRUD.class.getName(),
113                                    IConfigurationContainerAware.class.getName()}, null);
114             Dictionary<String, String> props = new Hashtable<String, String>();
115             props.put("salListenerName", "neutron");
116             c.add(createContainerServiceDependency(containerName)
117                     .setService(IClusterContainerServices.class)
118                     .setCallbacks("setClusterContainerService",
119                     "unsetClusterContainerService").setRequired(true));
120         }
121         if (imp.equals(NeutronSubnetInterface.class)) {
122             // export the service
123             c.setInterface(
124                     new String[] { INeutronSubnetCRUD.class.getName(),
125                                    IConfigurationContainerAware.class.getName()}, null);
126             Dictionary<String, String> props = new Hashtable<String, String>();
127             props.put("salListenerName", "neutron");
128             c.add(createContainerServiceDependency(containerName)
129                     .setService(IClusterContainerServices.class)
130                     .setCallbacks("setClusterContainerService",
131                     "unsetClusterContainerService").setRequired(true));
132         }
133         if (imp.equals(NeutronNetworkInterface.class)) {
134             // export the service
135             c.setInterface(
136                     new String[] { INeutronNetworkCRUD.class.getName(),
137                                    IConfigurationContainerAware.class.getName()}, null);
138             Dictionary<String, String> props = new Hashtable<String, String>();
139             props.put("salListenerName", "neutron");
140             c.add(createContainerServiceDependency(containerName)
141                     .setService(IClusterContainerServices.class)
142                     .setCallbacks("setClusterContainerService",
143                     "unsetClusterContainerService").setRequired(true));
144         }
145     }
146 }