当前位置: 首页>>代码示例>>Java>>正文


Java CloseCodes.CLOSED_ABNORMALLY属性代码示例

本文整理汇总了Java中javax.websocket.CloseReason.CloseCodes.CLOSED_ABNORMALLY属性的典型用法代码示例。如果您正苦于以下问题:Java CloseCodes.CLOSED_ABNORMALLY属性的具体用法?Java CloseCodes.CLOSED_ABNORMALLY怎么用?Java CloseCodes.CLOSED_ABNORMALLY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.websocket.CloseReason.CloseCodes的用法示例。


在下文中一共展示了CloseCodes.CLOSED_ABNORMALLY属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendCloseMessage

private void sendCloseMessage(CloseReason closeReason) {
    // 125 is maximum size for the payload of a control message
    ByteBuffer msg = ByteBuffer.allocate(125);
    CloseCode closeCode = closeReason.getCloseCode();
    // CLOSED_ABNORMALLY should not be put on the wire
    if (closeCode == CloseCodes.CLOSED_ABNORMALLY) {
        // PROTOCOL_ERROR is probably better than GOING_AWAY here
        msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode());
    } else {
        msg.putShort((short) closeCode.getCode());
    }

    String reason = closeReason.getReasonPhrase();
    if (reason != null && reason.length() > 0) {
        appendCloseReasonWithTruncation(msg, reason);
    }
    msg.flip();
    try {
        wsRemoteEndpoint.startMessageBlock(Constants.OPCODE_CLOSE, msg, true);
    } catch (IOException ioe) {
        handleCloseException(ioe, closeCode);
    } catch (WritePendingException wpe) {
        handleCloseException(wpe, closeCode);
    } finally {
        webSocketContainer.unregisterSession(localEndpoint, this);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:27,代码来源:WsSession.java

示例2: handleCloseException

private void handleCloseException(Exception e, CloseCode closeCode) {
    // Failed to send close message. Close the socket and let the caller
    // deal with the Exception
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("wsSession.sendCloseFail", id), e);
    }
    wsRemoteEndpoint.close();
    // Failure to send a close message is not unexpected in the case of
    // an abnormal closure (usually triggered by a failure to read/write
    // from/to the client. In this case do not trigger the endpoint's
    // error handling
    if (closeCode != CloseCodes.CLOSED_ABNORMALLY) {
        localEndpoint.onError(this, e);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:15,代码来源:WsSession.java

示例3: handleThrowableOnSend

private void handleThrowableOnSend(Throwable t) throws WsIOException {
    ExceptionUtils.handleThrowable(t);
    wsSession.getLocal().onError(wsSession, t);
    CloseReason cr = new CloseReason(CloseCodes.CLOSED_ABNORMALLY,
            sm.getString("wsFrame.ioeTriggeredClose"));
    throw new WsIOException(cr);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:7,代码来源:WsFrameBase.java

示例4: onDataAvailable

@Override
public void onDataAvailable() {
    try {
        wsFrame.onDataAvailable();
    } catch (WsIOException ws) {
        wsProtocolHandler.close(ws.getCloseReason());
    } catch (IOException ioe) {
        onError(ioe);
        CloseReason cr = new CloseReason(
                CloseCodes.CLOSED_ABNORMALLY, ioe.getMessage());
        wsProtocolHandler.close(cr);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:13,代码来源:WsHttpUpgradeHandler.java

示例5: sendMessage

protected void sendMessage(String msg) {
    try {
        session.getBasicRemote().sendText(msg);
    } catch (IOException ioe) {
        CloseReason cr =
                new CloseReason(CloseCodes.CLOSED_ABNORMALLY, ioe.getMessage());
        try {
            session.close(cr);
        } catch (IOException ioe2) {
            // Ignore
        }
    }
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:13,代码来源:Snake.java

示例6: sendCloseMessage

private void sendCloseMessage(CloseReason closeReason) {
	// 125 is maximum size for the payload of a control message
	ByteBuffer msg = ByteBuffer.allocate(125);
	CloseCode closeCode = closeReason.getCloseCode();
	// CLOSED_ABNORMALLY should not be put on the wire
	if (closeCode == CloseCodes.CLOSED_ABNORMALLY) {
		// PROTOCOL_ERROR is probably better than GOING_AWAY here
		msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode());
	} else {
		msg.putShort((short) closeCode.getCode());
	}

	String reason = closeReason.getReasonPhrase();
	if (reason != null && reason.length() > 0) {
		appendCloseReasonWithTruncation(msg, reason);
	}
	msg.flip();
	try {
		wsRemoteEndpoint.startMessageBlock(Constants.OPCODE_CLOSE, msg, true);
	} catch (IOException ioe) {
		handleCloseException(ioe, closeCode);
	} catch (WritePendingException wpe) {
		handleCloseException(wpe, closeCode);
	} finally {
		webSocketContainer.unregisterSession(localEndpoint, this);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:27,代码来源:WsSession.java

示例7: handleCloseException

private void handleCloseException(Exception e, CloseCode closeCode) {
	// Failed to send close message. Close the socket and let the caller
	// deal with the Exception
	if (log.isDebugEnabled()) {
		log.debug(sm.getString("wsSession.sendCloseFail", id), e);
	}
	wsRemoteEndpoint.close();
	// Failure to send a close message is not unexpected in the case of
	// an abnormal closure (usually triggered by a failure to read/write
	// from/to the client. In this case do not trigger the endpoint's
	// error handling
	if (closeCode != CloseCodes.CLOSED_ABNORMALLY) {
		localEndpoint.onError(this, e);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:15,代码来源:WsSession.java

示例8: onDataAvailable

@Override
public void onDataAvailable() {
	try {
		wsFrame.onDataAvailable();
	} catch (WsIOException ws) {
		wsProtocolHandler.close(ws.getCloseReason());
	} catch (IOException ioe) {
		onError(ioe);
		CloseReason cr = new CloseReason(CloseCodes.CLOSED_ABNORMALLY, ioe.getMessage());
		wsProtocolHandler.close(cr);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:12,代码来源:WsHttpUpgradeHandler.java

示例9: sendCloseMessage

private void sendCloseMessage(CloseReason closeReason) {
    // 125 is maximum size for the payload of a control message
    ByteBuffer msg = ByteBuffer.allocate(125);
    CloseCode closeCode = closeReason.getCloseCode();
    // CLOSED_ABNORMALLY should not be put on the wire
    if (closeCode == CloseCodes.CLOSED_ABNORMALLY) {
        // PROTOCOL_ERROR is probably better than GOING_AWAY here
        msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode());
    } else {
        msg.putShort((short) closeCode.getCode());
    }

    String reason = closeReason.getReasonPhrase();
    if (reason != null && reason.length() > 0) {
        appendCloseReasonWithTruncation(msg, reason);
    }
    msg.flip();
    try {
        wsRemoteEndpoint.startMessageBlock(
                Constants.OPCODE_CLOSE, msg, true);
    } catch (IOException ioe) {
        // Failed to send close message. Close the socket and let the caller
        // deal with the Exception
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("wsSession.sendCloseFail"), ioe);
        }
        wsRemoteEndpoint.close();
        // Failure to send a close message is not unexpected in the case of
        // an abnormal closure (usually triggered by a failure to read/write
        // from/to the client. In this case do not trigger the endpoint's
        // error handling
        if (closeCode != CloseCodes.CLOSED_ABNORMALLY) {
            localEndpoint.onError(this, ioe);
        }
    } finally {
        webSocketContainer.unregisterSession(localEndpoint, this);
    }
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:38,代码来源:WsSession.java

示例10: close

private final void close(Throwable t) {
    CloseReason cr;
    if (t instanceof WsIOException) {
        cr = ((WsIOException) t).getCloseReason();
    } else {
        cr = new CloseReason(
            CloseCodes.CLOSED_ABNORMALLY, t.getMessage());
    }

    try {
        wsSession.close(cr);
    } catch (IOException ignore) {
        // Ignore
    }
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:15,代码来源:WsFrameClient.java

示例11: handleThrowableOnSend

private void handleThrowableOnSend(Throwable t) throws WsIOException {
	ExceptionUtils.handleThrowable(t);
	wsSession.getLocal().onError(wsSession, t);
	CloseReason cr = new CloseReason(CloseCodes.CLOSED_ABNORMALLY, sm.getString("wsFrame.ioeTriggeredClose"));
	throw new WsIOException(cr);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:6,代码来源:WsFrameBase.java


注:本文中的javax.websocket.CloseReason.CloseCodes.CLOSED_ABNORMALLY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。