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

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

Introduction

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

Prototype

long getTimeSinceLastActive();

Source Link

Document

Return the time (in ms) since the session was last active, or otherwise if the session is new, then the time since the session was created.

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  w  w  .  j a  v  a  2s. com
        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());
    }
}