Merge "Bug 1029: Remove dead code: samples/clustersession"
[controller.git] / opendaylight / adsal / protocol_plugins / stub / src / main / java / org / opendaylight / controller / protocol_plugins / stub / internal / Activator.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9
10
11
12 package org.opendaylight.controller.protocol_plugins.stub.internal;
13
14 import org.apache.felix.dm.Component;
15 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
16 import org.opendaylight.controller.sal.core.Node;
17 import org.opendaylight.controller.sal.core.NodeConnector;
18 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
19 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
20 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
21 import org.opendaylight.controller.sal.reader.IPluginInReadService;
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 import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
26 import org.opendaylight.controller.sal.utils.INodeFactory;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import java.util.Dictionary;
31 import java.util.Hashtable;
32
33 /**
34  * stub protocol plugin Activator
35  *
36  *
37  */
38 public class Activator extends ComponentActivatorAbstractBase {
39     protected static final Logger logger = LoggerFactory
40             .getLogger(Activator.class);
41
42     /**
43      * Function called when the activator starts just after some initializations
44      * are done by the ComponentActivatorAbstractBase.
45      *
46      */
47     @Override
48     public void init() {
49         Node.NodeIDType.registerIDType("STUB", Integer.class);
50         NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class, "STUB");
51     }
52
53     /**
54      * Function called when the activator stops just before the cleanup done by
55      * ComponentActivatorAbstractBase
56      *
57      */
58     @Override
59     public void destroy() {
60         Node.NodeIDType.unRegisterIDType("STUB");
61         NodeConnector.NodeConnectorIDType.unRegisterIDType("STUB");
62     }
63
64     /**
65      * Function that is used to communicate to dependency manager the list of
66      * known implementations for services inside a container
67      *
68      *
69      * @return An array containing all the CLASS objects that will be
70      *         instantiated in order to get an fully working implementation
71      *         Object
72      */
73     @Override
74     public Object[] getImplementations() {
75         Object[] res = { ReadService.class, InventoryService.class, TopologyServices.class };
76         return res;
77     }
78
79     /**
80      * Function that is called when configuration of the dependencies is
81      * required.
82      *
83      * @param c
84      *            dependency manager Component object, used for configuring the
85      *            dependencies exported and imported
86      * @param imp
87      *            Implementation class that is being configured, needed as long
88      *            as the same routine can configure multiple implementations
89      * @param containerName
90      *            The containerName being configured, this allow also optional
91      *            per-container different behavior if needed, usually should not
92      *            be the case though.
93      */
94     @Override
95     public void configureInstance(Component c, Object imp, String containerName) {
96         if (imp.equals(ReadService.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(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
102             c.setInterface(IPluginInReadService.class.getName(), props);
103         }
104
105         if (imp.equals(InventoryService.class)) {
106             // export the service to be used by SAL
107             Dictionary<String, Object> props = new Hashtable<String, Object>();
108             // Set the protocolPluginType property which will be used
109             // by SAL
110             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
111             c.setInterface(IPluginInInventoryService.class.getName(), props);
112         }
113
114         if(imp.equals(TopologyServices.class)){
115             Dictionary<String, Object> props = new Hashtable<String, Object>();
116             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
117             c.setInterface(IPluginInTopologyService.class.getName(), props);
118             c.add(createServiceDependency().setService(IPluginOutTopologyService.class, "")
119                     .setCallbacks("setPluginOutTopologyService", "unsetPluginOutTopologyService")
120                     .setRequired(true));
121
122         }
123
124     }
125
126     @Override
127     public Object[] getGlobalImplementations() {
128         Object[] res =
129                 {
130                         FlowProgrammerService.class,
131                         StubNodeFactory.class,
132                         StubNodeConnectorFactory.class,
133                         InventoryService.class
134                 };
135         return res;
136     }
137
138     @Override
139     public void configureGlobalInstance(Component c, Object imp){
140         if (imp.equals(FlowProgrammerService.class)) {
141             // export the service to be used by SAL
142             Dictionary<String, Object> props = new Hashtable<String, Object>();
143             // Set the protocolPluginType property which will be used
144             // by SAL
145             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
146             c.setInterface(IPluginInFlowProgrammerService.class.getName(), props);
147         }
148         if (imp.equals(StubNodeFactory.class)) {
149             // export the service to be used by SAL
150             Dictionary<String, Object> props = new Hashtable<String, Object>();
151             // Set the protocolPluginType property which will be used
152             // by SAL
153             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
154             props.put("protocolName", "STUB");
155             c.setInterface(INodeFactory.class.getName(), props);
156         }
157         if (imp.equals(StubNodeConnectorFactory.class)) {
158             // export the service to be used by SAL
159             Dictionary<String, Object> props = new Hashtable<String, Object>();
160             // Set the protocolPluginType property which will be used
161             // by SAL
162             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
163             props.put("protocolName", "STUB");
164             c.setInterface(INodeConnectorFactory.class.getName(), props);
165         }
166         if (imp.equals(InventoryService.class)) {
167             // export the service to be used by SAL
168             Dictionary<String, Object> props = new Hashtable<String, Object>();
169             // Set the protocolPluginType property which will be used
170             // by SAL
171             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "STUB");
172             props.put("scope", "Global");
173             c.setInterface(IPluginInInventoryService.class.getName(), props);
174             c.add(createServiceDependency().setService(IPluginOutInventoryService.class, "(scope=Global)")
175                     .setCallbacks("setPluginOutInventoryServices", "unsetPluginOutInventoryServices")
176                     .setRequired(true));
177         }
178
179     }
180 }