Merge "Fixed Group and meter id bugs"
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / InventoryService.java
index 6e6cb00f899d13a94188f7c76c439a68b331f573..39bbecf0214f5443e1991ba359a679bbc6cba183 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.controller.protocol_plugin.openflow.internal;
 
+import java.util.Collections;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -44,10 +45,11 @@ public class InventoryService implements IInventoryShimInternalListener,
         IPluginInInventoryService, IInventoryProvider {
     protected static final Logger logger = LoggerFactory
             .getLogger(InventoryService.class);
-    private Set<IPluginOutInventoryService> pluginOutInventoryServices;
+    private final Set<IPluginOutInventoryService> pluginOutInventoryServices =
+            new CopyOnWriteArraySet<IPluginOutInventoryService>();
     private IController controller = null;
-    private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties are maintained in global container only
-    private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties are maintained in global container only
+    private ConcurrentMap<Node, Map<String, Property>> nodeProps;
+    private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps;
     private boolean isDefaultContainer = false;
     private String containerName = null;
 
@@ -73,13 +75,14 @@ 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<Node, Map<String, Property>>();
         nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
-        pluginOutInventoryServices = new CopyOnWriteArraySet<IPluginOutInventoryService>();
     }
 
     /**
@@ -109,6 +112,7 @@ public class InventoryService implements IInventoryShimInternalListener,
      */
     void stop() {
         logger.trace("STOP called!");
+        pluginOutInventoryServices.clear();
     }
 
     public void setPluginOutInventoryServices(IPluginOutInventoryService service) {
@@ -135,6 +139,12 @@ public class InventoryService implements IInventoryShimInternalListener,
         return nodeProps;
     }
 
+    // nothing to return
+    @Override
+    public Set<Node> getConfiguredNotConnectedNodes() {
+        return Collections.emptySet();
+    }
+
     @Override
     public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps(
             Boolean refresh) {
@@ -201,13 +211,6 @@ public class InventoryService implements IInventoryShimInternalListener,
             return;
         }
 
-        Set<Node> 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 });
 
@@ -232,8 +235,9 @@ public class InventoryService implements IInventoryShimInternalListener,
 
     private void removeNode(Node node) {
         logger.trace("{} removed", node);
-        if (nodeProps == null)
+        if (nodeProps == null) {
             return;
+        }
 
         // update local cache
         nodeProps.remove(node);
@@ -256,8 +260,8 @@ public class InventoryService implements IInventoryShimInternalListener,
 
     private void updateNode(Node node, Set<Property> 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;
         }
 
@@ -297,5 +301,4 @@ public class InventoryService implements IInventoryShimInternalListener,
             break;
         }
     }
-
 }