Merge "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     @Override
44     public void init() {
45         Node.NodeIDType.registerIDType("STUB", Integer.class);
46         NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class, "STUB");
47     }
48
49     /**
50      * Function called when the activator stops just before the cleanup done by
51      * ComponentActivatorAbstractBase
52      *
53      */
54     @Override
55     public void destroy() {
56         Node.NodeIDType.unRegisterIDType("STUB");
57         NodeConnector.NodeConnectorIDType.unRegisterIDType("STUB");
58     }
59
60     /**
61      * Function that is used to communicate to dependency manager the list of
62      * known implementations for services inside a container
63      *
64      *
65      * @return An array containing all the CLASS objects that will be
66      *         instantiated in order to get an fully working implementation
67      *         Object
68      */
69     @Override
70     public Object[] getImplementations() {
71         Object[] res = { ReadService.class, InventoryService.class };
72         return res;
73     }
74
75     /**
76      * Function that is called when configuration of the dependencies is
77      * required.
78      *
79      * @param c
80      *            dependency manager Component object, used for configuring the
81      *            dependencies exported and imported
82      * @param imp
83      *            Implementation class that is being configured, needed as long
84      *            as the same routine can configure multiple implementations
85      * @param containerName
86      *            The containerName being configured, this allow also optional
87      *            per-container different behavior if needed, usually should not
88      *            be the case though.
89      */
90     @Override
91     public void configureInstance(Component c, Object imp, String containerName) {
92         if (imp.equals(ReadService.class)) {
93             // export the service to be used by SAL
94             Dictionary<String, Object> props = new Hashtable<String, Object>();
95             // Set the protocolPluginType property which will be used
96             // by SAL
97             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
98             c.setInterface(IPluginInReadService.class.getName(), props);
99         }
100
101         if (imp.equals(InventoryService.class)) {
102             // export the service to be used by SAL
103             Dictionary<String, Object> props = new Hashtable<String, Object>();
104             // Set the protocolPluginType property which will be used
105             // by SAL
106             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
107             c.setInterface(IPluginInInventoryService.class.getName(), props);
108         }
109     }
110
111     @Override
112     public Object[] getGlobalImplementations() {
113         Object[] res =
114                 {
115                         FlowProgrammerService.class,
116                         StubNodeFactory.class,
117                         StubNodeConnectorFactory.class,
118                         InventoryService.class };
119         return res;
120     }
121
122     @Override
123     public void configureGlobalInstance(Component c, Object imp){
124         if (imp.equals(FlowProgrammerService.class)) {
125             // export the service to be used by SAL
126             Dictionary<String, Object> props = new Hashtable<String, Object>();
127             // Set the protocolPluginType property which will be used
128             // by SAL
129             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
130             c.setInterface(IPluginInFlowProgrammerService.class.getName(), props);
131         }
132         if (imp.equals(StubNodeFactory.class)) {
133             // export the service to be used by SAL
134             Dictionary<String, Object> props = new Hashtable<String, Object>();
135             // Set the protocolPluginType property which will be used
136             // by SAL
137             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
138             props.put("protocolName", "STUB");
139             c.setInterface(INodeFactory.class.getName(), props);
140         }
141         if (imp.equals(StubNodeConnectorFactory.class)) {
142             // export the service to be used by SAL
143             Dictionary<String, Object> props = new Hashtable<String, Object>();
144             // Set the protocolPluginType property which will be used
145             // by SAL
146             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
147             props.put("protocolName", "STUB");
148             c.setInterface(INodeConnectorFactory.class.getName(), props);
149         }
150         if (imp.equals(InventoryService.class)) {
151             // export the service to be used by SAL
152             Dictionary<String, Object> props = new Hashtable<String, Object>();
153             // Set the protocolPluginType property which will be used
154             // by SAL
155             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
156             props.put("scope", "Global");
157             c.setInterface(IPluginInInventoryService.class.getName(), props);
158             c.add(createServiceDependency().setService(IPluginOutInventoryService.class, "(scope=Global)")
159                     .setCallbacks("setPluginOutInventoryServices", "unsetPluginOutInventoryServices")
160                     .setRequired(true));
161         }
162     }
163 }