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.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
20 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
21 import org.opendaylight.controller.hosttracker.IfIptoHost;
22 import org.opendaylight.controller.hosttracker.IfNewHostNotify;
23 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
24 import org.opendaylight.controller.sal.packet.IDataPacketService;
25 import org.opendaylight.controller.sal.packet.IListenDataPacket;
26 import org.opendaylight.controller.sal.routing.IListenRoutingUpdates;
27 import org.opendaylight.controller.sal.routing.IRouting;
28 import org.opendaylight.controller.samples.simpleforwarding.IBroadcastHandler;
29 import org.opendaylight.controller.samples.simpleforwarding.IBroadcastPortSelector;
30 import org.opendaylight.controller.switchmanager.IInventoryListener;
31 import org.opendaylight.controller.switchmanager.ISwitchManager;
32 import org.opendaylight.controller.topologymanager.ITopologyManager;
33
34 public class Activator extends ComponentActivatorAbstractBase {
35     protected static final Logger logger = LoggerFactory
36             .getLogger(Activator.class);
37
38
39     /**
40      * Function that is used to communicate to dependency manager the
41      * list of known implementations for services inside a container
42      *
43      *
44      * @return An array containing all the CLASS objects that will be
45      * instantiated in order to get an fully working implementation
46      * Object
47      */
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     public void configureInstance(Component c, Object imp, String containerName) {
68         if (imp.equals(SimpleForwardingImpl.class)) {
69             // export the service
70             c.setInterface(new String[] { IInventoryListener.class.getName(),
71                     IfNewHostNotify.class.getName(),
72                     IListenRoutingUpdates.class.getName() }, null);
73
74             c.add(createContainerServiceDependency(containerName).setService(
75                     IClusterContainerServices.class).setCallbacks(
76                     "setClusterContainerService",
77                     "unsetClusterContainerService").setRequired(true));
78
79             c.add(createContainerServiceDependency(containerName).setService(
80                     ISwitchManager.class).setCallbacks("setSwitchManager",
81                     "unsetSwitchManager").setRequired(false));
82
83             c.add(createContainerServiceDependency(containerName).setService(
84                     IfIptoHost.class).setCallbacks("setHostTracker",
85                     "unsetHostTracker").setRequired(false));
86
87             c.add(createContainerServiceDependency(containerName).setService(
88                     IForwardingRulesManager.class).setCallbacks(
89                     "setForwardingRulesManager", "unsetForwardingRulesManager")
90                     .setRequired(false));
91
92             c.add(createContainerServiceDependency(containerName).setService(
93                     ITopologyManager.class).setCallbacks("setTopologyManager",
94                     "unsetTopologyManager").setRequired(false));
95
96             c.add(createContainerServiceDependency(containerName).setService(
97                     IRouting.class).setCallbacks("setRouting", "unsetRouting")
98                     .setRequired(false));
99         }else if (imp.equals(SimpleBroadcastHandlerImpl.class)) {
100             Dictionary<String, String> props = new Hashtable<String, String>();
101             props.put("salListenerName", "simplebroadcasthandler");
102
103             // export the service
104             c.setInterface(new String[] { IBroadcastHandler.class.getName(),
105                     IListenDataPacket.class.getName() }, props);
106
107             c.add(createContainerServiceDependency(containerName).setService(
108                     IDataPacketService.class).setCallbacks("setDataPacketService",
109                    "unsetDataPacketService").setRequired(false));
110
111             c.add(createContainerServiceDependency(containerName).setService(
112                    ITopologyManager.class).setCallbacks("setTopologyManager",
113                    "unsetTopologyManager").setRequired(true));
114
115             c.add(createContainerServiceDependency(containerName).setService(
116                    IBroadcastPortSelector.class).setCallbacks("setBroadcastPortSelector",
117                    "unsetBroadcastPortSelector").setRequired(false));
118
119             c.add(createContainerServiceDependency(containerName).setService(
120                    ISwitchManager.class).setCallbacks("setSwitchManager",
121                    "unsetSwitchManager").setRequired(false));
122         }
123     }
124 }

©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.