Integration of MDSAL into distribution
[controller.git] / opendaylight / protocol_plugins / stub / src / main / java / org / opendaylight / controller / protocol_plugins / stub / internal / Activator.java
1 package org.opendaylight.controller.protocol_plugins.stub.internal;
2
3 import java.util.Dictionary;
4 import java.util.Hashtable;
5
6 import org.apache.felix.dm.Component;
7
8 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
9 import org.opendaylight.controller.sal.core.IContainerListener;
10 import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
11 import org.opendaylight.controller.sal.utils.INodeFactory;
12 import org.opendaylight.controller.sal.core.Node;
13 import org.opendaylight.controller.sal.core.NodeConnector;
14 import org.opendaylight.controller.sal.discovery.IDiscoveryService;
15 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
16 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
17 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
18 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
19 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
20 import org.opendaylight.controller.sal.reader.IPluginInReadService;
21 import org.opendaylight.controller.sal.reader.IReadService;
22 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
23 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
24 import org.opendaylight.controller.sal.utils.GlobalConstants;
25
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * stub protocol plugin Activator
31  *
32  *
33  */
34 public class Activator extends ComponentActivatorAbstractBase {
35     protected static final Logger logger = LoggerFactory
36             .getLogger(Activator.class);
37
38     /**
39      * Function called when the activator starts just after some initializations
40      * are done by the ComponentActivatorAbstractBase.
41      *
42      */
43     public void init() {
44         Node.NodeIDType.registerIDType("STUB", Integer.class);
45         NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class, "STUB");
46     }
47
48     /**
49      * Function called when the activator stops just before the cleanup done by
50      * ComponentActivatorAbstractBase
51      *
52      */
53     public void destroy() {
54         Node.NodeIDType.unRegisterIDType("STUB");
55         NodeConnector.NodeConnectorIDType.unRegisterIDType("STUB");
56     }
57
58     /**
59      * Function that is used to communicate to dependency manager the list of
60      * known implementations for services inside a container
61      *
62      *
63      * @return An array containing all the CLASS objects that will be
64      *         instantiated in order to get an fully working implementation
65      *         Object
66      */
67     public Object[] getImplementations() {
68         Object[] res = { ReadService.class, InventoryService.class };
69         return res;
70     }
71
72     /**
73      * Function that is called when configuration of the dependencies is
74      * required.
75      *
76      * @param c
77      *            dependency manager Component object, used for configuring the
78      *            dependencies exported and imported
79      * @param imp
80      *            Implementation class that is being configured, needed as long
81      *            as the same routine can configure multiple implementations
82      * @param containerName
83      *            The containerName being configured, this allow also optional
84      *            per-container different behavior if needed, usually should not
85      *            be the case though.
86      */
87     public void configureInstance(Component c, Object imp, String containerName) {
88         if (imp.equals(ReadService.class)) {
89             // export the service to be used by SAL
90             Dictionary<String, Object> props = new Hashtable<String, Object>();
91             // Set the protocolPluginType property which will be used
92             // by SAL
93             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
94             c.setInterface(IPluginInReadService.class.getName(), props);
95         }
96
97         if (imp.equals(InventoryService.class)) {
98             // export the service to be used by SAL
99             Dictionary<String, Object> props = new Hashtable<String, Object>();
100             // Set the protocolPluginType property which will be used
101             // by SAL
102             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
103             c.setInterface(IPluginInInventoryService.class.getName(), props);
104         }
105     }
106
107     public Object[] getGlobalImplementations() {
108         Object[] res = { FlowProgrammerService.class, StubNodeFactory.class, StubNodeConnectorFactory.class };
109         return res;
110     }
111
112     public void configureGlobalInstance(Component c, Object imp){
113         if (imp.equals(FlowProgrammerService.class)) {
114             // export the service to be used by SAL
115             Dictionary<String, Object> props = new Hashtable<String, Object>();
116             // Set the protocolPluginType property which will be used
117             // by SAL
118             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
119             c.setInterface(IPluginInFlowProgrammerService.class.getName(), props);
120         }
121         if (imp.equals(StubNodeFactory.class)) {
122             // export the service to be used by SAL
123             Dictionary<String, Object> props = new Hashtable<String, Object>();
124             // Set the protocolPluginType property which will be used
125             // by SAL
126             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
127             props.put("protocolName", "STUB");
128             c.setInterface(INodeFactory.class.getName(), props);
129         }
130         if (imp.equals(StubNodeConnectorFactory.class)) {
131             // export the service to be used by SAL
132             Dictionary<String, Object> props = new Hashtable<String, Object>();
133             // Set the protocolPluginType property which will be used
134             // by SAL
135             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
136             props.put("protocolName", "STUB");
137             c.setInterface(INodeConnectorFactory.class.getName(), props);
138         }
139
140     }
141 }