Enhancing GroupChecker for faster processing of group updates

Change-Id: I9344ccf0ffbc9cff206318a627f5d97df1091677
diff --git a/drivers/default/src/main/java/org/onosproject/driver/pipeline/ofdpa/Ofdpa2GroupHandler.java b/drivers/default/src/main/java/org/onosproject/driver/pipeline/ofdpa/Ofdpa2GroupHandler.java
index 2c2f3ba..40aad0d 100644
--- a/drivers/default/src/main/java/org/onosproject/driver/pipeline/ofdpa/Ofdpa2GroupHandler.java
+++ b/drivers/default/src/main/java/org/onosproject/driver/pipeline/ofdpa/Ofdpa2GroupHandler.java
@@ -106,10 +106,10 @@
     private AtomicCounter nextIndex;
 
     protected DeviceId deviceId;
-    private Cache<GroupKey, List<OfdpaGroupHandlerUtility.OfdpaNextGroup>> pendingAddNextObjectives;
-    private Cache<NextObjective, List<GroupKey>> pendingRemoveNextObjectives;
-    private Cache<GroupKey, Set<OfdpaGroupHandlerUtility.GroupChainElem>> pendingGroups;
-    private ConcurrentHashMap<GroupKey, Set<NextObjective>> pendingUpdateNextObjectives;
+    Cache<GroupKey, List<OfdpaGroupHandlerUtility.OfdpaNextGroup>> pendingAddNextObjectives;
+    Cache<NextObjective, List<GroupKey>> pendingRemoveNextObjectives;
+    Cache<GroupKey, Set<OfdpaGroupHandlerUtility.GroupChainElem>> pendingGroups;
+    ConcurrentHashMap<GroupKey, Set<NextObjective>> pendingUpdateNextObjectives;
 
     // local store for pending bucketAdds - by design there can be multiple
     // pending bucket for a group
@@ -119,14 +119,6 @@
     private ScheduledExecutorService groupCheckerExecutor =
             Executors.newScheduledThreadPool(2, groupedThreads("onos/pipeliner", "ofdpa-%d", log));
 
-    public Cache<GroupKey, List<OfdpaNextGroup>> pendingAddNextObjectives() {
-        return pendingAddNextObjectives;
-    }
-
-    public Cache<GroupKey, Set<GroupChainElem>> pendingGroups() {
-        return pendingGroups;
-    }
-
     /**
      * Determines whether this pipeline support copy ttl instructions or not.
      *
@@ -1849,22 +1841,27 @@
         });
     }
 
-    private void processPendingUpdateNextObjs(GroupKey groupKey) {
-        pendingUpdateNextObjectives.compute(groupKey, (gKey, nextObjs) -> {
-            if (nextObjs != null) {
-
-                nextObjs.forEach(nextObj -> {
-                    log.debug("Group {} updated, update pending next objective {}.",
-                              groupKey, nextObj);
-
-                    pass(nextObj);
-                });
-            }
-            return Sets.newHashSet();
-        });
+    protected void addPendingRemoveNextObjective(NextObjective nextObjective,
+                                                 List<GroupKey> groupKeys) {
+        pendingRemoveNextObjectives.put(nextObjective, groupKeys);
     }
 
-    private void processPendingRemoveNextObjs(GroupKey key) {
+    protected int getNextAvailableIndex() {
+        return (int) nextIndex.incrementAndGet();
+    }
+
+    protected void processPendingUpdateNextObjs(GroupKey groupKey) {
+        Set<NextObjective> nextObjs = pendingUpdateNextObjectives.remove(groupKey);
+        if (nextObjs != null) {
+            nextObjs.forEach(nextObj -> {
+                log.debug("Group {} updated, update pending next objective {}.",
+                          groupKey, nextObj);
+                pass(nextObj);
+            });
+        }
+    }
+
+    protected void processPendingRemoveNextObjs(GroupKey key) {
         pendingRemoveNextObjectives.asMap().forEach((nextObjective, groupKeys) -> {
             if (groupKeys.isEmpty()) {
                 pendingRemoveNextObjectives.invalidate(nextObjective);
@@ -1875,10 +1872,6 @@
         });
     }
 
-    protected int getNextAvailableIndex() {
-        return (int) nextIndex.incrementAndGet();
-    }
-
     protected void processPendingAddGroupsOrNextObjs(GroupKey key, boolean added) {
         //first check for group chain
         Set<OfdpaGroupHandlerUtility.GroupChainElem> gceSet = pendingGroups.asMap().remove(key);
@@ -1951,11 +1944,6 @@
         }
     }
 
-    protected void addPendingRemoveNextObjective(NextObjective nextObjective,
-                                                 List<GroupKey> groupKeys) {
-        pendingRemoveNextObjectives.put(nextObjective, groupKeys);
-    }
-
     private void updateFlowObjectiveStore(Integer nextId, OfdpaNextGroup nextGrp) {
         synchronized (flowObjectiveStore) {
             // get fresh copy of what the store holds