@Test public void testToMemcachedExpiration() throws Exception { assertEquals(toMemcachedExpiration(60*60*24*30), 60*60*24*30); assertEquals(toMemcachedExpiration(60*60*24*30 + 1), System.currentTimeMillis()/1000 + 60*60*24*30 + 1); } }
public void saveValidityBackup() { final String backupValidityKey = _sessionIdFormat.createBackupKey( _validityKey ); final int maxInactiveInterval = _session.getMaxInactiveInterval(); // fix for #88, along with the change in session.getMemcachedExpirationTimeToSet final int expiration = maxInactiveInterval <= 0 ? 0 : maxInactiveInterval; _storage.set( backupValidityKey, toMemcachedExpiration(expiration), _validityData ); }
public void saveSessionBackup( @Nonnull final MemcachedBackupSession session, @Nonnull final String key ) throws InterruptedException { try { final byte[] data = _manager.serialize( session ); final Future<Boolean> backupResult = _storage.set( key, toMemcachedExpiration(session.getMemcachedExpirationTimeToSet()), data ); if ( !backupResult.get().booleanValue() ) { _log.warn( "Update for secondary backup of session "+ session.getIdInternal() +" (after unsuccessful ping) did not return sucess." ); } } catch ( final ExecutionException e ) { _log.warn( "An exception occurred when trying to update secondary session backup for " + session.getIdInternal(), e ); } } }
@Override public Void call() throws Exception { pingSession( _sessionId ); /* * For non-sticky sessions we store/ping a backup of the session in a secondary memcached node (under a special key * that's resolved by the SuffixBasedNodeLocator), but only when we have more than 1 memcached node configured... */ if ( _storeSecondaryBackup ) { try { pingSessionBackup( _sessionId ); final String backupValidityKey = _sessionIdFormat.createBackupKey( _validityKey ); // fix for #88, along with the change in session.getMemcachedExpirationTimeToSet final int expiration = _maxInactiveInterval <= 0 ? 0 : _maxInactiveInterval; _storage.set( backupValidityKey, toMemcachedExpiration(expiration), _validityData ); } catch( final RuntimeException e ) { _log.info( "Could not store secondary backup of session " + _sessionId, e ); } } return null; }
private void storeSessionInMemcached( final MemcachedBackupSession session, final byte[] data) throws InterruptedException, ExecutionException, TimeoutException { /* calculate the expiration time (instead of using just maxInactiveInterval), as * this is relevant for the update of the expiration time: if we would just use * maxInactiveInterval, the session would exist longer in memcached than it would * be valid in tomcat */ final int expirationTime = session.getMemcachedExpirationTimeToSet(); final long start = System.currentTimeMillis(); try { final Future<Boolean> future = _storage.set( _memcachedNodesManager.getStorageKeyFormat().format(session.getId()), toMemcachedExpiration(expirationTime), data ); if ( !_sessionBackupAsync ) { future.get( _sessionBackupTimeout, TimeUnit.MILLISECONDS ); session.setLastMemcachedExpirationTime( expirationTime ); session.setLastBackupTime( System.currentTimeMillis() ); } else { /* in async mode, we asume the session was stored successfully */ session.setLastMemcachedExpirationTime( expirationTime ); session.setLastBackupTime( System.currentTimeMillis() ); } } finally { _statistics.registerSince( MEMCACHED_UPDATE, start ); } }
final Future<Boolean> validityResult = _storage.set( validityKey, toMemcachedExpiration(expiration), validityData ); if ( !_manager.isSessionBackupAsync() ) { validityResult.get( _manager.getSessionBackupTimeout(), TimeUnit.MILLISECONDS );
public void saveSessionBackupFromResult( final BackupResult backupResult ) { final byte[] data = backupResult.getData(); if ( data != null ) { final String key = _sessionIdFormat.createBackupKey( _session.getId() ); _storage.set( key, toMemcachedExpiration(_session.getMemcachedExpirationTimeToSet()), data ); } else { _log.warn( "No data set for backupResultStatus " + backupResult.getStatus() + " for sessionId " + _session.getIdInternal() + ", skipping backup" + " of non-sticky session in secondary memcached." ); } }
final Future<Boolean> validityResult = _storage.set( validityKey, toMemcachedExpiration(expiration), validityData ); if ( !_manager.isSessionBackupAsync() ) {
public void saveValidityBackup() { final String backupValidityKey = _sessionIdFormat.createBackupKey( _validityKey ); final int maxInactiveInterval = _session.getMaxInactiveInterval(); // fix for #88, along with the change in session.getMemcachedExpirationTimeToSet final int expiration = maxInactiveInterval <= 0 ? 0 : maxInactiveInterval; _storage.set( backupValidityKey, toMemcachedExpiration(expiration), _validityData ); }
public void saveSessionBackup( @Nonnull final MemcachedBackupSession session, @Nonnull final String key ) throws InterruptedException { try { final byte[] data = _manager.serialize( session ); final Future<Boolean> backupResult = _storage.set( key, toMemcachedExpiration(session.getMemcachedExpirationTimeToSet()), data ); if ( !backupResult.get().booleanValue() ) { _log.warn( "Update for secondary backup of session "+ session.getIdInternal() +" (after unsuccessful ping) did not return sucess." ); } } catch ( final ExecutionException e ) { _log.warn( "An exception occurred when trying to update secondary session backup for " + session.getIdInternal(), e ); } } }
@Override public Void call() throws Exception { pingSession( _sessionId ); /* * For non-sticky sessions we store/ping a backup of the session in a secondary memcached node (under a special key * that's resolved by the SuffixBasedNodeLocator), but only when we have more than 1 memcached node configured... */ if ( _storeSecondaryBackup ) { try { pingSessionBackup( _sessionId ); final String backupValidityKey = _sessionIdFormat.createBackupKey( _validityKey ); // fix for #88, along with the change in session.getMemcachedExpirationTimeToSet final int expiration = _maxInactiveInterval <= 0 ? 0 : _maxInactiveInterval; _storage.set( backupValidityKey, toMemcachedExpiration(expiration), _validityData ); } catch( final RuntimeException e ) { _log.info( "Could not store secondary backup of session " + _sessionId, e ); } } return null; }
private void storeSessionInMemcached( final MemcachedBackupSession session, final byte[] data) throws InterruptedException, ExecutionException, TimeoutException { /* calculate the expiration time (instead of using just maxInactiveInterval), as * this is relevant for the update of the expiration time: if we would just use * maxInactiveInterval, the session would exist longer in memcached than it would * be valid in tomcat */ final int expirationTime = session.getMemcachedExpirationTimeToSet(); final long start = System.currentTimeMillis(); try { final Future<Boolean> future = _storage.set( _memcachedNodesManager.getStorageKeyFormat().format(session.getId()), toMemcachedExpiration(expirationTime), data ); if ( !_sessionBackupAsync ) { future.get( _sessionBackupTimeout, TimeUnit.MILLISECONDS ); session.setLastMemcachedExpirationTime( expirationTime ); session.setLastBackupTime( System.currentTimeMillis() ); } else { /* in async mode, we asume the session was stored successfully */ session.setLastMemcachedExpirationTime( expirationTime ); session.setLastBackupTime( System.currentTimeMillis() ); } } finally { _statistics.registerSince( MEMCACHED_UPDATE, start ); } }
final Future<Boolean> validityResult = _storage.set( validityKey, toMemcachedExpiration(expiration), validityData ); if ( !_manager.isSessionBackupAsync() ) { validityResult.get( _manager.getSessionBackupTimeout(), TimeUnit.MILLISECONDS );
public void saveSessionBackupFromResult( final BackupResult backupResult ) { final byte[] data = backupResult.getData(); if ( data != null ) { final String key = _sessionIdFormat.createBackupKey( _session.getId() ); _storage.set( key, toMemcachedExpiration(_session.getMemcachedExpirationTimeToSet()), data ); } else { _log.warn( "No data set for backupResultStatus " + backupResult.getStatus() + " for sessionId " + _session.getIdInternal() + ", skipping backup" + " of non-sticky session in secondary memcached." ); } }
final Future<Boolean> validityResult = _storage.set( validityKey, toMemcachedExpiration(expiration), validityData ); if ( !_manager.isSessionBackupAsync() ) {