Revert "Checkstyle enforcer"
[controller.git] / opendaylight / samples / loadbalancer / src / main / java / org / opendaylight / controller / samples / loadbalancer / internal / 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 package org.opendaylight.controller.samples.loadbalancer.internal;
9
10 import java.util.Dictionary;
11 import java.util.Hashtable;
12
13 import org.apache.felix.dm.Component;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
18 import org.opendaylight.controller.hosttracker.IfIptoHost;
19 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
20 import org.opendaylight.controller.sal.packet.IDataPacketService;
21 import org.opendaylight.controller.sal.packet.IListenDataPacket;
22 import org.opendaylight.controller.sal.routing.IRouting;
23 import org.opendaylight.controller.samples.loadbalancer.IConfigManager;
24
25 /**
26  * Main application activator class for registering the dependencies and 
27  * initialising the load balancer application.
28  *
29  */
30
31 public class Activator extends ComponentActivatorAbstractBase {
32     
33     /*
34      * Logger instance
35      */
36     protected static final Logger logger = LoggerFactory.getLogger(Activator.class);
37
38     /**
39      * Function called when the activator starts just after some
40      * initializations are done by the
41      * ComponentActivatorAbstractBase.
42      *
43      */
44     public void init() {
45     }
46
47     /**
48      * Function called when the activator stops just before the
49      * cleanup done by ComponentActivatorAbstractBase
50      *
51      */
52     public void destroy() {
53     }
54
55     /**
56      * Function that is used to communicate to dependency manager the
57      * list of known implementations for services inside a container
58      *
59      *
60      * @return An array containing all the CLASS objects that will be
61      * instantiated in order to get an fully working implementation
62      * Object
63      */
64     public Object[] getImplementations() {
65         Object[] res = { LoadBalancerService.class };
66         return res;
67     }
68
69     /**
70      * Function that is called when configuration of the dependencies
71      * is required.
72      *
73      * @param c dependency manager Component object, used for
74      * configuring the dependencies exported and imported
75      * @param imp Implementation class that is being configured,
76      * needed as long as the same routine can configure multiple
77      * implementations
78      * @param containerName The containerName being configured, this allow
79      * also optional per-container different behavior if needed, usually
80      * should not be the case though.
81      */
82     public void configureInstance(Component c, Object imp, String containerName) {
83         if (imp.equals(LoadBalancerService.class)) {
84             // export the service
85             Dictionary<String, String> props = new Hashtable<String, String>();
86             props.put("salListenerName", "loadbalancer");
87
88             c.setInterface(new String[] { IListenDataPacket.class.getName(),
89                         IConfigManager.class.getName()}, props);
90
91             c.add(createContainerServiceDependency(containerName).setService(
92                     IDataPacketService.class).setCallbacks(
93                     "setDataPacketService", "unsetDataPacketService")
94                     .setRequired(true));
95             
96             c.add(createContainerServiceDependency(containerName).setService(
97                     IRouting.class).setCallbacks("setRouting", "unsetRouting")
98                     .setRequired(false));
99
100             c.add(createContainerServiceDependency(containerName).setService(
101                     IfIptoHost.class).setCallbacks("setHostTracker",
102                     "unsetHostTracker").setRequired(true));
103
104             c.add(createContainerServiceDependency(containerName).setService(
105                     IForwardingRulesManager.class).setCallbacks(
106                     "setForwardingRulesManager", "unsetForwardingRulesManager")
107                     .setRequired(true));
108         }
109     }
110
111     /**
112      * Method which tells how many Global implementations are
113      * supported by the bundle. This way we can tune the number of
114      * components created. This components will be created ONLY at the
115      * time of bundle startup and will be destroyed only at time of
116      * bundle destruction, this is the major difference with the
117      * implementation retrieved via getImplementations where all of
118      * them are assumed to be in a container !
119      *
120      *
121      * @return The list of implementations the bundle will support,
122      * in Global version
123      */
124     protected Object[] getGlobalImplementations() {
125         return null;
126     }
127
128     /**
129      * Configure the dependency for a given instance Global
130      *
131      * @param c Component assigned for this instance, this will be
132      * what will be used for configuration
133      * @param imp implementation to be configured
134      * @param containerName container on which the configuration happens
135      */
136     protected void configureGlobalInstance(Component c, Object imp) {
137     }
138 }