/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package ee.tlu.htk.dippler.schedulers; import ee.tlu.htk.dippler.backoffice.SessionInfo; import ee.tlu.htk.dippler.backoffice.SessionKeeperLocal; import ee.tlu.htk.dippler.utils.Utility; import java.util.Date; import java.util.Iterator; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import javax.ejb.EJB; import javax.ejb.Schedule; import javax.ejb.Singleton; /** * * @author raido */ @Singleton public class ExpiredSessionCleaner { @EJB private SessionKeeperLocal sessionKeeper; @Schedule(minute = "*/15", hour="*", info = "Every 15 minutes") private void run() { ConcurrentHashMap sessions = sessionKeeper.getAllSessions(); System.out.println("CLEANING UP SESSIONS AT " + new Date().toString()); System.out.println("ACTIVE SESSIONS COUNT " + sessions.size()); int killed_count = 0; Iterator it = sessions.entrySet().iterator(); while (it.hasNext()) { Entry mapEntry = (Entry) it.next(); SessionInfo session = mapEntry.getValue(); if ((Utility.getTime() - session.getActivityTime()) >= 3600) { //1 hour session limit sessionKeeper.destroySession(session.getId()); killed_count++; } } System.out.println("TOTAL SESSIONS KILLED " + killed_count); System.out.println("ACTIVE SESSIONS LEFT " + sessionKeeper.getAllSessions().size()); } }