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);
40 * Function that is used to communicate to dependency manager the
41 * list of known implementations for services inside a container
44 * @return An array containing all the CLASS objects that will be
45 * instantiated in order to get an fully working implementation
48 public Object[] getImplementations() {
49 Object[] res = { LoadBalancerService.class };
54 * Function that is called when configuration of the dependencies
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
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.
66 public void configureInstance(Component c, Object imp, String containerName) {
67 if (imp.equals(LoadBalancerService.class)) {
69 Dictionary<String, String> props = new Hashtable<String, String>();
70 props.put("salListenerName", "loadbalancer");
72 c.setInterface(new String[] { IListenDataPacket.class.getName(),
73 IConfigManager.class.getName()}, props);
75 c.add(createContainerServiceDependency(containerName).setService(
76 IDataPacketService.class).setCallbacks(
77 "setDataPacketService", "unsetDataPacketService")
80 c.add(createContainerServiceDependency(containerName).setService(
81 IRouting.class).setCallbacks("setRouting", "unsetRouting")
84 c.add(createContainerServiceDependency(containerName).setService(
85 IfIptoHost.class).setCallbacks("setHostTracker",
86 "unsetHostTracker").setRequired(true));
88 c.add(createContainerServiceDependency(containerName).setService(
89 IForwardingRulesManager.class).setCallbacks(
90 "setForwardingRulesManager", "unsetForwardingRulesManager")
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 !
105 * @return The list of implementations the bundle will support,
108 protected Object[] getGlobalImplementations() {
113 * Configure the dependency for a given instance Global
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
120 protected void configureGlobalInstance(Component c, Object imp) {