/** Incoming Errors from Parser */
 @Override
 public void incomingError(Throwable t) {
   if (connection.getIOState().isInputAvailable()) {
     // Forward Errors to User WebSocket Object
     websocket.incomingError(t);
   }
 }
 /** Incoming Errors from Parser */
 @Override
 public void incomingError(WebSocketException e) {
   if (connection.isInputClosed()) {
     return; // input is closed
   }
   // Forward Errors to User WebSocket Object
   websocket.incomingError(e);
 }
  /**
   * Open/Activate the session
   *
   * @throws IOException
   */
  public void open() {
    if (isOpen()) {
      throw new WebSocketException("Cannot Open WebSocketSession, Already open");
    }

    // Connect remote
    remote = new WebSocketRemoteEndpoint(connection, outgoingHandler);

    // Activate Session
    this.active = true;

    // Open WebSocket
    websocket.setSession(this);
    websocket.onConnect();

    if (LOG.isDebugEnabled()) {
      LOG.debug("{}", dump());
    }
  }
  /** 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());
    }
  }
 public void notifyClose(int statusCode, String reason) {
   if (LOG.isDebugEnabled()) {
     LOG.debug("notifyClose({},{})", statusCode, reason);
   }
   websocket.onClose(new CloseInfo(statusCode, reason));
 }