Example usage for org.springframework.web.socket CloseStatus SESSION_NOT_RELIABLE

List of usage examples for org.springframework.web.socket CloseStatus SESSION_NOT_RELIABLE

Introduction

In this page you can find the example usage for org.springframework.web.socket CloseStatus SESSION_NOT_RELIABLE.

Prototype

CloseStatus SESSION_NOT_RELIABLE

To view the source code for org.springframework.web.socket CloseStatus SESSION_NOT_RELIABLE.

Click Source Link

Document

A status code for use within the framework the indicate a session has become unreliable (e.g.

Usage

From source file:com.company.project.config.StompDisconnectEvent.java

@Override
public void onApplicationEvent(SessionDisconnectEvent event) {
    StompHeaderAccessor sha = StompHeaderAccessor.wrap(event.getMessage());
    CloseStatus status = event.getCloseStatus();

    if (status.equals(CloseStatus.BAD_DATA)) {
        System.out.println("CloseStatus.BAD_DATA");
    }//from  www.  ja  v  a 2  s.  c om
    if (status.equals(CloseStatus.GOING_AWAY)) {
        System.out.println("CloseStatus.GOING_AWAY");
    }
    if (status.equals(CloseStatus.NORMAL)) {
        System.out.println("CloseStatus.NORMAL");
    }
    if (status.equals(CloseStatus.NOT_ACCEPTABLE)) {
        System.out.println("CloseStatus.NOT_ACCEPTABLE");
    }
    if (status.equals(CloseStatus.NO_CLOSE_FRAME)) {
        System.out.println("CloseStatus.NO_CLOSE_FRAME");
    }
    if (status.equals(CloseStatus.NO_STATUS_CODE)) {
        System.out.println("CloseStatus.NO_STATUS_CODE");
    }
    if (status.equals(CloseStatus.POLICY_VIOLATION)) {
        System.out.println("CloseStatus.POLICY_VIOLATION");
    }
    if (status.equals(CloseStatus.PROTOCOL_ERROR)) {
        System.out.println("CloseStatus.PROTOCOL_ERROR");
    }
    if (status.equals(CloseStatus.REQUIRED_EXTENSION)) {
        System.out.println("CloseStatus.REQUIRED_EXTENSION");
    }
    if (status.equals(CloseStatus.SERVER_ERROR)) {
        System.out.println("CloseStatus.SERVER_ERROR");
    }
    if (status.equals(CloseStatus.SERVICE_RESTARTED)) {
        System.out.println("CloseStatus.SERVICE_RESTARTED");
    }
    if (status.equals(CloseStatus.SESSION_NOT_RELIABLE)) {
        System.out.println("CloseStatus.SESSION_NOT_RELIABLE");
    }
    if (status.equals(CloseStatus.TLS_HANDSHAKE_FAILURE)) {
        System.out.println("CloseStatus.TLS_HANDSHAKE_FAILURE");
    }
    if (status.equals(CloseStatus.TOO_BIG_TO_PROCESS)) {
        System.out.println("CloseStatus.TOO_BIG_TO_PROCESS");
    }

    System.out.println("CloseStatus: " + status);

    logger.debug("Disconnect event [sessionId: " + sha.getSessionId() + " ]");
    System.out.println("Disconnect event [sessionId: " + event.getSessionId() + " ]");
}

From source file:org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.java

private void limitExceeded(String reason) {
    this.limitExceeded = true;
    throw new SessionLimitExceededException(reason, CloseStatus.SESSION_NOT_RELIABLE);
}

From source file:org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.java

@Override
public void close(CloseStatus status) throws IOException {
    this.closeLock.lock();
    try {//w w  w . j a  v  a 2s . c om
        if (this.closeInProgress) {
            return;
        }
        if (!CloseStatus.SESSION_NOT_RELIABLE.equals(status)) {
            try {
                checkSessionLimits();
            } catch (SessionLimitExceededException ex) {
                // Ignore
            }
            if (this.limitExceeded) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Changing close status " + status + " to SESSION_NOT_RELIABLE.");
                }
                status = CloseStatus.SESSION_NOT_RELIABLE;
            }
        }
        this.closeInProgress = true;
        super.close(status);
    } finally {
        this.closeLock.unlock();
    }
}

From source file:org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.java

/**
 * When a session is connected through a higher-level protocol it has a chance
 * to use heartbeat management to shut down sessions that are too slow to send
 * or receive messages. However, after a WebSocketSession is established and
 * before the higher level protocol is fully connected there is a possibility for
 * sessions to hang. This method checks and closes any sessions that have been
 * connected for more than 60 seconds without having received a single message.
 *///from w  ww.j av  a2 s .  co m
private void checkSessions() {
    long currentTime = System.currentTimeMillis();
    if (!isRunning() || (currentTime - this.lastSessionCheckTime < TIME_TO_FIRST_MESSAGE)) {
        return;
    }

    if (this.sessionCheckLock.tryLock()) {
        try {
            for (WebSocketSessionHolder holder : this.sessions.values()) {
                if (holder.hasHandledMessages()) {
                    continue;
                }
                long timeSinceCreated = currentTime - holder.getCreateTime();
                if (timeSinceCreated < TIME_TO_FIRST_MESSAGE) {
                    continue;
                }
                WebSocketSession session = holder.getSession();
                if (logger.isInfoEnabled()) {
                    logger.info("No messages received after " + timeSinceCreated + " ms. " + "Closing "
                            + holder.getSession() + ".");
                }
                try {
                    this.stats.incrementNoMessagesReceivedCount();
                    session.close(CloseStatus.SESSION_NOT_RELIABLE);
                } catch (Throwable ex) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("Failed to close unreliable " + session, ex);
                    }
                }
            }
        } finally {
            this.lastSessionCheckTime = currentTime;
            this.sessionCheckLock.unlock();
        }
    }
}

From source file:org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.java

/**
 * Performs cleanup and notify the {@link WebSocketHandler}.
 */// w  w w  .jav  a 2  s. c o m
@Override
public final void close(CloseStatus status) throws IOException {
    if (isOpen()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Closing SockJS session " + getId() + " with " + status);
        }
        this.state = State.CLOSED;
        try {
            if (isActive() && !CloseStatus.SESSION_NOT_RELIABLE.equals(status)) {
                try {
                    writeFrameInternal(SockJsFrame.closeFrame(status.getCode(), status.getReason()));
                } catch (Throwable ex) {
                    logger.debug("Failure while sending SockJS close frame", ex);
                }
            }
            updateLastActiveTime();
            cancelHeartbeat();
            disconnect(status);
        } finally {
            try {
                this.handler.afterConnectionClosed(this, status);
            } catch (Throwable ex) {
                logger.debug("Error from WebSocketHandler.afterConnectionClosed in " + this, ex);
            }
        }
    }
}