Merge "Do not catch Throwables, but rather Exceptions"
[controller.git] / opendaylight / samples / simpleforwarding / src / main / java / org / opendaylight / controller / samples / simpleforwarding / 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.samples.simpleforwarding.internal;
11
12 import java.util.Dictionary;
13 import java.util.Hashtable;
14
15 import org.apache.felix.dm.Component;
16 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
17 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
18 import org.opendaylight.controller.hosttracker.IfIptoHost;
19 import org.opendaylight.controller.hosttracker.IfNewHostNotify;
20 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
21 import org.opendaylight.controller.sal.packet.IDataPacketService;
22 import org.opendaylight.controller.sal.packet.IListenDataPacket;
23 import org.opendaylight.controller.sal.routing.IListenRoutingUpdates;
24 import org.opendaylight.controller.sal.routing.IRouting;
25 import org.opendaylight.controller.samples.simpleforwarding.IBroadcastHandler;
26 import org.opendaylight.controller.samples.simpleforwarding.IBroadcastPortSelector;
27 import org.opendaylight.controller.switchmanager.IInventoryListener;
28 import org.opendaylight.controller.switchmanager.ISwitchManager;
29 import org.opendaylight.controller.topologymanager.ITopologyManager;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class Activator extends ComponentActivatorAbstractBase {
34     protected static final Logger logger = LoggerFactory
35             .getLogger(Activator.class);
36
37
38     /**
39      * Function that is used to communicate to dependency manager the
40      * list of known implementations for services inside a container
41      *
42      *
43      * @return An array containing all the CLASS objects that will be
44      * instantiated in order to get an fully working implementation
45      * Object
46      */
47     @Override
48     public Object[] getImplementations() {
49         Object[] res = { SimpleForwardingImpl.class,
50                          SimpleBroadcastHandlerImpl.class };
51         return res;
52     }
53
54     /**
55      * Function that is called when configuration of the dependencies
56      * is required.
57      *
58      * @param c dependency manager Component object, used for
59      * configuring the dependencies exported and imported
60      * @param imp Implementation class that is being configured,
61      * needed as long as the same routine can configure multiple
62      * implementations
63      * @param containerName The containerName being configured, this allow
64      * also optional per-container different behavior if needed, usually
65      * should not be the case though.
66      */
67     @Override
68     public void configureInstance(Component c, Object imp, String containerName) {
69         if (imp.equals(SimpleForwardingImpl.class)) {
70             Dictionary<String, Object> props = new Hashtable<String, Object>();
71             props.put("salListenerName", "simpleforwarding");
72
73             // export the service
74             c.setInterface(new String[] { IInventoryListener.class.getName(),
75                     IfNewHostNotify.class.getName(),
76                     IListenRoutingUpdates.class.getName(),
77                     IListenDataPacket.class.getName() }, props);
78
79             c.add(createContainerServiceDependency(containerName).setService(
80                     IClusterContainerServices.class).setCallbacks(
81                     "setClusterContainerService",
82                     "unsetClusterContainerService").setRequired(true));
83
84             c.add(createContainerServiceDependency(containerName).setService(
85                     ISwitchManager.class).setCallbacks("setSwitchManager",
86                     "unsetSwitchManager").setRequired(false));
87
88             c.add(createContainerServiceDependency(containerName).setService(
89                     IfIptoHost.class).setCallbacks("setHostTracker",
90                     "unsetHostTracker").setRequired(false));
91
92             c.add(createContainerServiceDependency(containerName).setService(
93                     IForwardingRulesManager.class).setCallbacks(
94                     "setForwardingRulesManager", "unsetForwardingRulesManager")
95                     .setRequired(false));
96
97             c.add(createContainerServiceDependency(containerName).setService(
98                     ITopologyManager.class).setCallbacks("setTopologyManager",
99                     "unsetTopologyManager").setRequired(false));
100
101             c.add(createContainerServiceDependency(containerName).setService(
102                     IRouting.class).setCallbacks("setRouting", "unsetRouting")
103                     .setRequired(false));
104             c.add(createContainerServiceDependency(containerName).setService(
105                     IDataPacketService.class).setCallbacks("setDataPacketService",
106                    "unsetDataPacketService").setRequired(false));
107
108         } else if (imp.equals(SimpleBroadcastHandlerImpl.class)) {
109             Dictionary<String, String> props = new Hashtable<String, String>();
110             props.put("salListenerName", "simplebroadcasthandler");
111
112             // export the service
113             c.setInterface(new String[] { IBroadcastHandler.class.getName(),
114                     IListenDataPacket.class.getName() }, props);
115
116             c.add(createContainerServiceDependency(containerName).setService(
117                     IDataPacketService.class).setCallbacks("setDataPacketService",
118                    "unsetDataPacketService").setRequired(false));
119
120             c.add(createContainerServiceDependency(containerName).setService(
121                    ITopologyManager.class).setCallbacks("setTopologyManager",
122                    "unsetTopologyManager").setRequired(true));
123
124             c.add(createContainerServiceDependency(containerName).setService(
125                    IBroadcastPortSelector.class).setCallbacks("setBroadcastPortSelector",
126                    "unsetBroadcastPortSelector").setRequired(false));
127
128             c.add(createContainerServiceDependency(containerName).setService(
129                    ISwitchManager.class).setCallbacks("setSwitchManager",
130                    "unsetSwitchManager").setRequired(false));
131         }
132     }
133 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.