當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。