Search in sources :

Example 1 with ExpiringSession

use of org.springframework.session.ExpiringSession in project metasfresh-webui-api by metasfresh.

the class FixedMapSessionRepository method createSession.

@Override
public ExpiringSession createSession() {
    final ExpiringSession result = new MapSession();
    if (defaultMaxInactiveInterval != null) {
        result.setMaxInactiveIntervalInSeconds(defaultMaxInactiveInterval);
    }
    // Fire event
    applicationEventPublisher.publishEvent(new SessionCreatedEvent(this, result.getId()));
    return result;
}
Also used : ExpiringSession(org.springframework.session.ExpiringSession) SessionCreatedEvent(org.springframework.session.events.SessionCreatedEvent) MapSession(org.springframework.session.MapSession)

Example 2 with ExpiringSession

use of org.springframework.session.ExpiringSession in project metasfresh-webui-api by metasfresh.

the class FixedMapSessionRepository method getSession.

@Override
public ExpiringSession getSession(final String id) {
    final ExpiringSession saved = sessions.get(id);
    if (saved == null) {
        return null;
    }
    if (saved.isExpired()) {
        final boolean expired = true;
        deleteAndFireEvent(saved.getId(), expired);
        return null;
    }
    return new MapSession(saved);
}
Also used : ExpiringSession(org.springframework.session.ExpiringSession) MapSession(org.springframework.session.MapSession)

Example 3 with ExpiringSession

use of org.springframework.session.ExpiringSession in project metasfresh-webui-api by metasfresh.

the class FixedMapSessionRepository method purgeExpiredSessions.

public void purgeExpiredSessions() {
    final Stopwatch stopwatch = Stopwatch.createStarted();
    int countExpiredSessions = 0;
    final List<ExpiringSession> sessionsToCheck = new ArrayList<>(sessions.values());
    for (final ExpiringSession session : sessionsToCheck) {
        if (session.isExpired()) {
            deleteAndFireEvent(session.getId(), true);
            countExpiredSessions++;
        }
    }
    logger.debug("Purged {}/{} expired sessions in {}", countExpiredSessions, sessionsToCheck.size(), stopwatch);
}
Also used : ExpiringSession(org.springframework.session.ExpiringSession) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList)

Aggregations

ExpiringSession (org.springframework.session.ExpiringSession)3 MapSession (org.springframework.session.MapSession)2 Stopwatch (com.google.common.base.Stopwatch)1 ArrayList (java.util.ArrayList)1 SessionCreatedEvent (org.springframework.session.events.SessionCreatedEvent)1