class ExtensionWebSocketClient {

    public void stop() {
        // Saving and nulling before closing so EWSListener can know when it is closed by the client 
        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) {
            // Make sure anything still using these futures know that they are no longer valid
            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.");
    }

    public  ExtensionWebSocketClient(String sourceName);

}