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

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

Introduction

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

Prototype

String getId();

Source Link

Document

Return a unique session identifier.

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  a2  s  .  c  om
        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());
    }
}