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