@Override
  public void onClose(NettyResponseFuture<?> future) {
    logger.trace("onClose");

    try {
      WebSocketUpgradeHandler h = (WebSocketUpgradeHandler) future.getAsyncHandler();
      NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted());

      logger.trace("Connection was closed abnormally (that is, with no close frame being sent).");
      if (webSocket != null)
        webSocket.close(
            1006, "Connection was closed abnormally (that is, with no close frame being sent).");
    } catch (Throwable t) {
      logger.error("onError", t);
    }
  }
  @Override
  public void onError(NettyResponseFuture<?> future, Throwable e) {
    logger.warn("onError {}", e);

    try {
      WebSocketUpgradeHandler h = (WebSocketUpgradeHandler) future.getAsyncHandler();

      NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted());
      if (webSocket != null) {
        webSocket.onError(e.getCause());
        webSocket.close();
      }
    } catch (Throwable t) {
      logger.error("onError", t);
    }
  }