Allow turning off CoreEventDispatcher watchdog for debugging.

This can be done by setting CoreManager maxEventTimeLimit=0

Change-Id: I5328677020fe0fd48976957a89ee0a32d1d61292
diff --git a/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java b/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java
index 7b9c705..a8405dd 100644
--- a/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java
+++ b/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java
@@ -183,11 +183,11 @@
         }
 
         Integer timeLimit = Tools.getIntegerProperty(properties, "maxEventTimeLimit");
-        if (timeLimit != null && timeLimit > 1) {
+        if (timeLimit != null && timeLimit >= 0) {
             maxEventTimeLimit = timeLimit;
             eventDeliveryService.setDispatchTimeLimit(maxEventTimeLimit);
         } else if (timeLimit != null) {
-            log.warn("maxEventTimeLimit must be greater than 1");
+            log.warn("maxEventTimeLimit must be greater than or equal to 0");
         }
 
         Boolean performanceCheck = Tools.isPropertyEnabled(properties, "sharedThreadPerformanceCheck");
diff --git a/core/net/src/main/java/org/onosproject/event/impl/CoreEventDispatcher.java b/core/net/src/main/java/org/onosproject/event/impl/CoreEventDispatcher.java
index 2d20e47..12e922a 100644
--- a/core/net/src/main/java/org/onosproject/event/impl/CoreEventDispatcher.java
+++ b/core/net/src/main/java/org/onosproject/event/impl/CoreEventDispatcher.java
@@ -36,10 +36,10 @@
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.concurrent.Executors.newSingleThreadExecutor;
 import static org.onlab.util.Tools.groupedThreads;
-import static org.slf4j.LoggerFactory.getLogger;
-
 import static org.onosproject.security.AppGuard.checkPermission;
-import static org.onosproject.security.AppPermission.Type.*;
+import static org.onosproject.security.AppPermission.Type.EVENT_READ;
+import static org.onosproject.security.AppPermission.Type.EVENT_WRITE;
+import static org.slf4j.LoggerFactory.getLogger;
 /**
  * Simple implementation of an event dispatching service.
  */
@@ -50,6 +50,8 @@
 
     private final Logger log = getLogger(getClass());
 
+    private boolean executionTimeLimit = false;
+
     // Default number of millis a sink can take to process an event.
     private static final long DEFAULT_EXECUTE_MS = 5_000; // ms
     private static final long WATCHDOG_MS = 250; // ms
@@ -83,25 +85,48 @@
     public void activate() {
         dispatchLoop = new DispatchLoop();
         dispatchFuture = executor.submit(dispatchLoop);
-        watchdog = new Watchdog();
-        SharedExecutors.getTimer().schedule(watchdog, WATCHDOG_MS, WATCHDOG_MS);
+
+        if (maxProcessMillis != 0) {
+            startWatchdog();
+        }
+
         log.info("Started");
     }
 
     @Deactivate
     public void deactivate() {
         dispatchLoop.stop();
-        watchdog.cancel();
+        stopWatchdog();
         post(KILL_PILL);
         log.info("Stopped");
     }
 
+    private void startWatchdog() {
+        log.info("Starting watchdog task");
+        watchdog = new Watchdog();
+        SharedExecutors.getTimer().schedule(watchdog, WATCHDOG_MS, WATCHDOG_MS);
+    }
+
+    private void stopWatchdog() {
+        log.info("Stopping watchdog task");
+        if (watchdog != null) {
+            watchdog.cancel();
+        }
+    }
+
     @Override
     public void setDispatchTimeLimit(long millis) {
         checkPermission(EVENT_WRITE);
-        checkArgument(millis >= WATCHDOG_MS,
+        checkArgument(millis == 0 || millis >= WATCHDOG_MS,
                       "Time limit must be greater than %s", WATCHDOG_MS);
+        long oldMillis = maxProcessMillis;
         maxProcessMillis = millis;
+
+        if (millis == 0 && oldMillis != 0) {
+            stopWatchdog();
+        } else if (millis != 0 && oldMillis == 0) {
+            startWatchdog();
+        }
     }
 
     @Override
diff --git a/core/net/src/test/java/org/onosproject/event/impl/CoreEventDispatcherTest.java b/core/net/src/test/java/org/onosproject/event/impl/CoreEventDispatcherTest.java
index 3757481..77b2d68 100644
--- a/core/net/src/test/java/org/onosproject/event/impl/CoreEventDispatcherTest.java
+++ b/core/net/src/test/java/org/onosproject/event/impl/CoreEventDispatcherTest.java
@@ -29,7 +29,7 @@
 import static org.junit.Assert.assertEquals;
 
 /**
- * Test of the even dispatcher mechanism.
+ * Test of the event dispatcher mechanism.
  */
 public class CoreEventDispatcherTest {