2549dcbeb93b09879612d876ed61966092e0827a
[affinity.git] / l2agent / src / main / java / org / opendaylight / affinity / l2agent / 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.affinity.l2agent;
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.sal.core.ComponentActivatorAbstractBase;
19 import org.opendaylight.controller.sal.packet.IListenDataPacket;
20 import org.opendaylight.controller.sal.packet.IDataPacketService;
21 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
22 import org.opendaylight.controller.switchmanager.ISwitchManager;
23
24 public class Activator extends ComponentActivatorAbstractBase {
25     protected static final Logger logger = LoggerFactory
26             .getLogger(Activator.class);
27
28     /**
29      * Function called when the activator starts just after some
30      * initializations are done by the
31      * ComponentActivatorAbstractBase.
32      *
33      */
34     public void init() {
35
36     }
37
38     /**
39      * Function called when the activator stops just before the
40      * cleanup done by ComponentActivatorAbstractBase
41      *
42      */
43     public void destroy() {
44
45     }
46
47     /**
48      * Function that is used to communicate to dependency manager the
49      * list of known implementations for services inside a container
50      *
51      *
52      * @return An array containing all the CLASS objects that will be
53      * instantiated in order to get an fully working implementation
54      * Object
55      */
56     public Object[] getImplementations() {
57         Object[] res = { L2Agent.class };
58         return res;
59     }
60
61     /**
62      * Function that is called when configuration of the dependencies
63      * is required.
64      *
65      * @param c dependency manager Component object, used for
66      * configuring the dependencies exported and imported
67      * @param imp Implementation class that is being configured,
68      * needed as long as the same routine can configure multiple
69      * implementations
70      * @param containerName The containerName being configured, this allow
71      * also optional per-container different behavior if needed, usually
72      * should not be the case though.
73      */
74     public void configureInstance(Component c, Object imp, String containerName) {
75         if (imp.equals(L2Agent.class)) {
76             // export the services
77             Dictionary<String, String> props = new Hashtable<String, String>();
78             props.put("salListenerName", "L2Agent");
79             c.setInterface(new String[] { IListenDataPacket.class.getName(),                    
80                                           IfL2Agent.class.getName() }, props);
81
82             // register dependent modules
83             c.add(createContainerServiceDependency(containerName).setService(
84                     ISwitchManager.class).setCallbacks("setSwitchManager",
85                     "unsetSwitchManager").setRequired(true));
86
87             c.add(createContainerServiceDependency(containerName).setService(
88                     IDataPacketService.class).setCallbacks(
89                     "setDataPacketService", "unsetDataPacketService")
90                     .setRequired(true));
91
92             c.add(createContainerServiceDependency(containerName).setService(
93                     IFlowProgrammerService.class).setCallbacks(
94                     "setFlowProgrammerService", "unsetFlowProgrammerService")
95                     .setRequired(true));
96         }
97     }
98 }