Avoid unnecessary FlowRuleProgrammable polling

- Schedule background task only if there is a chance for positive
  availability event
- Exclude DEVICE_UPDATE type

Change-Id: I574cfe4ce3468e0be7010ed164cb02d4eeb88ec3
diff --git a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleDriverProvider.java b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleDriverProvider.java
index c3ad08b..6cf2cf3 100644
--- a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleDriverProvider.java
+++ b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleDriverProvider.java
@@ -193,6 +193,11 @@
         }
     }
 
+    // potentially positive device event
+    private static final Set<DeviceEvent.Type> POSITIVE_DEVICE_EVENT =
+            Sets.immutableEnumSet(DEVICE_ADDED,
+                                  DEVICE_AVAILABILITY_CHANGED);
+
     private class InternalDeviceListener implements DeviceListener {
 
         @Override
@@ -200,15 +205,20 @@
             executor.execute(() -> handleEvent(event));
         }
 
+        @Override
+        public boolean isRelevant(DeviceEvent event) {
+            Device device = event.subject();
+            return POSITIVE_DEVICE_EVENT.contains(event.type()) &&
+                   device.is(FlowRuleProgrammable.class);
+        }
+
         private void handleEvent(DeviceEvent event) {
             Device device = event.subject();
-            boolean isRelevant = mastershipService.isLocalMaster(device.id())
-                    && device.is(FlowRuleProgrammable.class)
-                    && (event.type() == DEVICE_ADDED ||
-                        event.type() == DEVICE_UPDATED ||
-                        (event.type() == DEVICE_AVAILABILITY_CHANGED && deviceService.isAvailable(device.id())));
+            boolean isRelevant = mastershipService.isLocalMaster(device.id()) &&
+                    deviceService.isAvailable(device.id());
+
             if (isRelevant) {
-                pollDeviceFlowEntries(event.subject());
+                pollDeviceFlowEntries(device);
             }
         }
     }