當前位置: 首頁>>代碼示例>>Java>>正文


Java CloseStatus類代碼示例

本文整理匯總了Java中org.springframework.web.socket.CloseStatus的典型用法代碼示例。如果您正苦於以下問題:Java CloseStatus類的具體用法?Java CloseStatus怎麽用?Java CloseStatus使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CloseStatus類屬於org.springframework.web.socket包,在下文中一共展示了CloseStatus類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleTextMessage

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) {
    try {
        log.info("[{}] Processing {}", session.getId(), message);
        SessionMetaData sessionMd = internalSessionMap.get(session.getId());
        if (sessionMd != null) {
            actorService.process(new TextPluginWebSocketMsg(sessionMd.sessionRef, message.getPayload()));
        } else {
            log.warn("[{}] Failed to find session", session.getId());
            session.close(CloseStatus.SERVER_ERROR.withReason("Session not found!"));
        }
        session.sendMessage(message);
    } catch (IOException e) {
        log.warn("IO error", e);
    }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:17,代碼來源:PluginWebSocketHandler.java

示例2: close

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
@Override
public void close(PluginWebsocketSessionRef sessionRef) throws IOException {
    String externalId = sessionRef.getSessionId();
    log.debug("[{}] Processing close request", externalId);
    String internalId = externalSessionMap.get(externalId);
    if (internalId != null) {
        SessionMetaData sessionMd = internalSessionMap.get(internalId);
        if (sessionMd != null) {
            sessionMd.session.close(CloseStatus.NORMAL);
        } else {
            log.warn("[{}][{}] Failed to find session by internal id", externalId, internalId);
        }
    } else {
        log.warn("[{}] Failed to find session by external id", externalId);
    }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:17,代碼來源:PluginWebSocketHandler.java

示例3: afterConnectionClosed

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
    log.warn("[id={}] Connection was closed, status: {}", session.getId(), closeStatus);

    String chargeBoxId = getChargeBoxId(session);

    futureResponseContextStore.removeSession(session);

    int sizeAfterRemove;

    synchronized (sessionContextLock) {
        sessionContextStore.remove(chargeBoxId, session);
        sizeAfterRemove = sessionContextStore.getSize(chargeBoxId);
    }

    // Take into account that there might be multiple connections to a charging station.
    // Send notification only for the change 1 -> 0.
    if (sizeAfterRemove == 0) {
        disconnectedCallbackList.forEach(consumer -> consumer.accept(chargeBoxId));
    }
}
 
開發者ID:RWTH-i5-IDSG,項目名稱:steve-plugsurfing,代碼行數:22,代碼來源:AbstractWebSocketEndpoint.java

示例4: closeInternal

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
protected void closeInternal(CloseStatus status) {
	if (this.state == null) {
		logger.warn("Ignoring close since connect() was never invoked");
		return;
	}
	if (State.CLOSING.equals(this.state) || State.CLOSED.equals(this.state)) {
		logger.debug("Ignoring close (already closing or closed), current state=" + this.state);
		return;
	}
	this.state = State.CLOSING;
	this.closeStatus = status;
	try {
		disconnect(status);
	}
	catch (Throwable ex) {
		if (logger.isErrorEnabled()) {
			logger.error("Failed to close " + this, ex);
		}
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:AbstractClientSockJsSession.java

示例5: handleOpenFrame

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
private void handleOpenFrame() {
	if (logger.isDebugEnabled()) {
		logger.debug("Processing SockJS open frame in " + this);
	}
	if (State.NEW.equals(state)) {
		this.state = State.OPEN;
		try {
			this.webSocketHandler.afterConnectionEstablished(this);
			this.connectFuture.set(this);
		}
		catch (Throwable ex) {
			if (logger.isErrorEnabled()) {
				Class<?> type = this.webSocketHandler.getClass();
				logger.error(type + ".afterConnectionEstablished threw exception in " + this, ex);
			}
		}
	}
	else {
		if (logger.isDebugEnabled()) {
			logger.debug("Open frame received in " + getId() + " but we're not" +
					"connecting (current state=" + this.state + "). The server might " +
					"have been restarted and lost track of the session.");
		}
		closeInternal(new CloseStatus(1006, "Server lost session"));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:27,代碼來源:AbstractClientSockJsSession.java

示例6: afterTransportClosed

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
public void afterTransportClosed(CloseStatus closeStatus) {
	this.closeStatus = (this.closeStatus != null ? this.closeStatus : closeStatus);
	Assert.state(this.closeStatus != null, "CloseStatus not available");

	if (logger.isDebugEnabled()) {
		logger.debug("Transport closed with " + this.closeStatus + " in " + this);
	}

	this.state = State.CLOSED;
	try {
		this.webSocketHandler.afterConnectionClosed(this, this.closeStatus);
	}
	catch (Exception ex) {
		if (logger.isErrorEnabled()) {
			Class<?> type = this.webSocketHandler.getClass();
			logger.error(type + ".afterConnectionClosed threw an exception", ex);
		}
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:AbstractClientSockJsSession.java

示例7: writeFrame

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
/**
 * For internal use within a TransportHandler and the (TransportHandler-specific)
 * session class.
 */
protected void writeFrame(SockJsFrame frame) throws SockJsTransportFailureException {
	if (logger.isTraceEnabled()) {
		logger.trace("Preparing to write " + frame);
	}
	try {
		writeFrameInternal(frame);
	}
	catch (Throwable ex) {
		logWriteFrameFailure(ex);
		try {
			// Force disconnect (so we won't try to send close frame)
			disconnect(CloseStatus.SERVER_ERROR);
		}
		catch (Throwable disconnectFailure) {
			// Ignore
		}
		try {
			close(CloseStatus.SERVER_ERROR);
		}
		catch (Throwable closeFailure) {
			// Nothing of consequence, already forced disconnect
		}
		throw new SockJsTransportFailureException("Failed to write " + frame, getId(), ex);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:30,代碼來源:AbstractSockJsSession.java

示例8: handleMessage

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
public void handleMessage(TextMessage message, WebSocketSession wsSession) throws Exception {
	String payload = message.getPayload();
	if (StringUtils.isEmpty(payload)) {
		return;
	}
	String[] messages;
	try {
		messages = getSockJsServiceConfig().getMessageCodec().decode(payload);
	}
	catch (Throwable ex) {
		logger.error("Broken data received. Terminating WebSocket connection abruptly", ex);
		tryCloseWithSockJsTransportError(ex, CloseStatus.BAD_DATA);
		return;
	}
	delegateMessages(messages);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:WebSocketServerSockJsSession.java

示例9: handleRequestInternal

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
@Override
public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response,
		AbstractHttpSockJsSession sockJsSession) throws SockJsException {

	String callback = getCallbackParam(request);
	if (!StringUtils.hasText(callback)) {
		response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
		try {
			response.getBody().write("\"callback\" parameter required".getBytes(UTF8_CHARSET));
		}
		catch (IOException ex) {
			sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
			throw new SockJsTransportFailureException("Failed to write to response", sockJsSession.getId(), ex);
		}
		return;
	}

	super.handleRequestInternal(request, response, sockJsSession);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:HtmlFileTransportHandler.java

示例10: handleRequestInternal

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
@Override
public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response,
		AbstractHttpSockJsSession sockJsSession) throws SockJsException {

	try {
		String callback = getCallbackParam(request);
		if (!StringUtils.hasText(callback)) {
			response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
			response.getBody().write("\"callback\" parameter required".getBytes(UTF8_CHARSET));
			return;
		}
	}
	catch (Throwable ex) {
		sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
		throw new SockJsTransportFailureException("Failed to send error", sockJsSession.getId(), ex);
	}

	super.handleRequestInternal(request, response, sockJsSession);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:JsonpPollingTransportHandler.java

示例11: afterConnectionEstablished

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
@Test
public void afterConnectionEstablished() throws Exception {

	@SuppressWarnings("resource")
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
	context.refresh();

	EchoHandler.reset();
	PerConnectionWebSocketHandler handler = new PerConnectionWebSocketHandler(EchoHandler.class);
	handler.setBeanFactory(context.getBeanFactory());

	WebSocketSession session = new TestWebSocketSession();
	handler.afterConnectionEstablished(session);

	assertEquals(1, EchoHandler.initCount);
	assertEquals(0, EchoHandler.destroyCount);

	handler.afterConnectionClosed(session, CloseStatus.NORMAL);

	assertEquals(1, EchoHandler.initCount);
	assertEquals(1, EchoHandler.destroyCount);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:PerConnectionWebSocketHandlerTests.java

示例12: cancelInactivityTasks

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void cancelInactivityTasks() throws Exception {
	TcpConnection<byte[]> tcpConnection = getTcpConnection();

	ScheduledFuture future = mock(ScheduledFuture.class);
	when(this.taskScheduler.scheduleWithFixedDelay(any(), eq(1L))).thenReturn(future);

	tcpConnection.onReadInactivity(mock(Runnable.class), 2L);
	tcpConnection.onWriteInactivity(mock(Runnable.class), 2L);

	this.webSocketHandlerCaptor.getValue().afterConnectionClosed(this.webSocketSession, CloseStatus.NORMAL);

	verify(future, times(2)).cancel(true);
	verifyNoMoreInteractions(future);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:WebSocketStompClientTests.java

示例13: close

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
@Test
public void close() throws Exception {

	this.session.delegateConnectionEstablished();
	assertOpen();

	this.session.setActive(true);
	this.session.close();

	assertEquals(1, this.session.getSockJsFramesWritten().size());
	assertEquals(SockJsFrame.closeFrameGoAway(), this.session.getSockJsFramesWritten().get(0));

	assertEquals(1, this.session.getNumberOfLastActiveTimeUpdates());
	assertTrue(this.session.didCancelHeartbeat());

	assertEquals(new CloseStatus(3000, "Go away!"), this.session.getCloseStatus());
	assertClosed();
	verify(this.webSocketHandler).afterConnectionClosed(this.session, new CloseStatus(3000, "Go away!"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:SockJsSessionTests.java

示例14: afterConnectionClosed

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
  UserSession user = registry.removeBySession(session);
  if (user != null) {
    user.clearRecording();
    roomManager.getRoom(user.getRoomName()).leave(user);
  }
}
 
開發者ID:jake-kent,項目名稱:TLIVideoConferencingv2,代碼行數:9,代碼來源:CallHandler.java

示例15: afterConnectionClosed

import org.springframework.web.socket.CloseStatus; //導入依賴的package包/類
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception
{
	this.webSocketSessionClosedBusinessService.closed(session);

	log.info("Session {} closed with status {}.", session.getId(), status);
}
 
開發者ID:tmply,項目名稱:tmply,代碼行數:8,代碼來源:WebSocketController.java


注:本文中的org.springframework.web.socket.CloseStatus類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。