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 {
}
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");
......
......@@ -36,10 +36,10 @@ import java.util.concurrent.LinkedBlockingQueue;
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 @@ public class CoreEventDispatcher extends DefaultEventSinkRegistry
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 class CoreEventDispatcher extends DefaultEventSinkRegistry
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
......
......@@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
/**
* Test of the even dispatcher mechanism.
* Test of the event dispatcher mechanism.
*/
public class CoreEventDispatcherTest {
......