X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Finternal%2FInventoryService.java;h=f983e1244dba519f7a2afc0c6d13f8937f1178bc;hb=dfa4383b0b5c9c6de340526a62aef731922fa29f;hp=4869a9500b489ca58c1eaf72359fb8aaeb72cd12;hpb=7c3362df780f30a47d0f6a7b7695360bbb5513bc;p=controller.git diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java index 4869a9500b..f983e1244d 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java @@ -8,8 +8,6 @@ package org.opendaylight.controller.protocol_plugin.openflow.internal; -import java.util.Collections; -import java.util.Date; import java.util.Dictionary; import java.util.HashMap; import java.util.HashSet; @@ -17,15 +15,14 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.CopyOnWriteArraySet; import org.apache.felix.dm.Component; import org.opendaylight.controller.protocol_plugin.openflow.IInventoryProvider; import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener; import org.opendaylight.controller.protocol_plugin.openflow.core.IController; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.opendaylight.controller.sal.core.ConstructionException; import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.Node.NodeIDType; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.core.Property; import org.opendaylight.controller.sal.core.UpdateType; @@ -47,11 +44,11 @@ public class InventoryService implements IInventoryShimInternalListener, IPluginInInventoryService, IInventoryProvider { protected static final Logger logger = LoggerFactory .getLogger(InventoryService.class); - private Set pluginOutInventoryServices = Collections - .synchronizedSet(new HashSet()); + private final Set pluginOutInventoryServices = + new CopyOnWriteArraySet(); private IController controller = null; - private ConcurrentMap> nodeProps; // properties are maintained in global container only - private ConcurrentMap> nodeConnectorProps; // properties are maintained in global container only + private ConcurrentMap> nodeProps; + private ConcurrentMap> nodeConnectorProps; private boolean isDefaultContainer = false; private String containerName = null; @@ -77,8 +74,10 @@ public class InventoryService implements IInventoryShimInternalListener, Dictionary props = c.getServiceProperties(); if (props != null) { containerName = (String) props.get("containerName"); - isDefaultContainer = containerName.equals(GlobalConstants.DEFAULT - .toString()); + if (containerName != null) { + isDefaultContainer = containerName.equals(GlobalConstants.DEFAULT + .toString()); + } } nodeProps = new ConcurrentHashMap>(); @@ -112,6 +111,7 @@ public class InventoryService implements IInventoryShimInternalListener, */ void stop() { logger.trace("STOP called!"); + pluginOutInventoryServices.clear(); } public void setPluginOutInventoryServices(IPluginOutInventoryService service) { @@ -129,19 +129,6 @@ public class InventoryService implements IInventoryShimInternalListener, } } - protected Node OFSwitchToNode(ISwitch sw) { - Node node = null; - Object id = sw.getId(); - - try { - node = new Node(NodeIDType.OPENFLOW, id); - } catch (ConstructionException e) { - logger.error("", e); - } - - return node; - } - /** * Retrieve nodes from openflow */ @@ -206,11 +193,10 @@ public class InventoryService implements IInventoryShimInternalListener, } // update sal and discovery - synchronized (pluginOutInventoryServices) { - for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNodeConnector(nodeConnector, type, props); - } + for (IPluginOutInventoryService service : pluginOutInventoryServices) { + service.updateNodeConnector(nodeConnector, type, props); } + } private void addNode(Node node, Set props) { @@ -218,13 +204,6 @@ public class InventoryService implements IInventoryShimInternalListener, return; } - Set nodeSet = nodeProps.keySet(); - if (((props == null) || props.isEmpty()) && (nodeSet != null) - && nodeSet.contains(node)) { - // node already added - return; - } - logger.trace("addNode: {} added, props: {} for container {}", new Object[] { node, props, containerName }); @@ -242,17 +221,16 @@ public class InventoryService implements IInventoryShimInternalListener, nodeProps.put(node, propMap); // update sal - synchronized (pluginOutInventoryServices) { - for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNode(node, UpdateType.ADDED, props); - } + for (IPluginOutInventoryService service : pluginOutInventoryServices) { + service.updateNode(node, UpdateType.ADDED, props); } } private void removeNode(Node node) { logger.trace("{} removed", node); - if (nodeProps == null) + if (nodeProps == null) { return; + } // update local cache nodeProps.remove(node); @@ -268,17 +246,15 @@ public class InventoryService implements IInventoryShimInternalListener, } // update sal - synchronized (pluginOutInventoryServices) { - for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNode(node, UpdateType.REMOVED, null); - } + for (IPluginOutInventoryService service : pluginOutInventoryServices) { + service.updateNode(node, UpdateType.REMOVED, null); } } private void updateNode(Node node, Set properties) { logger.trace("{} updated, props: {}", node, properties); - if (nodeProps == null || !nodeProps.containsKey(node) || - properties == null || properties.isEmpty()) { + if ((nodeProps == null) || !nodeProps.containsKey(node) || + (properties == null) || properties.isEmpty()) { return; } @@ -296,10 +272,8 @@ public class InventoryService implements IInventoryShimInternalListener, // Update SAL if we got new properties if (!newProperties.isEmpty()) { - synchronized (pluginOutInventoryServices) { - for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNode(node, UpdateType.CHANGED, newProperties); - } + for (IPluginOutInventoryService service : pluginOutInventoryServices) { + service.updateNode(node, UpdateType.CHANGED, newProperties); } } } @@ -320,5 +294,4 @@ public class InventoryService implements IInventoryShimInternalListener, break; } } - }