本文整理汇总了Java中javax.websocket.CloseReason.CloseCodes类的典型用法代码示例。如果您正苦于以下问题:Java CloseCodes类的具体用法?Java CloseCodes怎么用?Java CloseCodes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CloseCodes类属于javax.websocket.CloseReason包,在下文中一共展示了CloseCodes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessageBinary
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void sendMessageBinary(ByteBuffer msg, boolean last)
throws WsIOException {
if (binaryMsgHandler instanceof WrappedMessageHandler) {
long maxMessageSize =
((WrappedMessageHandler) binaryMsgHandler).getMaxMessageSize();
if (maxMessageSize > -1 && msg.remaining() > maxMessageSize) {
throw new WsIOException(new CloseReason(CloseCodes.TOO_BIG,
sm.getString("wsFrame.messageTooBig",
Long.valueOf(msg.remaining()),
Long.valueOf(maxMessageSize))));
}
}
try {
if (binaryMsgHandler instanceof MessageHandler.Partial<?>) {
((MessageHandler.Partial<ByteBuffer>) binaryMsgHandler).onMessage(msg, last);
} else {
// Caller ensures last == true if this branch is used
((MessageHandler.Whole<ByteBuffer>) binaryMsgHandler).onMessage(msg);
}
} catch(Throwable t) {
handleThrowableOnSend(t);
}
}
示例2: handleSendFailureWithEncode
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
private void handleSendFailureWithEncode(Throwable t) throws IOException, EncodeException {
// First, unwrap any execution exception
if (t instanceof ExecutionException) {
t = t.getCause();
}
// Close the session
wsSession.doClose(new CloseReason(CloseCodes.GOING_AWAY, t.getMessage()),
new CloseReason(CloseCodes.CLOSED_ABNORMALLY, t.getMessage()));
// Rethrow the exception
if (t instanceof EncodeException) {
throw (EncodeException) t;
}
if (t instanceof IOException) {
throw (IOException) t;
}
throw new IOException(t);
}
示例3: destroy
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
/**
* Cleans up the resources still in use by WebSocket sessions created from
* this container. This includes closing sessions and cancelling
* {@link Future}s associated with blocking read/writes.
*/
public void destroy() {
CloseReason cr = new CloseReason(
CloseCodes.GOING_AWAY, sm.getString("wsWebSocketContainer.shutdown"));
for (WsSession session : sessions.keySet()) {
try {
session.close(cr);
} catch (IOException ioe) {
log.debug(sm.getString(
"wsWebSocketContainer.sessionCloseFail", session.getId()), ioe);
}
}
// Only unregister with AsyncChannelGroupUtil if this instance
// registered with it
if (asynchronousChannelGroup != null) {
synchronized (asynchronousChannelGroupLock) {
if (asynchronousChannelGroup != null) {
AsyncChannelGroupUtil.unregister();
asynchronousChannelGroup = null;
}
}
}
}
示例4: testWsCloseThenTcpReset
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
@Test
public void testWsCloseThenTcpReset() throws Exception {
startServer(TestEndpointConfig.class);
TesterWsCloseClient client = new TesterWsCloseClient("localhost", getPort());
client.httpUpgrade(BaseEndpointConfig.PATH);
client.sendCloseFrame(CloseCodes.GOING_AWAY);
client.forceCloseSocket();
// WebSocket 1.1, section 2.1.5 requires this to be CLOSED_ABNORMALLY if
// the container initiates the close and the close code from the client
// if the client initiates it. When the client resets the TCP connection
// after sending the close, different operating systems react different
// ways. Some present the close message then drop the connection, some
// just drop the connection. Therefore, this test has to handle both
// close codes.
awaitOnClose(CloseCodes.CLOSED_ABNORMALLY, CloseCodes.GOING_AWAY);
}
示例5: testWsCloseThenTcpCloseWhenOnMessageSends
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
@Test
public void testWsCloseThenTcpCloseWhenOnMessageSends() throws Exception {
events.onMessageSends = true;
startServer(TestEndpointConfig.class);
TesterWsCloseClient client = new TesterWsCloseClient("localhost", getPort());
client.httpUpgrade(BaseEndpointConfig.PATH);
client.sendMessage("Test");
awaitLatch(events.onMessageCalled, "onMessage not called");
client.sendCloseFrame(CloseCodes.NORMAL_CLOSURE);
client.closeSocket();
events.onMessageWait.countDown();
// BIO will see close from client before it sees the TCP close
awaitOnClose(CloseCodes.CLOSED_ABNORMALLY, CloseCodes.NORMAL_CLOSURE);
}
示例6: testWsCloseThenTcpResetWhenOnMessageSends
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
@Test
public void testWsCloseThenTcpResetWhenOnMessageSends() throws Exception {
events.onMessageSends = true;
startServer(TestEndpointConfig.class);
TesterWsCloseClient client = new TesterWsCloseClient("localhost", getPort());
client.httpUpgrade(BaseEndpointConfig.PATH);
client.sendMessage("Test");
awaitLatch(events.onMessageCalled, "onMessage not called");
client.sendCloseFrame(CloseCodes.NORMAL_CLOSURE);
client.forceCloseSocket();
events.onMessageWait.countDown();
// APR will see close from client before it sees the TCP reset
awaitOnClose(CloseCodes.CLOSED_ABNORMALLY, CloseCodes.NORMAL_CLOSURE);
}
示例7: unregisterUser
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
/**
* When user leaves the activity.
*/
@OnClose
public void unregisterUser(Session websocket, CloseReason reason) {
Long toolContentID = Long
.valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_CONTENT_ID).get(0));
websockets.get(toolContentID).remove(websocket);
if (log.isDebugEnabled()) {
// If there was something wrong with the connection, put it into logs.
log.debug("User " + websocket.getUserPrincipal().getName() + " left Dokumaran with Tool Content ID: "
+ toolContentID
+ (!(reason.getCloseCode().equals(CloseCodes.GOING_AWAY)
|| reason.getCloseCode().equals(CloseCodes.NORMAL_CLOSURE))
? ". Abnormal close. Code: " + reason.getCloseCode() + ". Reason: "
+ reason.getReasonPhrase()
: ""));
}
}
示例8: unregisterUser
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
/**
* When user leaves the activity.
*/
@OnClose
public void unregisterUser(Session websocket, CloseReason reason) {
Long toolSessionId = Long
.valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0));
websockets.get(toolSessionId).remove(websocket);
if (log.isDebugEnabled()) {
// If there was something wrong with the connection, put it into logs.
log.debug("User " + websocket.getUserPrincipal().getName() + " left Leader Selection with Tool Session ID: "
+ toolSessionId
+ (!(reason.getCloseCode().equals(CloseCodes.GOING_AWAY)
|| reason.getCloseCode().equals(CloseCodes.NORMAL_CLOSURE))
? ". Abnormal close. Code: " + reason.getCloseCode() + ". Reason: "
+ reason.getReasonPhrase()
: ""));
}
}
示例9: unregisterUser
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
/**
* If there was something wrong with the connection, put it into logs.
*/
@OnClose
public void unregisterUser(Session session, CloseReason reason) {
Long lessonId = Long.valueOf(session.getRequestParameterMap().get(AttributeNames.PARAM_LESSON_ID).get(0));
Set<Websocket> lessonWebsockets = PresenceWebsocketServer.websockets.get(lessonId);
Iterator<Websocket> websocketIterator = lessonWebsockets.iterator();
while (websocketIterator.hasNext()) {
Websocket websocket = websocketIterator.next();
if (websocket.session.equals(session)) {
websocketIterator.remove();
break;
}
}
if (PresenceWebsocketServer.log.isDebugEnabled()) {
PresenceWebsocketServer.log.debug(
"User " + session.getUserPrincipal().getName() + " left Presence Chat with lessonId: " + lessonId
+ (!(reason.getCloseCode().equals(CloseCodes.GOING_AWAY)
|| reason.getCloseCode().equals(CloseCodes.NORMAL_CLOSURE))
? ". Abnormal close. Code: " + reason.getCloseCode() + ". Reason: "
+ reason.getReasonPhrase()
: ""));
}
}
示例10: unregisterUser
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
/**
* When user leaves the activity.
*/
@OnClose
public void unregisterUser(Session session, CloseReason reason) {
Long toolSessionId = Long
.valueOf(session.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0));
Set<Websocket> sessionWebsockets = LearningWebsocketServer.websockets.get(toolSessionId);
Iterator<Websocket> websocketIterator = sessionWebsockets.iterator();
while (websocketIterator.hasNext()) {
Websocket websocket = websocketIterator.next();
if (websocket.session.equals(session)) {
websocketIterator.remove();
break;
}
}
if (LearningWebsocketServer.log.isDebugEnabled()) {
LearningWebsocketServer.log.debug(
"User " + session.getUserPrincipal().getName() + " left Chat with toolSessionId: " + toolSessionId
+ (!(reason.getCloseCode().equals(CloseCodes.GOING_AWAY)
|| reason.getCloseCode().equals(CloseCodes.NORMAL_CLOSURE))
? ". Abnormal close. Code: " + reason.getCloseCode() + ". Reason: "
+ reason.getReasonPhrase()
: ""));
}
}
示例11: unregisterUser
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
/**
* When user leaves the activity.
*/
@OnClose
public void unregisterUser(Session websocket, CloseReason reason) {
Long toolSessionId = Long
.valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0));
LearningWebsocketServer.websockets.get(toolSessionId).remove(websocket);
if (LearningWebsocketServer.log.isDebugEnabled()) {
// If there was something wrong with the connection, put it into logs.
LearningWebsocketServer.log.debug("User " + websocket.getUserPrincipal().getName()
+ " left Scratchie with Tool Session ID: " + toolSessionId
+ (!(reason.getCloseCode().equals(CloseCodes.GOING_AWAY)
|| reason.getCloseCode().equals(CloseCodes.NORMAL_CLOSURE))
? ". Abnormal close. Code: " + reason.getCloseCode() + ". Reason: "
+ reason.getReasonPhrase()
: ""));
}
}
示例12: unregisterUser
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
/**
* When user leaves the activity.
*/
@OnClose
public void unregisterUser(Session websocket, CloseReason reason) {
Long toolSessionId = Long
.valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0));
LearningWebsocketServer.websockets.get(toolSessionId).remove(websocket);
if (LearningWebsocketServer.log.isDebugEnabled()) {
// If there was something wrong with the connection, put it into logs.
LearningWebsocketServer.log.debug("User " + websocket.getUserPrincipal().getName()
+ " left Scribe with Tool Session ID: " + toolSessionId
+ (!(reason.getCloseCode().equals(CloseCodes.GOING_AWAY)
|| reason.getCloseCode().equals(CloseCodes.NORMAL_CLOSURE))
? ". Abnormal close. Code: " + reason.getCloseCode() + ". Reason: "
+ reason.getReasonPhrase()
: ""));
}
}
示例13: closeWebSocketConnection
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
/**
* Close Websocket connection Connection
* @param session
*/
private void closeWebSocketConnection(final Session session ){
try {
Thread.sleep(3000);
} catch (InterruptedException e1) {
}
if (session != null && session.isOpen()) {
try {
CloseReason closeReason = new CloseReason(
CloseCodes.NORMAL_CLOSURE, "Session Closed");
session.close(closeReason);
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例14: closeWebSocketConnection
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
/**
*
* Close websocket client connection.
* @param session
*/
public void closeWebSocketConnection(Session session){
try {
Thread.sleep(DELAY);
} catch (InterruptedException e1) {
}
if (session != null && session.isOpen()) {
try {
CloseReason closeReason = new CloseReason(CloseCodes.NORMAL_CLOSURE,"Closed");
session.close(closeReason);
logger.info("Session closed");
} catch (IOException e) {
logger.error("Fail to close connection ",e);
}
}
}
示例15: sendMessageText
import javax.websocket.CloseReason.CloseCodes; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void sendMessageText(boolean last) throws WsIOException {
if (textMsgHandler instanceof WrappedMessageHandler) {
long maxMessageSize = ((WrappedMessageHandler) textMsgHandler).getMaxMessageSize();
if (maxMessageSize > -1 && messageBufferText.remaining() > maxMessageSize) {
throw new WsIOException(new CloseReason(CloseCodes.TOO_BIG, sm.getString("wsFrame.messageTooBig",
Long.valueOf(messageBufferText.remaining()), Long.valueOf(maxMessageSize))));
}
}
try {
if (textMsgHandler instanceof MessageHandler.Partial<?>) {
((MessageHandler.Partial<String>) textMsgHandler).onMessage(messageBufferText.toString(), last);
} else {
// Caller ensures last == true if this branch is used
((MessageHandler.Whole<String>) textMsgHandler).onMessage(messageBufferText.toString());
}
} catch (Throwable t) {
handleThrowableOnSend(t);
} finally {
messageBufferText.clear();
}
}