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


Java CloseReason类代码示例

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


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

示例1: handleSendFailureWithEncode

import javax.websocket.CloseReason; //导入依赖的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);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:20,代码来源:WsRemoteEndpointImplBase.java

示例2: onClose

import javax.websocket.CloseReason; //导入依赖的package包/类
/**
 * Called when a close message is received. Should only ever happen once.
 * Also called after a protocol error when the ProtocolHandler needs to
 * force the closing of the connection.
 */
public void onClose(CloseReason closeReason) {

    synchronized (stateLock) {
        if (state != State.CLOSED) {
            try {
                wsRemoteEndpoint.setBatchingAllowed(false);
            } catch (IOException e) {
                log.warn(sm.getString("wsSession.flushFailOnClose"), e);
                fireEndpointOnError(e);
            }
            if (state == State.OPEN) {
                state = State.OUTPUT_CLOSED;
                sendCloseMessage(closeReason);
                fireEndpointOnClose(closeReason);
            }
            state = State.CLOSED;

            // Close the socket
            wsRemoteEndpoint.close();
        }
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:28,代码来源:WsSession.java

示例3: sendMessageBinary

import javax.websocket.CloseReason; //导入依赖的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);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:25,代码来源:WsFrameBase.java

示例4: onClose

import javax.websocket.CloseReason; //导入依赖的package包/类
@Override
public final void onClose(Session session, CloseReason closeReason) {

    if (methodMapping.getOnClose() != null) {
        try {
            methodMapping.getOnClose().invoke(pojo,
                    methodMapping.getOnCloseArgs(pathParameters, session, closeReason));
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            log.error(sm.getString("pojoEndpointBase.onCloseFail",
                    pojo.getClass().getName()), t);
        }
    }

    // Trigger the destroy method for any associated decoders
    Set<MessageHandler> messageHandlers = session.getMessageHandlers();
    for (MessageHandler messageHandler : messageHandlers) {
        if (messageHandler instanceof PojoMessageHandlerWholeBase<?>) {
            ((PojoMessageHandlerWholeBase<?>) messageHandler).onClose();
        }
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:23,代码来源:PojoEndpointBase.java

示例5: onClose

import javax.websocket.CloseReason; //导入依赖的package包/类
@Override
public final void onClose(Session session, CloseReason closeReason) {

	if (methodMapping.getOnClose() != null) {
		try {
			methodMapping.getOnClose().invoke(pojo,
					methodMapping.getOnCloseArgs(pathParameters, session, closeReason));
		} catch (Throwable t) {
			ExceptionUtils.handleThrowable(t);
			log.error(sm.getString("pojoEndpointBase.onCloseFail", pojo.getClass().getName()), t);
		}
	}

	// Trigger the destroy method for any associated decoders
	Set<MessageHandler> messageHandlers = session.getMessageHandlers();
	for (MessageHandler messageHandler : messageHandlers) {
		if (messageHandler instanceof PojoMessageHandlerWholeBase<?>) {
			((PojoMessageHandlerWholeBase<?>) messageHandler).onClose();
		}
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:22,代码来源:PojoEndpointBase.java

示例6: sendMessageText

import javax.websocket.CloseReason; //导入依赖的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();
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:24,代码来源:WsFrameBase.java

示例7: destroy

import javax.websocket.CloseReason; //导入依赖的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;
            }
        }
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:30,代码来源:WsWebSocketContainer.java

示例8: getReconnecHandler

import javax.websocket.CloseReason; //导入依赖的package包/类
/**
 * @return
 *         Returns an object of Reconnect Handler
 *         Responsible for reconnecting to the server when connection loses
 *         Handle any networking issues as well
 */
private ReconnectHandler getReconnecHandler() {
    ClientManager.ReconnectHandler reconnectHandler = new ClientManager.ReconnectHandler() {
        @Override
        public boolean onDisconnect(CloseReason closeReason) {
            // If we close the session no need to reconnect
            if (WebSocketClient.this.isInterrupted || closeReason.getCloseCode() == CloseReason.CloseCodes.NORMAL_CLOSURE) {
                return false;
            }
            reconnect("Disconnected.... Trying to reconnect .... " + closeReason);
            return true;
        }

        @Override
        public boolean onConnectFailure(Exception exception) {
            if (!WebSocketClient.this.isInterrupted) {
                reconnect("Connection Failure... Attempting to reconnect ..." + exception.toString());
                return true;
            }
            return false;
        }
    };
    return reconnectHandler;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:30,代码来源:WebSocketClient.java

示例9: unregisterUser

import javax.websocket.CloseReason; //导入依赖的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()
			    : ""));
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:LearningWebsocketServer.java

示例10: unregisterUser

import javax.websocket.CloseReason; //导入依赖的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()
			    : ""));
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:LearningWebsocketServer.java

示例11: unregisterUser

import javax.websocket.CloseReason; //导入依赖的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()
				    : ""));
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:PresenceWebsocketServer.java

示例12: unregisterUser

import javax.websocket.CloseReason; //导入依赖的package包/类
@OnClose
   public void unregisterUser(Session websocket, CloseReason reason) throws JSONException, IOException {
String login = websocket.getUserPrincipal().getName();
if (login == null) {
    return;
}

Integer organisationId = Integer
	.valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_ORGANISATION_ID).get(0));
KumaliveDTO kumalive = kumalives.get(organisationId);
if (kumalive == null) {
    return;
}
KumaliveUser user = kumalive.learners.remove(login);
if (user != null) {
    Integer userId = user.userDTO.getUserID();
    if (kumalive.raisedHand != null) {
	kumalive.raisedHand.remove(userId);
    }
    if (userId.equals(kumalive.speaker)) {
	kumalive.speaker = null;
    }
}

sendRefresh(kumalive);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:KumaliveWebsocketServer.java

示例13: unregisterUser

import javax.websocket.CloseReason; //导入依赖的package包/类
/**
    * Removes Learner websocket from the collection.
    */
   @OnClose
   public void unregisterUser(Session session, CloseReason reason) {
String login = session.getUserPrincipal().getName();
if (login == null) {
    return;
}

Long lessonId = Long.valueOf(session.getRequestParameterMap().get(AttributeNames.PARAM_LESSON_ID).get(0));
Map<String, Session> lessonWebsockets = CommandWebsocketServer.websockets.get(lessonId);
if (lessonWebsockets == null) {
    return;
}

lessonWebsockets.remove(login);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:CommandWebsocketServer.java

示例14: unregisterUser

import javax.websocket.CloseReason; //导入依赖的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()
				    : ""));
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:LearningWebsocketServer.java

示例15: unregisterUser

import javax.websocket.CloseReason; //导入依赖的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()
			    : ""));
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:LearningWebsocketServer.java


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