I'm just getting started with WS and HTTP Server. Over an HTTP server, a couple of WS are created, which are used thorugh different shells. Every once in a while (couple weeks maybe) the WebServerSocket stops receiving new WS connections. If both the HttpServer and WSS are stopped and restarted everything works fine, but as there are other services running in the HTTP server this is not an option. I would like to stop and start the WS without restarting the HTTP server.
Added two new contexts to do this:
public class DevOpsCWS {
private final CustomWebSocket cws;
private static final Logger logger = LoggerFactory.getLogger(DevOpsCWS.class);
public DevOpsCWS (HttpServer hostServer, CustomWebSocket cws) {
this.cws = cws;
hostServer.createContext("/stopCWS", new StopCustomWebSocket());
hostServer.createContext("/startCWS", new StartCustomWebSocket());
}
private class StopCustomWebSocket implements HttpHandler {
@Override
public void handle(HttpExchange httpExchange) throws IOException {
try {
cws.stop();
} catch (IOException | InterruptedException t) {
// exception logging
} finally {
// success loggin
}
}
}
private class StartCustomWebSocket implements HttpHandler {
@Override
public void handle(HttpExchange httpExchange) throws IOException {
try {
cws.start();
} catch (IOException | InterruptedException t) {
// exception logging
} finally {
// success loggin
}
}
}
}
The issue I'm having appears, as far as I can tell, when calling the "start()" method of CustomWebSocket (it only calls the super.start() which invokes of WebSocketServer lib), the attribute "selectorthread" is not null, therefore no new Thread is created.
public void start() {
if (this.selectorthread != null) {
throw new IllegalStateException(this.getClass().getName() + " can only be started once.");
} else {
(new Thread(this)).start();
}
}
Thoughts on what I might be missing? Thanks in advance
Aucun commentaire:
Enregistrer un commentaire