Return singleton empty collection instead of null in Read service code
[controller.git] / opendaylight / sal / implementation / src / main / java / org / opendaylight / controller / sal / implementation / internal / Activator.java
index b56a96e50cb8acc844f3419276bc4140a1ca34a0..98cb3b83ca6347a13e25c1c0674ca53f766a3848 100644 (file)
@@ -8,6 +8,9 @@
 
 package org.opendaylight.controller.sal.implementation.internal;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
+
 import org.apache.felix.dm.Component;
 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
@@ -23,7 +26,9 @@ import org.opendaylight.controller.sal.packet.IListenDataPacket;
 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
 import org.opendaylight.controller.sal.reader.IPluginInReadService;
+import org.opendaylight.controller.sal.reader.IPluginOutReadService;
 import org.opendaylight.controller.sal.reader.IReadService;
+import org.opendaylight.controller.sal.reader.IReadServiceListener;
 import org.opendaylight.controller.sal.topology.IListenTopoUpdates;
 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
@@ -35,24 +40,51 @@ public class Activator extends ComponentActivatorAbstractBase {
     protected static final Logger logger = LoggerFactory
             .getLogger(Activator.class);
 
+
     /**
-     * Function called when the activator starts just after some initializations
-     * are done by the ComponentActivatorAbstractBase.
+     * Function that is used to communicate to dependency manager the list of
+     * known Global implementations
      *
+     *
+     * @return An array containing all the CLASS objects that will be
+     *         instantiated in order to get an fully working implementation
+     *         Object
      */
-    @Override
-    public void init() {
-
+    public Object[] getGlobalImplementations() {
+        Object[] res = { Inventory.class };
+        return res;
     }
 
     /**
-     * Function called when the activator stops just before the cleanup done by
-     * ComponentActivatorAbstractBase
+     * Function that is called when configuration of the dependencies is required.
      *
+     * @param c
+     *            dependency manager Component object, used for configuring the
+     *            dependencies exported and imported
+     * @param imp
+     *            Implementation class that is being configured, needed as long
+     *            as the same routine can configure multiple implementations
      */
-    @Override
-    public void destroy() {
+    public void configureGlobalInstance(Component c, Object imp) {
+        if (imp.equals(Inventory.class)) {
+            Dictionary<String, Object> props = new Hashtable<String, Object>();
+            props.put("scope", "Global");
+            // export the service
+            c.setInterface(
+                    new String[] { IPluginOutInventoryService.class.getName(),
+                            IInventoryService.class.getName() }, props);
 
+            // Now lets add a service dependency to make sure the
+            // provider of service exists
+            c.add(createServiceDependency()
+                    .setService(IListenInventoryUpdates.class, "(scope=Global)")
+                    .setCallbacks("setUpdateService", "unsetUpdateService")
+                    .setRequired(false));
+            c.add(createServiceDependency()
+                    .setService(IPluginInInventoryService.class, "(scope=Global)")
+                    .setCallbacks("setPluginService", "unsetPluginService")
+                    .setRequired(false));
+        }
     }
 
     /**
@@ -145,14 +177,22 @@ public class Activator extends ComponentActivatorAbstractBase {
         }
 
         if (imp.equals(ReadService.class)) {
-            // It is the provider of IReadService
-            c.setInterface(IReadService.class.getName(), null);
+            // export services
+            c.setInterface(new String[] {
+                    IReadService.class.getName(),IPluginOutReadService.class.getName()}, null);
 
             // It is also the consumer of IPluginInReadService
             c.add(createContainerServiceDependency(containerName)
                     .setService(IPluginInReadService.class)
                     .setCallbacks("setService", "unsetService")
-                    .setRequired(true));
+                    .setRequired(false));
+
+            //consumes plugins' reader updates
+            c.add(createContainerServiceDependency(containerName)
+                    .setService(IReadServiceListener.class)
+                    .setCallbacks("setReaderListener", "unsetReaderListener")
+                    .setRequired(false));
+
         }
 
         /************************/