Fix for bug 278 Replace implementation of dbCache in InventoryService with a Concurre...
authorDave Tucker <dave.j.tucker@hp.com>
Thu, 23 Jan 2014 06:28:16 +0000 (06:28 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 25 Jan 2014 01:12:04 +0000 (01:12 +0000)
Change-Id: I95549730117d5ce330524cb63098e2e931c61a29
Signed-off-by: Dave Tucker <dave.j.tucker@hp.com>
neutron/src/main/java/org/opendaylight/ovsdb/neutron/SouthboundHandler.java
neutron/src/test/java/org/opendaylight/ovsdb/neutron/AdminConfigManagerTest.java
ovsdb/src/main/java/org/opendaylight/ovsdb/plugin/ConfigurationService.java
ovsdb/src/main/java/org/opendaylight/ovsdb/plugin/InventoryService.java
ovsdb/src/main/java/org/opendaylight/ovsdb/plugin/InventoryServiceInternal.java
ovsdb/src/main/java/org/opendaylight/ovsdb/plugin/NodeDB.java
ovsdb/src/main/java/org/opendaylight/ovsdb/plugin/OVSDBConfigService.java

index 3e4c4187977a31461fe411120636b71bb84af25f..7f38f7a7413bb869d152a0c9362cba78ba7286b9 100644 (file)
@@ -12,8 +12,9 @@ package org.opendaylight.ovsdb.neutron;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.Executors;
 import java.util.concurrent.LinkedBlockingQueue;
 
@@ -194,7 +195,7 @@ public class SouthboundHandler extends BaseHandler implements OVSDBInventoryList
         } else if (Open_vSwitch.NAME.getName().equalsIgnoreCase(tableName)) {
             logger.debug("{} Added / Updated {} , {}, {}", tableName, node, uuid, row);
             try {
-                Map<String, Table<?>> interfaces = this.ovsdbConfigService.getRows(node, Interface.NAME.getName());
+                ConcurrentMap<String, Table<?>> interfaces = this.ovsdbConfigService.getRows(node, Interface.NAME.getName());
                 if (interfaces != null) {
                     for (String intfUUID : interfaces.keySet()) {
                         Interface intf = (Interface) interfaces.get(intfUUID);
index 255caffc2fa226baec727c390c26a635bd4a6c39..9baf80499eaa96476d7c87ba8b6dc05ca523a094 100644 (file)
@@ -20,8 +20,8 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -46,7 +46,7 @@ public class AdminConfigManagerTest {
 
         Node mockNode = mock(Node.class);
 
-        Map<String, Table<?>> ovsMap = new HashMap<String, Table<?>>();
+        ConcurrentMap<String, Table<?>> ovsMap = new ConcurrentHashMap<>();
 
         Open_vSwitch ovsTable = new Open_vSwitch();
         OvsDBMap localIp = new OvsDBMap();
@@ -74,7 +74,7 @@ public class AdminConfigManagerTest {
 
         Node mockNode = mock(Node.class);
 
-        Map<String, Table<?>> ovsMap = new HashMap<String, Table<?>>();
+        ConcurrentMap<String, Table<?>> ovsMap = new ConcurrentHashMap<>();
 
         Open_vSwitch nullRow = new Open_vSwitch();
         Open_vSwitch ovsRow1 = new Open_vSwitch();
index 8cf648ca9f802c75c5adc5029fc0fab5ceba93a0..efca4a4d9de175de79e7fe183ec760daf5e23e21 100644 (file)
@@ -18,6 +18,7 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
 
 import org.eclipse.osgi.framework.console.CommandInterpreter;
 import org.eclipse.osgi.framework.console.CommandProvider;
@@ -837,12 +838,12 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
     }
 
     @Override
-    public Map<String, Table<?>> getRows(Node node, String tableName) throws Exception{
+    public ConcurrentMap<String, Table<?>> getRows(Node node, String tableName) throws Exception{
         try{
             if (inventoryServiceInternal == null) {
                 throw new Exception("Inventory Service is Unavailable.");
             }
-            Map<String, Table<?>> ovsTable = inventoryServiceInternal.getTableCache(node, tableName);
+            ConcurrentMap<String, Table<?>> ovsTable = inventoryServiceInternal.getTableCache(node, tableName);
             return ovsTable;
         } catch(Exception e){
             throw new Exception("Unable to read table due to "+e.getMessage());
@@ -889,7 +890,7 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
 
     @Override
     public List<String> getTables(Node node) {
-        Map<String, Map<String, Table<?>>> cache  = inventoryServiceInternal.getCache(node);
+        ConcurrentMap<String, ConcurrentMap<String, Table<?>>> cache  = inventoryServiceInternal.getCache(node);
         if (cache == null) return null;
         return new ArrayList<String>(cache.keySet());
     }
index 66a69a501d23ac6623ce32b3b396854dfe8a8156..17bfa81dfcb29829266d3f0dee11776f00a54f42 100644 (file)
@@ -56,7 +56,7 @@ public class InventoryService implements IPluginInInventoryService, InventorySer
             new CopyOnWriteArraySet<IPluginOutInventoryService>();
     private ConcurrentMap<Node, Map<String, Property>> nodeProps;
     private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps;
-    private Map<Node, NodeDB> dbCache = Maps.newHashMap();
+    private ConcurrentMap<Node, NodeDB> dbCache = Maps.newConcurrentMap();
     private ScheduledExecutorService executor;
 
     /**
@@ -126,7 +126,7 @@ public class InventoryService implements IPluginInInventoryService, InventorySer
 
 
     @Override
-    public Map<String, Map<String, Table<?>>> getCache(Node n) {
+    public ConcurrentMap<String, ConcurrentMap<String, Table<?>>> getCache(Node n) {
         NodeDB db = dbCache.get(n);
         if (db == null) return null;
         return db.getTableCache();
@@ -134,7 +134,7 @@ public class InventoryService implements IPluginInInventoryService, InventorySer
 
 
     @Override
-    public Map<String, Table<?>> getTableCache(Node n, String tableName) {
+    public ConcurrentMap<String, Table<?>> getTableCache(Node n, String tableName) {
         NodeDB db = dbCache.get(n);
         if (db == null) return null;
         return db.getTableCache(tableName);
index 482e36162f1e85f848eb3677e557395e54b5d74c..032427560e2cefcf439dc89a33f39c91dd999444 100644 (file)
@@ -9,8 +9,8 @@
  */
 package org.opendaylight.ovsdb.plugin;
 
-import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
 
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.Property;
@@ -21,8 +21,8 @@ import org.opendaylight.ovsdb.lib.message.TableUpdates;
 import org.opendaylight.ovsdb.lib.table.internal.Table;
 
 public interface InventoryServiceInternal extends IPluginInInventoryService {
-    public Map<String, Map<String, Table<?>>> getCache(Node n);
-    public Map<String, Table<?>> getTableCache(Node n, String tableName);
+    public ConcurrentMap<String, ConcurrentMap<String, Table<?>>> getCache(Node n);
+    public ConcurrentMap<String, Table<?>> getTableCache(Node n, String tableName);
     public Table<?> getRow (Node n, String tableName, String uuid);
     public void updateRow(Node n, String tableName, String uuid, Table<?> row);
     public void removeRow(Node n, String tableName, String uuid);
index aeb173de22fd98e4fecaeab1313a5d772a7a679a..912d0ee0d39d6ca67400c889a8237262e214f48b 100644 (file)
@@ -10,6 +10,7 @@
 package org.opendaylight.ovsdb.plugin;
 
 import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
 
 import com.google.common.collect.Maps;
 
@@ -19,7 +20,7 @@ import org.opendaylight.ovsdb.lib.table.internal.Table;
 
 public class NodeDB {
     private DatabaseSchema schema;
-    Map<String, Map<String, Table<?>>> cache = Maps.newHashMap();
+    ConcurrentMap<String, ConcurrentMap<String, Table<?>>> cache = Maps.newConcurrentMap();
 
     public DatabaseSchema getSchema() {
         return schema;
@@ -29,15 +30,15 @@ public class NodeDB {
         this.schema = schema;
     }
 
-    public Map<String, Map<String, Table<?>>> getTableCache() {
+    public ConcurrentMap<String, ConcurrentMap<String, Table<?>>> getTableCache() {
         return cache;
     }
 
-    public Map<String, Table<?>> getTableCache(String tableName) {
+    public ConcurrentMap<String, Table<?>> getTableCache(String tableName) {
         return cache.get(tableName);
     }
 
-    private void setTableCache(String tableName,  Map<String, Table<?>> tableCache) {
+    private void setTableCache(String tableName,  ConcurrentMap<String, Table<?>> tableCache) {
         cache.put(tableName, tableCache);
     }
 
@@ -50,9 +51,9 @@ public class NodeDB {
     }
 
     public void updateRow(String tableName, String uuid, Table<?> row) {
-        Map<String, Table<?>> tableCache = getTableCache(tableName);
+        ConcurrentMap<String, Table<?>> tableCache = getTableCache(tableName);
         if (tableCache == null) {
-            tableCache = Maps.newHashMap();
+            tableCache = Maps.newConcurrentMap();
             setTableCache(tableName, tableCache);
         }
         tableCache.put(uuid, row);
index 281bed7b95f80480f4568cf2eb0a82996bc03b2a..5deeaeaaf9a4023fd9fba0ae95a7b31c19affd50 100644 (file)
@@ -10,7 +10,7 @@
 package org.opendaylight.ovsdb.plugin;
 
 import java.util.List;
-import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
 
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.utils.Status;
@@ -23,6 +23,6 @@ public interface OVSDBConfigService {
     public String getSerializedRow(Node node, String tableName, String uuid) throws Exception;
     public String getSerializedRows(Node node, String tableName) throws Exception;
     public Table<?> getRow(Node node, String tableName, String uuid) throws Exception;
-    public Map<String, Table<?>> getRows(Node node, String tableName) throws Exception;
+    public ConcurrentMap<String, Table<?>> getRows(Node node, String tableName) throws Exception;
     public List<String> getTables(Node node) throws Exception;
 }