Right now its very fragile as an unhandled exception can cause the thread to die causing
the controller to be unusable. Making the thread more tolerant of exceptions and making
the shutdown of the thread more deterministic.
Change-Id: I31c31f012229de8e124c0c13fa651513daaf6776
Signed-off-by: Asad Ahmed <asaahmed@cisco.com>
.getLogger(Controller.class);
private ControllerIO controllerIO;
private Thread switchEventThread;
.getLogger(Controller.class);
private ControllerIO controllerIO;
private Thread switchEventThread;
+ private volatile boolean shutdownSwitchEventThread;// default to false
private ConcurrentHashMap<Long, ISwitch> switches;
private PriorityBlockingQueue<SwitchEvent> switchEvents;
// only 1 message listener per OFType
private ConcurrentHashMap<Long, ISwitch> switches;
private PriorityBlockingQueue<SwitchEvent> switchEvents;
// only 1 message listener per OFType
+ if(shutdownSwitchEventThread) {
+ // break out of the infinite loop
+ // if you are shutting down
+ logger.info("Switch Event Thread is shutting down");
+ break;
+ }
SwitchEvent ev = switchEvents.take();
SwitchEvent.SwitchEventType eType = ev.getEventType();
ISwitch sw = ev.getSwitch();
SwitchEvent ev = switchEvents.take();
SwitchEvent.SwitchEventType eType = ev.getEventType();
ISwitch sw = ev.getSwitch();
logger.error("Unknown switch event {}", eType.ordinal());
}
} catch (InterruptedException e) {
logger.error("Unknown switch event {}", eType.ordinal());
}
} catch (InterruptedException e) {
- switchEvents.clear();
- return;
+ // nothing to do except retry
+ } catch (Exception e) {
+ // log the exception and retry
+ logger.warn("Exception in Switch Event Thread is {}" ,e);
((SwitchHandler) entry.getValue()).stop();
it.remove();
}
((SwitchHandler) entry.getValue()).stop();
it.remove();
}
+ shutdownSwitchEventThread = true;
switchEventThread.interrupt();
try {
controllerIO.shutDown();
switchEventThread.interrupt();
try {
controllerIO.shutDown();