Thomas Vachuska
Committed by Gerrit Code Review

GUI -- Fixed a shut-down exception by explicitly closing all web-sockets on shutdown.

Change-Id: I3264a9029f36fdba150a3d729a2dd8c9024805d3
......@@ -23,7 +23,10 @@ import com.google.common.collect.Maps;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.mastership.MastershipService;
import org.onosproject.ui.UiExtension;
import org.onosproject.ui.UiExtensionService;
import org.onosproject.ui.UiMessageHandlerFactory;
......@@ -66,6 +69,8 @@ public class UiExtensionManager
private final AltTopoViewMessageHandler topoHandler =
new AltTopoViewMessageHandler();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected MastershipService mastershipService;
// Creates core UI extension
private UiExtension createCoreExtension() {
......@@ -111,6 +116,7 @@ public class UiExtensionManager
@Deactivate
public void deactivate() {
UiWebSocketServlet.closeAll();
unregister(core);
log.info("Stopped");
}
......
......@@ -35,15 +35,28 @@ public class UiWebSocketServlet extends WebSocketServlet {
private static final long PING_DELAY_MS = 5000;
private static UiWebSocketServlet instance;
private ServiceDirectory directory = new DefaultServiceDirectory();
private final Set<UiWebSocket> sockets = new HashSet<>();
private final Timer timer = new Timer();
private final TimerTask pruner = new Pruner();
/**
* Closes all currently open UI web-sockets.
*/
public static void closeAll() {
if (instance != null) {
instance.sockets.forEach(UiWebSocket::close);
instance.sockets.clear();
}
}
@Override
public void init() throws ServletException {
super.init();
instance = this;
timer.schedule(pruner, PING_DELAY_MS, PING_DELAY_MS);
}
......