NodeFactory service 99/399/2
authorKalvin Hom <kahom@cisco.com>
Tue, 28 May 2013 23:41:12 +0000 (16:41 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 28 May 2013 23:47:45 +0000 (23:47 +0000)
Added INodeFactory interface in SAL to
handle creation of different Node types;

Node will use INodeFactory to create Nodes
that are not one of the preset types;

StubNodeFactory for plugin stub creates
Nodes of STUB type;

Change-Id: I727eb7e4eae8daacf732b0856f6d0cc1d55ba749
Signed-off-by: Kalvin Hom <kahom@cisco.com>
opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java
opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeFactory.java [new file with mode: 0644]
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeFactory.java [new file with mode: 0644]

index ff44fd44670d70a876d664ee89f096c90c3cca74..9c47b3b9839dec497ff8dc0d6a23d3e896aad35d 100644 (file)
@@ -7,6 +7,7 @@ import org.apache.felix.dm.Component;
 
 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
 import org.opendaylight.controller.sal.core.IContainerListener;
+import org.opendaylight.controller.sal.utils.INodeFactory;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.discovery.IDiscoveryService;
@@ -103,7 +104,7 @@ public class Activator extends ComponentActivatorAbstractBase {
     }
     
     public Object[] getGlobalImplementations() {
-        Object[] res = { FlowProgrammerService.class };
+        Object[] res = { FlowProgrammerService.class, StubNodeFactory.class };
         return res;
     }
     
@@ -116,5 +117,14 @@ public class Activator extends ComponentActivatorAbstractBase {
             props.put("protocolPluginType", "STUB");
             c.setInterface(IPluginInFlowProgrammerService.class.getName(), props);
         }
+        if (imp.equals(StubNodeFactory.class)) {
+            // export the service to be used by SAL
+            Dictionary<String, Object> props = new Hashtable<String, Object>();
+            // Set the protocolPluginType property which will be used
+            // by SAL
+            props.put("protocolPluginType", "STUB");
+            props.put("protocolName", "STUB");
+            c.setInterface(INodeFactory.class.getName(), props);
+        }
     }
 }
diff --git a/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeFactory.java b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeFactory.java
new file mode 100644 (file)
index 0000000..c2ce473
--- /dev/null
@@ -0,0 +1,48 @@
+package org.opendaylight.controller.protocol_plugins.stub.internal;
+
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.utils.INodeFactory;
+import org.opendaylight.controller.sal.core.Node;
+
+public class StubNodeFactory implements INodeFactory
+    {
+      void init() {
+      }
+
+      /**
+       * Function called by the dependency manager when at least one dependency
+       * become unsatisfied or when the component is shutting down because for
+       * example bundle is being stopped.
+       * 
+       */
+      void destroy() {
+      }
+
+      /**
+       * Function called by dependency manager after "init ()" is called and after
+       * the services provided by the class are registered in the service registry
+       * 
+       */
+      void start() {
+      }
+
+      /**
+       * Function called by the dependency manager before the services exported by
+       * the component are unregistered, this will be followed by a "destroy ()"
+       * calls
+       * 
+       */
+      void stop() {
+      }
+      
+      public Node fromString(String nodeId, String nodeType){
+          if(nodeType.equals("STUB"))
+              try{
+                  return new Node("STUB", Integer.parseInt(nodeId));
+              } catch(ConstructionException e)
+              {
+                  return null;
+              }
+          return null;
+      }
+}
index ea9d93bdb6f0774b2d5c72128648f4431c72b2a8..4c7f278209096e16c857f57c6f49d9da7ea94c9f 100644 (file)
@@ -30,6 +30,8 @@ import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlRootElement;
 
 import org.opendaylight.controller.sal.utils.HexEncode;
+import org.opendaylight.controller.sal.utils.INodeFactory;
+import org.opendaylight.controller.sal.utils.ServiceHelper;
 
 /**
  * Describe a generic network element in multiple SDNs technologies. A
@@ -437,9 +439,13 @@ public class Node implements Serializable {
                 return null;
             }
         } else {
-            // We need to lookup via OSGi service registry for an
-            // handler for this
+            //Use INodeFactory to create a Node of registered Node type.
+            //The protocol plugin being used depends on typeStr.
+            INodeFactory f = (INodeFactory) ServiceHelper
+                    .getGlobalInstance(INodeFactory.class, new Node(), "(protocolName="+typeStr+")");
+            if(f==null)
+                return null;
+            return f.fromString(IDStr, typeStr);
         }
-        return null;
     }
 }
diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeFactory.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeFactory.java
new file mode 100644 (file)
index 0000000..29ba7d6
--- /dev/null
@@ -0,0 +1,27 @@
+
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.sal.utils;
+
+import org.opendaylight.controller.sal.core.Node;
+
+/**
+ * @file   INodeFactory.java
+ *
+ * @brief  Define the interface to be called when looking up custom node types
+ *
+ */
+
+public interface INodeFactory {
+    /**
+     * Method to get custom node types from protocol plugins
+     *
+     */
+    public Node fromString(String nodeId, String nodeType);
+}