Example usage for org.springframework.web.socket.sockjs.transport SockJsSession close

List of usage examples for org.springframework.web.socket.sockjs.transport SockJsSession close

Introduction

In this page you can find the example usage for org.springframework.web.socket.sockjs.transport SockJsSession close.

Prototype

@Override
void close() throws IOException;

Source Link

Document

Close the WebSocket connection with status 1000, i.e.

Usage

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

private void scheduleSessionTask() {

    synchronized (this.sessions) {
        if (this.sessionCleanupTask != null) {
            return;
        }//from w ww  . j a  v a 2s.c  o  m
        final List<String> removedSessionIds = new ArrayList<String>();
        this.sessionCleanupTask = getTaskScheduler().scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                for (SockJsSession session : sessions.values()) {
                    try {
                        if (session.getTimeSinceLastActive() > getDisconnectDelay()) {
                            sessions.remove(session.getId());
                            session.close();
                        }
                    } catch (Throwable ex) {
                        logger.error("Failed to close " + session, ex);
                    }
                }
                if (logger.isDebugEnabled() && !removedSessionIds.isEmpty()) {
                    logger.debug("Closed " + removedSessionIds.size() + " sessions " + removedSessionIds);
                    removedSessionIds.clear();
                }
            }
        }, getDisconnectDelay());
    }
}