/** Open/Activate the session */
  public void open() {
    if (LOG_OPEN.isDebugEnabled())
      LOG_OPEN.debug("[{}] {}.open()", policy.getBehavior(), this.getClass().getSimpleName());

    if (remote != null) {
      // already opened
      return;
    }

    try (ThreadClassLoaderScope scope = new ThreadClassLoaderScope(classLoader)) {
      // Upgrade success
      connection.getIOState().onConnected();

      // Connect remote
      remote = new WebSocketRemoteEndpoint(connection, outgoingHandler, getBatchMode());
      if (LOG_OPEN.isDebugEnabled())
        LOG_OPEN.debug(
            "[{}] {}.open() remote={}",
            policy.getBehavior(),
            this.getClass().getSimpleName(),
            remote);

      // Open WebSocket
      websocket.openSession(this);

      // Open connection
      connection.getIOState().onOpened();

      if (LOG.isDebugEnabled()) {
        LOG.debug("open -> {}", dump());
      }
    } catch (CloseException ce) {
      LOG.warn(ce);
      close(ce.getStatusCode(), ce.getMessage());
    } catch (Throwable t) {
      LOG.warn(t);
      // Exception on end-user WS-Endpoint.
      // Fast-fail & close connection with reason.
      int statusCode = StatusCode.SERVER_ERROR;
      if (policy.getBehavior() == WebSocketBehavior.CLIENT) {
        statusCode = StatusCode.POLICY_VIOLATION;
      }
      close(statusCode, t.getMessage());
    }
  }
 protected void terminateConnection(int statusCode, String rawreason) {
   LOG.debug("terminateConnection({},{})", statusCode, rawreason);
   session.close(statusCode, CloseFrame.truncate(rawreason));
 }