/** * @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String) */ @Override public boolean exists(String id) throws Exception { String idWithContext = getIdWithContext(id); String filename = _sessionFileMap.get(idWithContext); if (filename == null) return false; //check the expiry long expiry = getExpiryFromFilename(filename); if (expiry <= 0) return true; //never expires else return (expiry > System.currentTimeMillis()); //hasn't yet expired }
/** * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long) */ @Override public void doStore(String id, SessionData data, long lastSaveTime) throws Exception { File file = null; if (_storeDir != null) { delete(id); //make a fresh file using the latest session expiry String filename = getIdWithContextAndExpiry(data); String idWithContext = getIdWithContext(id); file = new File(_storeDir, filename); try(FileOutputStream fos = new FileOutputStream(file,false)) { save(fos, id, data); _sessionFileMap.put(idWithContext, filename); } catch (Exception e) { if (file != null) file.delete(); // No point keeping the file if we didn't save the whole session throw new UnwriteableSessionDataException(id, _context,e); } } }
/** * Delete a session * * @param id session id */ @Override public boolean delete(String id) throws Exception { if (_storeDir != null) { //remove from our map String filename = _sessionFileMap.remove(getIdWithContext(id)); if (filename == null) return false; //remove the file return deleteFile(filename); } return false; }
/** * Get the session id with its context and its expiry time * @param data * @return the session id plus context and expiry */ protected String getIdWithContextAndExpiry (SessionData data) { return ""+data.getExpiry()+"_"+getIdWithContext(data.getId()); }
String filename = _sessionFileMap.get(getIdWithContext(c)); if (filename == null) expired.add(c);
String idWithContext = getIdWithContext(id); String filename = _sessionFileMap.get(idWithContext); if (filename == null)