check if there are any stats remaining when removing

Change-Id: I6af100ff73d5f577f38901b8f0ec881e51253cc8

apply fix to distributed store

Change-Id: I829394e919aa79f10e01ac42904f5708b296cf51
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/statistic/impl/DistributedStatisticStore.java b/core/store/dist/src/main/java/org/onlab/onos/store/statistic/impl/DistributedStatisticStore.java
index 42fcf98..85cc66a 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/statistic/impl/DistributedStatisticStore.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/statistic/impl/DistributedStatisticStore.java
@@ -46,6 +46,7 @@
 import org.slf4j.Logger;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
@@ -153,8 +154,8 @@
             return;
         }
         InternalStatisticRepresentation rep = representations.get(cp);
-        if (rep != null) {
-            rep.remove(rule);
+        if (rep != null && rep.remove(rule)) {
+            updatePublishedStats(cp, Collections.emptySet());
         }
         Set<FlowEntry> values = current.get(cp);
         if (values != null) {
@@ -304,9 +305,9 @@
             counter.incrementAndGet();
         }
 
-        public synchronized void remove(FlowRule rule) {
+        public synchronized boolean remove(FlowRule rule) {
             rules.remove(rule);
-            counter.decrementAndGet();
+            return counter.decrementAndGet() == 0;
         }
 
         public synchronized boolean submit(FlowEntry rule) {
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleStatisticStore.java b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleStatisticStore.java
index 16577e8..d8bb32f 100644
--- a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleStatisticStore.java
+++ b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleStatisticStore.java
@@ -29,6 +29,7 @@
 import org.onlab.onos.net.statistic.StatisticStore;
 import org.slf4j.Logger;
 
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
@@ -84,8 +85,8 @@
             return;
         }
         InternalStatisticRepresentation rep = representations.get(cp);
-        if (rep != null) {
-            rep.remove(rule);
+        if (rep != null && rep.remove(rule)) {
+            updatePublishedStats(cp, Collections.emptySet());
         }
         Set<FlowEntry> values = current.get(cp);
         if (values != null) {
@@ -183,9 +184,9 @@
             counter.incrementAndGet();
         }
 
-        public synchronized void remove(FlowRule rule) {
+        public synchronized boolean remove(FlowRule rule) {
             rules.remove(rule);
-            counter.decrementAndGet();
+            return counter.decrementAndGet() == 0;
         }
 
         public synchronized boolean submit(FlowEntry rule) {