class WatcherWebSocketListener<T extends HasMetadata> implements WebSocket.Listener {
  protected static final Logger logger = LoggerFactory.getLogger(WatcherWebSocketListener.class);

  protected final WatchRequestState state;
  protected final AbstractWatchManager<T> manager;

  protected WatcherWebSocketListener(AbstractWatchManager<T> manager, WatchRequestState state) {
    this.manager = manager;
    this.state = state;
  }

  @Override
  public void onOpen(final WebSocket webSocket) {
    logger.debug("WebSocket successfully opened");
    manager.resetReconnectAttempts(state);
  }

  @Override
  public void onError(WebSocket webSocket, Throwable t) {
    manager.watchEnded(t, state);
  }

  @Override
  public void onMessage(WebSocket webSocket, String text) {<FILL_FUNCTION_BODY>}

  @Override
  public void onMessage(WebSocket webSocket, ByteBuffer bytes) {
    onMessage(webSocket, StandardCharsets.UTF_8.decode(bytes).toString());
  }

  @Override
  public void onClose(WebSocket webSocket, int code, String reason) {
    logger.debug("WebSocket close received. code: {}, reason: {}", code, reason);
    try {
      webSocket.sendClose(code, reason);
    } finally {
      manager.watchEnded(null, state);
    }
  }

}

    try {
      manager.onMessage(text, state);
    } finally {
      webSocket.request();
    }
  
<no_super_class>