Fix for bug 24.
[controller.git] / opendaylight / arphandler / src / main / java / org / opendaylight / controller / arphandler / internal / Activator.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.arphandler.internal;
11
12 import java.util.Hashtable;
13 import java.util.Dictionary;
14 import org.apache.felix.dm.Component;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 import org.opendaylight.controller.hosttracker.IfHostListener;
19 import org.opendaylight.controller.hosttracker.IfIptoHost;
20 import org.opendaylight.controller.hosttracker.hostAware.IHostFinder;
21 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
22 import org.opendaylight.controller.sal.packet.IListenDataPacket;
23 import org.opendaylight.controller.sal.packet.IDataPacketService;
24 import org.opendaylight.controller.switchmanager.ISwitchManager;
25 import org.opendaylight.controller.topologymanager.ITopologyManager;
26
27 public class Activator extends ComponentActivatorAbstractBase {
28     protected static final Logger logger = LoggerFactory
29             .getLogger(Activator.class);
30
31     /**
32      * Function called when the activator starts just after some
33      * initializations are done by the
34      * ComponentActivatorAbstractBase.
35      *
36      */
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     public void destroy() {
47
48     }
49
50     /**
51      * Function that is used to communicate to dependency manager the
52      * list of known implementations for services inside a container
53      *
54      *
55      * @return An array containing all the CLASS objects that will be
56      * instantiated in order to get an fully working implementation
57      * Object
58      */
59     public Object[] getImplementations() {
60         Object[] res = { ArpHandler.class };
61         return res;
62     }
63
64     /**
65      * Function that is called when configuration of the dependencies
66      * is required.
67      *
68      * @param c dependency manager Component object, used for
69      * configuring the dependencies exported and imported
70      * @param imp Implementation class that is being configured,
71      * needed as long as the same routine can configure multiple
72      * implementations
73      * @param containerName The containerName being configured, this allow
74      * also optional per-container different behavior if needed, usually
75      * should not be the case though.
76      */
77     public void configureInstance(Component c, Object imp, String containerName) {
78         if (imp.equals(ArpHandler.class)) {
79             // export the service
80             Dictionary<String, String> props = new Hashtable<String, String>();
81             props.put("salListenerName", "arphandler");
82             c.setInterface(new String[] { IHostFinder.class.getName(),
83                     IListenDataPacket.class.getName() }, props);
84
85             c.add(createContainerServiceDependency(containerName).setService(
86                     ISwitchManager.class).setCallbacks("setSwitchManager",
87                     "unsetSwitchManager").setRequired(true));
88
89             c.add(createContainerServiceDependency(containerName).setService(
90                     ITopologyManager.class).setCallbacks("setTopologyManager",
91                     "unsetTopologyMananger").setRequired(true));
92
93            c.add(createContainerServiceDependency(containerName).setService(
94                     IDataPacketService.class).setCallbacks(
95                     "setDataPacketService", "unsetDataPacketService")
96                     .setRequired(true));
97
98             // the Host Listener is optional
99             c.add(createContainerServiceDependency(containerName).setService(
100                     IfHostListener.class).setCallbacks("setHostListener",
101                     "unsetHostListener").setRequired(false));
102
103             // the IfIptoHost is a required dependency
104             c.add(createContainerServiceDependency(containerName).setService(
105                     IfIptoHost.class).setCallbacks("setHostTracker",
106                     "unsetHostTracker").setRequired(true));
107         }
108     }
109 }