Search in sources :

Example 1 with ConnectionState

use of org.eclipse.jetty.websocket.common.ConnectionState in project jetty.project by eclipse.

the class IOState method onFailedUpgrade.

/**
     * A websocket connection has failed its upgrade handshake, and is now closed.
     */
public void onFailedUpgrade() {
    assert (this.state == ConnectionState.CONNECTING);
    ConnectionState event = null;
    synchronized (this) {
        this.state = ConnectionState.CLOSED;
        cleanClose = false;
        inputAvailable = false;
        outputAvailable = false;
        event = this.state;
    }
    notifyStateListeners(event);
}
Also used : ConnectionState(org.eclipse.jetty.websocket.common.ConnectionState)

Example 2 with ConnectionState

use of org.eclipse.jetty.websocket.common.ConnectionState in project jetty.project by eclipse.

the class AbstractWebSocketConnection method onReadTimeout.

/**
     * Event for no activity on connection (read or write)
     */
@Override
protected boolean onReadTimeout() {
    IOState state = getIOState();
    ConnectionState cstate = state.getConnectionState();
    if (LOG_CLOSE.isDebugEnabled())
        LOG_CLOSE.debug("{} Read Timeout - {}", policy.getBehavior(), cstate);
    if (cstate == ConnectionState.CLOSED) {
        if (LOG_CLOSE.isDebugEnabled())
            LOG_CLOSE.debug("onReadTimeout - Connection Already CLOSED");
        // allow underlying connection and endpoint to disconnect on its own
        return true;
    }
    try {
        notifyError(new SocketTimeoutException("Timeout on Read"));
    } finally {
        // This is an Abnormal Close condition
        close(StatusCode.SHUTDOWN, "Idle Timeout");
    }
    return false;
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) ConnectionState(org.eclipse.jetty.websocket.common.ConnectionState)

Example 3 with ConnectionState

use of org.eclipse.jetty.websocket.common.ConnectionState in project jetty.project by eclipse.

the class IOState method onDisconnected.

public void onDisconnected() {
    ConnectionState event = null;
    synchronized (this) {
        if (this.state == ConnectionState.CLOSED) {
            // already closed
            return;
        }
        CloseInfo close = new CloseInfo(StatusCode.ABNORMAL, "Disconnected");
        this.cleanClose = false;
        this.state = ConnectionState.CLOSED;
        this.closeInfo = close;
        this.inputAvailable = false;
        this.outputAvailable = false;
        this.closeHandshakeSource = CloseHandshakeSource.ABNORMAL;
        event = this.state;
    }
    notifyStateListeners(event);
}
Also used : ConnectionState(org.eclipse.jetty.websocket.common.ConnectionState) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Example 4 with ConnectionState

use of org.eclipse.jetty.websocket.common.ConnectionState in project jetty.project by eclipse.

the class IOState method onWriteFailure.

/**
     * The local endpoint has reached a write failure.
     * <p>
     * A low level I/O failure, or even a jetty side EndPoint close (from idle timeout) are a few scenarios
     * @param t the throwable that caused the write failure
     */
public void onWriteFailure(Throwable t) {
    ConnectionState event = null;
    synchronized (this) {
        if (this.state == ConnectionState.CLOSED) {
            // already closed
            return;
        }
        // Build out Close Reason
        String reason = "WebSocket Write Failure";
        if (t instanceof EOFException) {
            reason = "WebSocket Write EOF";
            Throwable cause = t.getCause();
            if ((cause != null) && (StringUtil.isNotBlank(cause.getMessage()))) {
                reason = "EOF: " + cause.getMessage();
            }
        } else {
            if (StringUtil.isNotBlank(t.getMessage())) {
                reason = t.getMessage();
            }
        }
        CloseInfo close = new CloseInfo(StatusCode.ABNORMAL, reason);
        finalClose.compareAndSet(null, close);
        this.cleanClose = false;
        this.state = ConnectionState.CLOSED;
        this.inputAvailable = false;
        this.outputAvailable = false;
        this.closeHandshakeSource = CloseHandshakeSource.ABNORMAL;
        event = this.state;
    }
    notifyStateListeners(event);
}
Also used : EOFException(java.io.EOFException) ConnectionState(org.eclipse.jetty.websocket.common.ConnectionState) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Example 5 with ConnectionState

use of org.eclipse.jetty.websocket.common.ConnectionState in project jetty.project by eclipse.

the class IOState method onReadFailure.

/**
     * The local endpoint has reached a read failure.
     * <p>
     * This could be a normal result after a proper close handshake, or even a premature close due to a connection disconnect.
     * @param t the read failure
     */
public void onReadFailure(Throwable t) {
    ConnectionState event = null;
    synchronized (this) {
        if (this.state == ConnectionState.CLOSED) {
            // already closed
            return;
        }
        // Build out Close Reason
        String reason = "WebSocket Read Failure";
        if (t instanceof EOFException) {
            reason = "WebSocket Read EOF";
            Throwable cause = t.getCause();
            if ((cause != null) && (StringUtil.isNotBlank(cause.getMessage()))) {
                reason = "EOF: " + cause.getMessage();
            }
        } else {
            if (StringUtil.isNotBlank(t.getMessage())) {
                reason = t.getMessage();
            }
        }
        CloseInfo close = new CloseInfo(StatusCode.ABNORMAL, reason);
        finalClose.compareAndSet(null, close);
        this.cleanClose = false;
        this.state = ConnectionState.CLOSED;
        this.closeInfo = close;
        this.inputAvailable = false;
        this.outputAvailable = false;
        this.closeHandshakeSource = CloseHandshakeSource.ABNORMAL;
        event = this.state;
    }
    notifyStateListeners(event);
}
Also used : EOFException(java.io.EOFException) ConnectionState(org.eclipse.jetty.websocket.common.ConnectionState) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Aggregations

ConnectionState (org.eclipse.jetty.websocket.common.ConnectionState)10 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)3 EOFException (java.io.EOFException)2 SocketTimeoutException (java.net.SocketTimeoutException)1