Move init and destroy empty impl from Activator classes. Have only one
[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     /**
40      * Function that is used to communicate to dependency manager the
41      * list of 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     public Object[] getImplementations() {
49         Object[] res = { LoadBalancerService.class };
50         return res;
51     }
52
53     /**
54      * Function that is called when configuration of the dependencies
55      * is required.
56      *
57      * @param c dependency manager Component object, used for
58      * configuring the dependencies exported and imported
59      * @param imp Implementation class that is being configured,
60      * needed as long as the same routine can configure multiple
61      * implementations
62      * @param containerName The containerName being configured, this allow
63      * also optional per-container different behavior if needed, usually
64      * should not be the case though.
65      */
66     public void configureInstance(Component c, Object imp, String containerName) {
67         if (imp.equals(LoadBalancerService.class)) {
68             // export the service
69             Dictionary<String, String> props = new Hashtable<String, String>();
70             props.put("salListenerName", "loadbalancer");
71
72             c.setInterface(new String[] { IListenDataPacket.class.getName(),
73                         IConfigManager.class.getName()}, props);
74
75             c.add(createContainerServiceDependency(containerName).setService(
76                     IDataPacketService.class).setCallbacks(
77                     "setDataPacketService", "unsetDataPacketService")
78                     .setRequired(true));
79
80             c.add(createContainerServiceDependency(containerName).setService(
81                     IRouting.class).setCallbacks("setRouting", "unsetRouting")
82                     .setRequired(false));
83
84             c.add(createContainerServiceDependency(containerName).setService(
85                     IfIptoHost.class).setCallbacks("setHostTracker",
86                     "unsetHostTracker").setRequired(true));
87
88             c.add(createContainerServiceDependency(containerName).setService(
89                     IForwardingRulesManager.class).setCallbacks(
90                     "setForwardingRulesManager", "unsetForwardingRulesManager")
91                     .setRequired(true));
92         }
93     }
94
95     /**
96      * Method which tells how many Global implementations are
97      * supported by the bundle. This way we can tune the number of
98      * components created. This components will be created ONLY at the
99      * time of bundle startup and will be destroyed only at time of
100      * bundle destruction, this is the major difference with the
101      * implementation retrieved via getImplementations where all of
102      * them are assumed to be in a container !
103      *
104      *
105      * @return The list of implementations the bundle will support,
106      * in Global version
107      */
108     protected Object[] getGlobalImplementations() {
109         return null;
110     }
111
112     /**
113      * Configure the dependency for a given instance Global
114      *
115      * @param c Component assigned for this instance, this will be
116      * what will be used for configuration
117      * @param imp implementation to be configured
118      * @param containerName container on which the configuration happens
119      */
120     protected void configureGlobalInstance(Component c, Object imp) {
121     }
122 }