2 * Copyright IBM Corporation, 2013. All rights reserved.
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
8 package org.opendaylight.controller.samples.loadbalancer.internal;
10 import java.util.Dictionary;
11 import java.util.Hashtable;
13 import org.apache.felix.dm.Component;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
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;
26 * Main application activator class for registering the dependencies and
27 * initialising the load balancer application.
31 public class Activator extends ComponentActivatorAbstractBase {
36 protected static final Logger logger = LoggerFactory.getLogger(Activator.class);
39 * Function called when the activator starts just after some
40 * initializations are done by the
41 * ComponentActivatorAbstractBase.
48 * Function called when the activator stops just before the
49 * cleanup done by ComponentActivatorAbstractBase
52 public void destroy() {
56 * Function that is used to communicate to dependency manager the
57 * list of known implementations for services inside a container
60 * @return An array containing all the CLASS objects that will be
61 * instantiated in order to get an fully working implementation
64 public Object[] getImplementations() {
65 Object[] res = { LoadBalancerService.class };
70 * Function that is called when configuration of the dependencies
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
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.
82 public void configureInstance(Component c, Object imp, String containerName) {
83 if (imp.equals(LoadBalancerService.class)) {
85 Dictionary<String, String> props = new Hashtable<String, String>();
86 props.put("salListenerName", "loadbalancer");
88 c.setInterface(new String[] { IListenDataPacket.class.getName(),
89 IConfigManager.class.getName()}, props);
91 c.add(createContainerServiceDependency(containerName).setService(
92 IDataPacketService.class).setCallbacks(
93 "setDataPacketService", "unsetDataPacketService")
96 c.add(createContainerServiceDependency(containerName).setService(
97 IRouting.class).setCallbacks("setRouting", "unsetRouting")
100 c.add(createContainerServiceDependency(containerName).setService(
101 IfIptoHost.class).setCallbacks("setHostTracker",
102 "unsetHostTracker").setRequired(true));
104 c.add(createContainerServiceDependency(containerName).setService(
105 IForwardingRulesManager.class).setCallbacks(
106 "setForwardingRulesManager", "unsetForwardingRulesManager")
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 !
121 * @return The list of implementations the bundle will support,
124 protected Object[] getGlobalImplementations() {
129 * Configure the dependency for a given instance Global
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
136 protected void configureGlobalInstance(Component c, Object imp) {