本文整理匯總了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);
}
}
示例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);
}
}
示例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));
}
}
示例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);
}
}
}
示例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"));
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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!"));
}
示例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);
}
}
示例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);
}