From: Kalvin Hom Date: Wed, 29 May 2013 19:18:06 +0000 (-0700) Subject: NodeConnector custom type X-Git-Tag: releasepom-0.1.0~408^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=46a70492ef6227caa6a4494e1ca9a209e5e1d449 NodeConnector custom type Changes for NodeConnector to create new NodeConnector of custom type; Created STUB implementation for protocol plugin; Reordered NodeFactory's arguments to be consistent with other methods; Change-Id: I7608005985f6f61f54d4339290191574ea6450c6 Signed-off-by: Kalvin Hom --- diff --git a/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java index 9c47b3b983..8e4c985c06 100644 --- a/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java +++ b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java @@ -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.INodeConnectorFactory; import org.opendaylight.controller.sal.utils.INodeFactory; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; @@ -104,7 +105,7 @@ public class Activator extends ComponentActivatorAbstractBase { } public Object[] getGlobalImplementations() { - Object[] res = { FlowProgrammerService.class, StubNodeFactory.class }; + Object[] res = { FlowProgrammerService.class, StubNodeFactory.class, StubNodeConnectorFactory.class }; return res; } @@ -126,5 +127,15 @@ public class Activator extends ComponentActivatorAbstractBase { props.put("protocolName", "STUB"); c.setInterface(INodeFactory.class.getName(), props); } + if (imp.equals(StubNodeConnectorFactory.class)) { + // export the service to be used by SAL + Dictionary props = new Hashtable(); + // Set the protocolPluginType property which will be used + // by SAL + props.put("protocolPluginType", "STUB"); + props.put("protocolName", "STUB"); + c.setInterface(INodeConnectorFactory.class.getName(), props); + } + } } diff --git a/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeConnectorFactory.java b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeConnectorFactory.java new file mode 100644 index 0000000000..0c1963d933 --- /dev/null +++ b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/StubNodeConnectorFactory.java @@ -0,0 +1,49 @@ +package org.opendaylight.controller.protocol_plugins.stub.internal; + +import org.opendaylight.controller.sal.core.NodeConnector; +import org.opendaylight.controller.sal.utils.INodeConnectorFactory; +import org.opendaylight.controller.sal.core.Node; + +public class StubNodeConnectorFactory implements INodeConnectorFactory + { + 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 NodeConnector fromStringNoNode(String typeStr, String IDStr, + Node n){ + if(typeStr.equals("STUB")){ + try { + return new NodeConnector(typeStr, Integer.parseInt(IDStr), n); + } catch (Exception ex) { + return null; + } + } + return null; + } +} 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 index c2ce473303..5b8ee12e56 100644 --- 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 @@ -35,7 +35,7 @@ public class StubNodeFactory implements INodeFactory void stop() { } - public Node fromString(String nodeId, String nodeType){ + public Node fromString(String nodeType, String nodeId){ if(nodeType.equals("STUB")) try{ return new Node("STUB", Integer.parseInt(nodeId)); diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java index 4c7f278209..ef0c0667aa 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java @@ -445,7 +445,7 @@ public class Node implements Serializable { .getGlobalInstance(INodeFactory.class, new Node(), "(protocolName="+typeStr+")"); if(f==null) return null; - return f.fromString(IDStr, typeStr); + return f.fromString(typeStr, IDStr); } } } diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/NodeConnector.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/NodeConnector.java index 495af7970c..9c49a31508 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/NodeConnector.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/NodeConnector.java @@ -28,6 +28,9 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import org.apache.commons.lang3.tuple.ImmutablePair; +import org.opendaylight.controller.sal.utils.INodeConnectorFactory; +import org.opendaylight.controller.sal.utils.INodeFactory; +import org.opendaylight.controller.sal.utils.ServiceHelper; /** * Describe a generic network element attachment points, @@ -602,8 +605,13 @@ public class NodeConnector implements Serializable { return null; } } else { - // Lookup via OSGi service registry + //Use INodeConnectorFactory to create a NodeConnector of registered type. + //The protocol plugin being used depends on typeStr. + INodeConnectorFactory f = (INodeConnectorFactory) ServiceHelper + .getGlobalInstance(INodeConnectorFactory.class, new NodeConnector(), "(protocolName="+typeStr+")"); + if(f==null) + return null; + return f.fromStringNoNode(typeStr, IDStr, n); } - return null; } } diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeConnectorFactory.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeConnectorFactory.java new file mode 100644 index 0000000000..317976dc3e --- /dev/null +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/INodeConnectorFactory.java @@ -0,0 +1,29 @@ + +/* + * 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; +import org.opendaylight.controller.sal.core.NodeConnector; + +/** + * @file INodeFactory.java + * + * @brief Define the interface to be called when looking up custom node types + * + */ + +public interface INodeConnectorFactory { + /** + * Method to get custom NodeConnector types from protocol plugins + * + */ + public NodeConnector fromStringNoNode(String typeStr, String IDStr, + Node n); +} 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 index 29ba7d6222..dce6eb03f6 100644 --- 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 @@ -23,5 +23,5 @@ public interface INodeFactory { * Method to get custom node types from protocol plugins * */ - public Node fromString(String nodeId, String nodeType); + public Node fromString(String nodeType, String nodeId); }