/** Constructor. * Construct a SessionHandler witha a HashSessionManager with a standard * java.util.Random generator is created. */ public SessionHandler() { this(new HashSessionManager()); }
public void doStart() throws Exception { _sessions=new HashMap(); super.doStart(); _timer=new Timer(true); setScavengePeriod(getScavengePeriod()); if (_storeDir!=null) { if (!_storeDir.exists()) _storeDir.mkdir(); restoreSessions(); } setSavePeriod(getSavePeriod()); }
public void remove (String id) { if (id==null) return; //all sessions are invalidated when jetty is stopped, make sure we don't //remove all the sessions in this case if (isStopping() || isStopped()) return; if (_storeDir==null || !_storeDir.exists()) { return; } File f = new File(_storeDir, id); f.delete(); }
public void restoreSessions () throws Exception { if (_storeDir==null || !_storeDir.exists()) { return; } if (!_storeDir.canRead()) { Log.warn ("Unable to restore Sessions: Cannot read from Session storage directory "+_storeDir.getAbsolutePath()); return; } File[] files = _storeDir.listFiles(); for (int i=0;files!=null&&i<files.length;i++) { try { FileInputStream in = new FileInputStream(files[i]); Session session = restoreSession(in); in.close(); addSession(session, false); files[i].delete(); } catch (Exception e) { Log.warn("Problem restoring session "+files[i].getName(), e); } } }
public void run() { try { saveSessions(); } catch (Exception e) { Log.warn(e); } } };
public void doStop() throws Exception { if (_storeDir != null) saveSessions(); super.doStop(); _sessions.clear(); _sessions=null; // stop the scavenger synchronized(this) { if (_saveTask!=null) _saveTask.cancel(); if (_task!=null) _task.cancel(); if (_timer!=null) _timer.cancel(); _timer=null; } }
final SessionManager sessionManager = new HashSessionManager(); sessionManager.setIdManager(new HashSessionIdManager()); sessionHandler.setSessionManager(sessionManager);
if (isStopping() || isStopped()) return;
final SessionManager sessionManager = new HashSessionManager(); sessionManager.setIdManager(new HashSessionIdManager()); sessionHandler.setSessionManager(sessionManager);