public void disconnect() { running = false; if (webSocketImpl != null) { webSocketImpl.close(); } if (webSocketClient != null) { try { webSocketClient.stop(); } catch (Exception e) { LOGGER.error("", e); } webSocketClient.destroy(); } }
public void stop() { synchronized (this) { this.running.set(false); this.notifyAll(); } try { workerThread.join(); } catch (InterruptedException e) { logger.warning("Interrupted while waiting for transmitter to finish."); } try { client.stop(); } catch (Exception e) { logger.log(Level.INFO, "Exception while trying to stop", e); } client.destroy(); }
@Override public void closeNativeClient() { if (jettyClient != null) { log.debug("{} Closing client", label); try { jettyClient.stop(); jettyClient.destroy(); } catch (Exception e) { log.warn("{} Could not properly close websocket client.", label, e); } jettyClient = null; } if (jettyWsSession != null) { jettyWsSession.close(); jettyWsSession = null; } else { log.warn("{} Trying to close a JsonRpcClientWebSocket with jettyWsSession=null", label); } }
@OnWebSocketError public void onError(Session wsSession, Throwable err) { logger.info(String.format("Connection error: %s - %s", wsSession, err.getMessage())); try { if (client.isRunning()) { client.stop(); client.destroy(); } } catch (Exception e) { logger.log(Level.INFO, "Exception while trying to handle socket error", e); } } }
@OnWebSocketClose public void onClose(int statusCode, String reason) { logger.info(String.format("Connection closed: %d - %s", statusCode, reason)); try { if (client.isRunning()) { client.stop(); client.destroy(); } } catch (Exception e) { logger.log(Level.INFO, "Exception while trying to handle socket close", e); } }
private void connect() throws Exception { wsSession = null; client = new WebSocketClient(); client.start(); client.setAsyncWriteTimeout(5000); client.setConnectTimeout(2000); client.setStopTimeout(5000); ClientUpgradeRequest request = new ClientUpgradeRequest(); request.setHeader("Authorization", SSHUtil.getPublicKeyAuthorization(username)); Future<Session> future = client.connect(this, uri, request); logger.info(String.format("Connecting to : %s", uri)); try { wsSession = future.get(); } catch (Exception e) { logger.log(Level.INFO, "Exception while trying to connect", e); try { client.stop(); client.destroy(); } catch (Exception e1) { logger.log(Level.INFO, "Exception while trying to disconnect", e1); } } } @OnWebSocketClose
@Override public synchronized void stop() { if (webSocketClient == null) return; log.info("Stopping Jetty 9 WebSocketClient transport..."); setStopping(true); super.stop(); try { webSocketClient.stop(); } catch (Exception e) { getStatusHandler().handleException(new TransportException("Could not stop Jetty 9 WebSocketFactory", e)); log.error(e, "Jetty 9 WebSocketClient failed to stop properly."); } finally { webSocketClient.destroy(); webSocketClient = null; setStopping(false); } log.info("Jetty 9 WebSocketClient transport stopped."); }
@Override public synchronized void stop() { if (webSocketClient == null) return; log.info("Stopping Jetty 9 WebSocketClient transport..."); setStopping(true); super.stop(); try { webSocketClient.stop(); } catch (Exception e) { getStatusHandler().handleException(new TransportException("Could not stop Jetty 9 WebSocketFactory", e)); log.error(e, "Jetty 9 WebSocketClient failed to stop properly."); } finally { webSocketClient.destroy(); webSocketClient = null; setStopping(false); } log.info("Jetty 9 WebSocketClient transport stopped."); }