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; ...@@ -23,7 +23,10 @@ import com.google.common.collect.Maps;
23 import org.apache.felix.scr.annotations.Activate; 23 import org.apache.felix.scr.annotations.Activate;
24 import org.apache.felix.scr.annotations.Component; 24 import org.apache.felix.scr.annotations.Component;
25 import org.apache.felix.scr.annotations.Deactivate; 25 import org.apache.felix.scr.annotations.Deactivate;
26 +import org.apache.felix.scr.annotations.Reference;
27 +import org.apache.felix.scr.annotations.ReferenceCardinality;
26 import org.apache.felix.scr.annotations.Service; 28 import org.apache.felix.scr.annotations.Service;
29 +import org.onosproject.mastership.MastershipService;
27 import org.onosproject.ui.UiExtension; 30 import org.onosproject.ui.UiExtension;
28 import org.onosproject.ui.UiExtensionService; 31 import org.onosproject.ui.UiExtensionService;
29 import org.onosproject.ui.UiMessageHandlerFactory; 32 import org.onosproject.ui.UiMessageHandlerFactory;
...@@ -66,6 +69,8 @@ public class UiExtensionManager ...@@ -66,6 +69,8 @@ public class UiExtensionManager
66 private final AltTopoViewMessageHandler topoHandler = 69 private final AltTopoViewMessageHandler topoHandler =
67 new AltTopoViewMessageHandler(); 70 new AltTopoViewMessageHandler();
68 71
72 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
73 + protected MastershipService mastershipService;
69 74
70 // Creates core UI extension 75 // Creates core UI extension
71 private UiExtension createCoreExtension() { 76 private UiExtension createCoreExtension() {
...@@ -111,6 +116,7 @@ public class UiExtensionManager ...@@ -111,6 +116,7 @@ public class UiExtensionManager
111 116
112 @Deactivate 117 @Deactivate
113 public void deactivate() { 118 public void deactivate() {
119 + UiWebSocketServlet.closeAll();
114 unregister(core); 120 unregister(core);
115 log.info("Stopped"); 121 log.info("Stopped");
116 } 122 }
......
...@@ -35,15 +35,28 @@ public class UiWebSocketServlet extends WebSocketServlet { ...@@ -35,15 +35,28 @@ public class UiWebSocketServlet extends WebSocketServlet {
35 35
36 private static final long PING_DELAY_MS = 5000; 36 private static final long PING_DELAY_MS = 5000;
37 37
38 + private static UiWebSocketServlet instance;
39 +
38 private ServiceDirectory directory = new DefaultServiceDirectory(); 40 private ServiceDirectory directory = new DefaultServiceDirectory();
39 41
40 private final Set<UiWebSocket> sockets = new HashSet<>(); 42 private final Set<UiWebSocket> sockets = new HashSet<>();
41 private final Timer timer = new Timer(); 43 private final Timer timer = new Timer();
42 private final TimerTask pruner = new Pruner(); 44 private final TimerTask pruner = new Pruner();
43 45
46 + /**
47 + * Closes all currently open UI web-sockets.
48 + */
49 + public static void closeAll() {
50 + if (instance != null) {
51 + instance.sockets.forEach(UiWebSocket::close);
52 + instance.sockets.clear();
53 + }
54 + }
55 +
44 @Override 56 @Override
45 public void init() throws ServletException { 57 public void init() throws ServletException {
46 super.init(); 58 super.init();
59 + instance = this;
47 timer.schedule(pruner, PING_DELAY_MS, PING_DELAY_MS); 60 timer.schedule(pruner, PING_DELAY_MS, PING_DELAY_MS);
48 } 61 }
49 62
......