WsSession.java 文件源码

java
阅读 30 收藏 0 点赞 0 评论 0

项目:lazycat 作者:
/**
 * WebSocket 1.0. Section 2.1.5. Need internal close method as spec requires
 * that the local endpoint receives a 1006 on timeout.
 */
public void doClose(CloseReason closeReasonMessage, CloseReason closeReasonLocal) {
    // Double-checked locking. OK because state is volatile
    if (state != State.OPEN) {
        return;
    }

    synchronized (stateLock) {
        if (state != State.OPEN) {
            return;
        }

        if (log.isDebugEnabled()) {
            log.debug(sm.getString("wsSession.doClose", id));
        }
        try {
            wsRemoteEndpoint.setBatchingAllowed(false);
        } catch (IOException e) {
            log.warn(sm.getString("wsSession.flushFailOnClose"), e);
            fireEndpointOnError(e);
        }

        state = State.OUTPUT_CLOSED;

        sendCloseMessage(closeReasonMessage);
        fireEndpointOnClose(closeReasonLocal);
    }

    IOException ioe = new IOException(sm.getString("wsSession.messageFailed"));
    SendResult sr = new SendResult(ioe);
    for (FutureToSendHandler f2sh : futures.keySet()) {
        f2sh.onResult(sr);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号