Jonathan Hart

Allow turning off CoreEventDispatcher watchdog for debugging.

This can be done by setting CoreManager maxEventTimeLimit=0

Change-Id: I5328677020fe0fd48976957a89ee0a32d1d61292
...@@ -183,11 +183,11 @@ public class CoreManager implements CoreService { ...@@ -183,11 +183,11 @@ public class CoreManager implements CoreService {
183 } 183 }
184 184
185 Integer timeLimit = Tools.getIntegerProperty(properties, "maxEventTimeLimit"); 185 Integer timeLimit = Tools.getIntegerProperty(properties, "maxEventTimeLimit");
186 - if (timeLimit != null && timeLimit > 1) { 186 + if (timeLimit != null && timeLimit >= 0) {
187 maxEventTimeLimit = timeLimit; 187 maxEventTimeLimit = timeLimit;
188 eventDeliveryService.setDispatchTimeLimit(maxEventTimeLimit); 188 eventDeliveryService.setDispatchTimeLimit(maxEventTimeLimit);
189 } else if (timeLimit != null) { 189 } else if (timeLimit != null) {
190 - log.warn("maxEventTimeLimit must be greater than 1"); 190 + log.warn("maxEventTimeLimit must be greater than or equal to 0");
191 } 191 }
192 192
193 Boolean performanceCheck = Tools.isPropertyEnabled(properties, "sharedThreadPerformanceCheck"); 193 Boolean performanceCheck = Tools.isPropertyEnabled(properties, "sharedThreadPerformanceCheck");
......
...@@ -36,10 +36,10 @@ import java.util.concurrent.LinkedBlockingQueue; ...@@ -36,10 +36,10 @@ import java.util.concurrent.LinkedBlockingQueue;
36 import static com.google.common.base.Preconditions.checkArgument; 36 import static com.google.common.base.Preconditions.checkArgument;
37 import static java.util.concurrent.Executors.newSingleThreadExecutor; 37 import static java.util.concurrent.Executors.newSingleThreadExecutor;
38 import static org.onlab.util.Tools.groupedThreads; 38 import static org.onlab.util.Tools.groupedThreads;
39 -import static org.slf4j.LoggerFactory.getLogger;
40 -
41 import static org.onosproject.security.AppGuard.checkPermission; 39 import static org.onosproject.security.AppGuard.checkPermission;
42 -import static org.onosproject.security.AppPermission.Type.*; 40 +import static org.onosproject.security.AppPermission.Type.EVENT_READ;
41 +import static org.onosproject.security.AppPermission.Type.EVENT_WRITE;
42 +import static org.slf4j.LoggerFactory.getLogger;
43 /** 43 /**
44 * Simple implementation of an event dispatching service. 44 * Simple implementation of an event dispatching service.
45 */ 45 */
...@@ -50,6 +50,8 @@ public class CoreEventDispatcher extends DefaultEventSinkRegistry ...@@ -50,6 +50,8 @@ public class CoreEventDispatcher extends DefaultEventSinkRegistry
50 50
51 private final Logger log = getLogger(getClass()); 51 private final Logger log = getLogger(getClass());
52 52
53 + private boolean executionTimeLimit = false;
54 +
53 // Default number of millis a sink can take to process an event. 55 // Default number of millis a sink can take to process an event.
54 private static final long DEFAULT_EXECUTE_MS = 5_000; // ms 56 private static final long DEFAULT_EXECUTE_MS = 5_000; // ms
55 private static final long WATCHDOG_MS = 250; // ms 57 private static final long WATCHDOG_MS = 250; // ms
...@@ -83,25 +85,48 @@ public class CoreEventDispatcher extends DefaultEventSinkRegistry ...@@ -83,25 +85,48 @@ public class CoreEventDispatcher extends DefaultEventSinkRegistry
83 public void activate() { 85 public void activate() {
84 dispatchLoop = new DispatchLoop(); 86 dispatchLoop = new DispatchLoop();
85 dispatchFuture = executor.submit(dispatchLoop); 87 dispatchFuture = executor.submit(dispatchLoop);
86 - watchdog = new Watchdog(); 88 +
87 - SharedExecutors.getTimer().schedule(watchdog, WATCHDOG_MS, WATCHDOG_MS); 89 + if (maxProcessMillis != 0) {
90 + startWatchdog();
91 + }
92 +
88 log.info("Started"); 93 log.info("Started");
89 } 94 }
90 95
91 @Deactivate 96 @Deactivate
92 public void deactivate() { 97 public void deactivate() {
93 dispatchLoop.stop(); 98 dispatchLoop.stop();
94 - watchdog.cancel(); 99 + stopWatchdog();
95 post(KILL_PILL); 100 post(KILL_PILL);
96 log.info("Stopped"); 101 log.info("Stopped");
97 } 102 }
98 103
104 + private void startWatchdog() {
105 + log.info("Starting watchdog task");
106 + watchdog = new Watchdog();
107 + SharedExecutors.getTimer().schedule(watchdog, WATCHDOG_MS, WATCHDOG_MS);
108 + }
109 +
110 + private void stopWatchdog() {
111 + log.info("Stopping watchdog task");
112 + if (watchdog != null) {
113 + watchdog.cancel();
114 + }
115 + }
116 +
99 @Override 117 @Override
100 public void setDispatchTimeLimit(long millis) { 118 public void setDispatchTimeLimit(long millis) {
101 checkPermission(EVENT_WRITE); 119 checkPermission(EVENT_WRITE);
102 - checkArgument(millis >= WATCHDOG_MS, 120 + checkArgument(millis == 0 || millis >= WATCHDOG_MS,
103 "Time limit must be greater than %s", WATCHDOG_MS); 121 "Time limit must be greater than %s", WATCHDOG_MS);
122 + long oldMillis = maxProcessMillis;
104 maxProcessMillis = millis; 123 maxProcessMillis = millis;
124 +
125 + if (millis == 0 && oldMillis != 0) {
126 + stopWatchdog();
127 + } else if (millis != 0 && oldMillis == 0) {
128 + startWatchdog();
129 + }
105 } 130 }
106 131
107 @Override 132 @Override
......
...@@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit; ...@@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit;
29 import static org.junit.Assert.assertEquals; 29 import static org.junit.Assert.assertEquals;
30 30
31 /** 31 /**
32 - * Test of the even dispatcher mechanism. 32 + * Test of the event dispatcher mechanism.
33 */ 33 */
34 public class CoreEventDispatcherTest { 34 public class CoreEventDispatcherTest {
35 35
......