FlowRuleManager is now fully batch based
diff --git a/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java b/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
index 60ab307..0c07bab 100644
--- a/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
@@ -50,6 +50,7 @@
 import org.slf4j.Logger;
 
 import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Multimap;
@@ -116,71 +117,38 @@
 
     @Override
     public void applyFlowRules(FlowRule... flowRules) {
+        Set<FlowRuleBatchEntry> toAddBatchEntries = Sets.newHashSet();
         for (int i = 0; i < flowRules.length; i++) {
-            FlowRule f = flowRules[i];
-            store.storeFlowRule(f);
+            toAddBatchEntries.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, flowRules[i]));
         }
-    }
-
-    private void applyFlowRulesToProviders(FlowRule... flowRules) {
-        DeviceId did = null;
-        FlowRuleProvider frp = null;
-        for (FlowRule f : flowRules) {
-            if (!f.deviceId().equals(did)) {
-                did = f.deviceId();
-                final Device device = deviceService.getDevice(did);
-                frp = getProvider(device.providerId());
-            }
-            if (frp != null) {
-                frp.applyFlowRule(f);
-            }
-        }
+        applyBatch(new FlowRuleBatchOperation(toAddBatchEntries));
     }
 
     @Override
     public void removeFlowRules(FlowRule... flowRules) {
-        FlowRule f;
+        Set<FlowRuleBatchEntry> toRemoveBatchEntries = Sets.newHashSet();
         for (int i = 0; i < flowRules.length; i++) {
-            f = flowRules[i];
-            store.deleteFlowRule(f);
+            toRemoveBatchEntries.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, flowRules[i]));
         }
-    }
-
-    private void removeFlowRulesFromProviders(FlowRule... flowRules) {
-        DeviceId did = null;
-        FlowRuleProvider frp = null;
-        for (FlowRule f : flowRules) {
-            if (!f.deviceId().equals(did)) {
-                did = f.deviceId();
-                final Device device = deviceService.getDevice(did);
-                frp = getProvider(device.providerId());
-            }
-            if (frp != null) {
-                frp.removeFlowRule(f);
-            }
-        }
+        applyBatch(new FlowRuleBatchOperation(toRemoveBatchEntries));
     }
 
     @Override
     public void removeFlowRulesById(ApplicationId id) {
-        Iterable<FlowRule> rules = getFlowRulesById(id);
-        FlowRuleProvider frp;
-        Device device;
-
-        for (FlowRule f : rules) {
-            store.deleteFlowRule(f);
-            // FIXME: only accept request and push to provider on internal event
-            device = deviceService.getDevice(f.deviceId());
-            frp = getProvider(device.providerId());
-            // FIXME: flows removed from store and flows removed from might diverge
-            //        get rid of #removeRulesById?
-            frp.removeRulesById(id, f);
-        }
+        removeFlowRules(Iterables.toArray(getFlowRulesById(id), FlowRule.class));
     }
 
     @Override
     public Iterable<FlowRule> getFlowRulesById(ApplicationId id) {
-        return store.getFlowRulesByAppId(id);
+        Set<FlowRule> flowEntries = Sets.newHashSet();
+        for (Device d : deviceService.getDevices()) {
+            for (FlowEntry flowEntry : store.getFlowEntries(d.id())) {
+                if (flowEntry.appId() == id.id()) {
+                    flowEntries.add(flowEntry);
+                }
+            }
+        }
+        return flowEntries;
     }
 
     @Override
diff --git a/core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java b/core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java
index 659a2c4..85ceb3f 100644
--- a/core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java
+++ b/core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java
@@ -12,6 +12,7 @@
 import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_UPDATED;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -461,12 +462,12 @@
 
         @Override
         public int getDeviceCount() {
-            return 0;
+            return 1;
         }
 
         @Override
         public Iterable<Device> getDevices() {
-            return null;
+            return Arrays.asList(DEV);
         }
 
         @Override