248623cce8326e93288498d9af9ec15d92b100a2
[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.Dictionary;
13 import java.util.HashSet;
14 import java.util.Hashtable;
15 import java.util.Set;
16
17 import org.apache.felix.dm.Component;
18 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
19 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
20 import org.opendaylight.controller.connectionmanager.IConnectionManager;
21 import org.opendaylight.controller.hosttracker.IfHostListener;
22 import org.opendaylight.controller.hosttracker.IfIptoHost;
23 import org.opendaylight.controller.hosttracker.hostAware.IHostFinder;
24 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
25 import org.opendaylight.controller.sal.packet.IDataPacketService;
26 import org.opendaylight.controller.sal.packet.IListenDataPacket;
27 import org.opendaylight.controller.switchmanager.ISwitchManager;
28 import org.opendaylight.controller.topologymanager.ITopologyManager;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 public class Activator extends ComponentActivatorAbstractBase {
33     protected static final Logger logger = LoggerFactory
34             .getLogger(Activator.class);
35
36     /**
37      * Function called when the activator starts just after some
38      * initializations are done by the
39      * ComponentActivatorAbstractBase.
40      *
41      */
42     public void init() {
43
44     }
45
46     /**
47      * Function called when the activator stops just before the
48      * cleanup done by ComponentActivatorAbstractBase
49      *
50      */
51     public void destroy() {
52
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 = { ArpHandler.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(ArpHandler.class)) {
84             // export the service
85             Dictionary<String, Object> props = new Hashtable<String, Object>();
86             props.put("salListenerName", "arphandler");
87             Set<String> propSet = new HashSet<String>();
88             propSet.add(ArpHandler.ARP_EVENT_CACHE_NAME);
89             props.put("cachenames", propSet);
90
91             c.setInterface(new String[] {
92                     IHostFinder.class.getName(),
93                     IListenDataPacket.class.getName(),
94                     ICacheUpdateAware.class.getName()}, props);
95
96             // We need connection mgr to distribute packet out across the cluster
97             c.add(createServiceDependency().setService(
98                     IConnectionManager.class).setCallbacks("setConnectionManager",
99                     "unsetConnectionManager").setRequired(true));
100
101
102             c.add(createContainerServiceDependency(containerName).setService(
103                     ISwitchManager.class).setCallbacks("setSwitchManager",
104                     "unsetSwitchManager").setRequired(true));
105
106             c.add(createContainerServiceDependency(containerName).setService(
107                     ITopologyManager.class).setCallbacks("setTopologyManager",
108                     "unsetTopologyMananger").setRequired(true));
109
110             c.add(createContainerServiceDependency(containerName).setService(
111                     IDataPacketService.class).setCallbacks(
112                     "setDataPacketService", "unsetDataPacketService")
113                     .setRequired(true));
114
115             c.add(createContainerServiceDependency(containerName).setService(
116                    IClusterContainerServices.class).setCallbacks(
117                    "setClusterContainerService", "unsetClusterContainerService")
118                    .setRequired(true));
119
120             // the Host Listener is optional
121             c.add(createContainerServiceDependency(containerName).setService(
122                     IfHostListener.class).setCallbacks("setHostListener",
123                     "unsetHostListener").setRequired(false));
124
125             // the IfIptoHost is a required dependency
126             c.add(createContainerServiceDependency(containerName).setService(
127                     IfIptoHost.class).setCallbacks("setHostTracker",
128                     "unsetHostTracker").setRequired(true));
129         }
130     }
131 }