ExtensionWebSocketClient { public void stop() { WebSocket socket = webSocket; webSocket = null; outstandingNotifications = null; if (socket != null) { try { socket.close(1000, "Closed by client"); } catch (Exception e) { if (!e.getMessage().equals("Socket closed")) { log.warn("Websocket has already been closed"); } else { log.error("Error trying to close WebSocket", e); } } } synchronized (this) { if (webSocketFuture != null) { webSocketFuture.obtrudeValue(false); webSocketFuture = null; } if (authFuture != null) { authFuture.obtrudeValue(false); authFuture = null; } if (sourceFuture != null) { sourceFuture.obtrudeValue(false); sourceFuture = null; } listener.close(); } log.info("Websocket closed."); } ExtensionWebSocketClient(String sourceName); ExtensionWebSocketListener getListener(); String getSourceName(); CompletableFuture<Boolean> initiateFullConnection(String url, String token); synchronized CompletableFuture<Boolean> initiateWebsocketConnection(String url); CompletableFuture<Boolean> getWebsocketConnectionFuture(); void sendNotification(Object data); void sendQueryResponseEmpty(String replyAddress); void sendQueryResponse(int httpCode, String replyAddress, Map body); void sendQueryResponse(int httpCode, String replyAddress, Map[] body); void sendQueryError(String replyAddress, String messageCode, String messageTemplate, Object[] parameters); void send(Object obj); synchronized CompletableFuture<Boolean> authenticate(String user, String pass); synchronized CompletableFuture<Boolean> authenticate(String token); CompletableFuture<Boolean> getAuthenticationFuture(); synchronized CompletableFuture<Boolean> connectToSource(); CompletableFuture<Boolean> getSourceConnectionFuture(); void sourceHasDisconnected(); void setAutoReconnect(boolean value); boolean isOpen(); boolean isAuthed(); boolean isConnected(); void close(); void stop(); void useHandlersFrom(ExtensionWebSocketListener listener); void useHandlersFrom(ExtensionWebSocketClient client); void setCloseHandler(Handler<ExtensionWebSocketClient> closeHandler); void setHttpHandler(Handler<Response> httpHandler); void setPublishHandler(Handler<ExtensionServiceMessage> publishHandler); void setQueryHandler(Handler<ExtensionServiceMessage> queryHandler); void setConfigHandler(Handler<ExtensionServiceMessage> configHandler); void setAuthHandler(Handler<Response> authHandler); void setReconnectHandler(Handler<ExtensionServiceMessage> reconnectHandler); static final int QUERY_CHUNK_CODE; static final int QUERY_DATA_CODE; static final int QUERY_NODATA_CODE; }
@Test public void testStop() { markSourceConnected(true); assert !client.getListener().isClosed(); client.stop(); assert client.getListener().isClosed(); }