private Manager getSessionManager(Context context) { // Must be set for the persistent manager to work correctly. System.setProperty("org.apache.catalina.session.StandardSession.ACTIVITY_CHECK", "true"); PersistentManager manager = new PersistentManager(); StoreBase store; // Check if Migration has run and setup JDBC persistence if( !hibernateMigrationService.hasRunSystemMigration("com.tle.tomcat.migration.CreateTomcatSessionEntity") ) { // Use filestore until JDBC setup complete LOGGER.info("Setting up temporary file session store"); FileStore fileStore = new FileStore(); fileStore.setDirectory(System.getProperty("java.io.tmpdir")); store = fileStore; } else { LOGGER.info("Setting up JDBC session store"); JDBCStore jdbcStore = new JDBCStore(); jdbcStore.setConnectionURL(dataSourceService.getSystemUrl()); jdbcStore.setConnectionName(dataSourceService.getSystemUsername()); jdbcStore.setConnectionPassword(dataSourceService.getSystemPassword()); jdbcStore.setDriverName(dataSourceService.getDriverClass()); jdbcStore.setSessionTable("tomcat_sessions"); store = jdbcStore; } manager.setContext(context); manager.setProcessExpiresFrequency(3); // Every 30 seconds manager.setStore(store); // Persist immediately but leave in memory manager.setMaxIdleBackup(0); // Don't remove from memory for 30 minutes manager.setMaxIdleSwap((int) TimeUnit.MINUTES.toSeconds(30)); return manager; }
@Override public void processExpires() { log.debug("Processing expired sessions"); if (store instanceof StoreBase) { ((StoreBase) store).processExpires(); } }