protected LockingStrategy( @Nonnull final MemcachedSessionService manager, @Nonnull final MemcachedNodesManager memcachedNodesManager, @Nonnull final StorageClient storage, @Nonnull final LRUCache<String, Boolean> missingSessionsCache, final boolean storeSecondaryBackup, @Nonnull final Statistics stats, @Nonnull final CurrentRequest currentRequest ) { _manager = manager; _storage = storage; _missingSessionsCache = missingSessionsCache; _sessionIdFormat = memcachedNodesManager.getSessionIdFormat(); _storeSecondaryBackup = storeSecondaryBackup; _stats = stats; _currentRequest = currentRequest; _storageKeyFormat = memcachedNodesManager.getStorageKeyFormat(); _executor = Executors.newFixedThreadPool( Runtime.getRuntime().availableProcessors(), new NamedThreadFactory("msm-2ndary-backup") ); }
@Override public byte[] get(final String key) { return _storage.get(_memcachedNodesManager.getStorageKeyFormat().format( key )); } };
protected void deleteFromMemcached(final String sessionId) { if ( _enabled.get() && _memcachedNodesManager.isValidForMemcached( sessionId ) ) { if ( _log.isDebugEnabled() ) { _log.debug( "Deleting session from memcached: " + sessionId ); } try { final long start = System.currentTimeMillis(); _storage.delete( _memcachedNodesManager.getStorageKeyFormat().format(sessionId) ).get(); _statistics.registerSince( DELETE_FROM_MEMCACHED, start ); if ( !_sticky ) { _lockingStrategy.onAfterDeleteFromMemcached( sessionId ); } } catch ( final Throwable e ) { _log.info( "Could not delete session from memcached.", e ); } } }
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 ); } }
"\n- node ids: " + _memcachedNodesManager.getPrimaryNodeIds() + "\n- failover node ids: " + _memcachedNodesManager.getFailoverNodeIds() + "\n- storage key prefix: " + _memcachedNodesManager.getStorageKeyFormat().prefix + "\n- locking mode: " + _lockingMode + " (expiration: " + _lockExpiration + "s)" + "\n--------");
final byte[] object = _storage.get( _memcachedNodesManager.getStorageKeyFormat().format( sessionId ) ); _memcachedNodesManager.onLoadFromMemcachedSuccess( sessionId ); _log.warn( "Could not deserialize session with id " + sessionId + " from memcached, session will be purged from storage.", e ); releaseIfLocked( sessionId, lockStatus ); _storage.delete( _memcachedNodesManager.getStorageKeyFormat().format(sessionId) ); _invalidSessionsCache.put( sessionId, Boolean.TRUE ); } catch ( final Exception e ) {
protected LockingStrategy( @Nonnull final MemcachedSessionService manager, @Nonnull final MemcachedNodesManager memcachedNodesManager, @Nonnull final StorageClient storage, @Nonnull final LRUCache<String, Boolean> missingSessionsCache, final boolean storeSecondaryBackup, @Nonnull final Statistics stats, @Nonnull final CurrentRequest currentRequest ) { _manager = manager; _storage = storage; _missingSessionsCache = missingSessionsCache; _sessionIdFormat = memcachedNodesManager.getSessionIdFormat(); _storeSecondaryBackup = storeSecondaryBackup; _stats = stats; _currentRequest = currentRequest; _storageKeyFormat = memcachedNodesManager.getStorageKeyFormat(); _executor = Executors.newFixedThreadPool( Runtime.getRuntime().availableProcessors(), new NamedThreadFactory("msm-2ndary-backup") ); }
@Override public byte[] get(final String key) { return _storage.get(_memcachedNodesManager.getStorageKeyFormat().format( key )); } };
protected void deleteFromMemcached(final String sessionId) { if ( _enabled.get() && _memcachedNodesManager.isValidForMemcached( sessionId ) ) { if ( _log.isDebugEnabled() ) { _log.debug( "Deleting session from memcached: " + sessionId ); } try { final long start = System.currentTimeMillis(); _storage.delete( _memcachedNodesManager.getStorageKeyFormat().format(sessionId) ).get(); _statistics.registerSince( DELETE_FROM_MEMCACHED, start ); if ( !_sticky ) { _lockingStrategy.onAfterDeleteFromMemcached( sessionId ); } } catch ( final Throwable e ) { _log.info( "Could not delete session from memcached.", e ); } } }
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 ); } }
"\n- node ids: " + _memcachedNodesManager.getPrimaryNodeIds() + "\n- failover node ids: " + _memcachedNodesManager.getFailoverNodeIds() + "\n- storage key prefix: " + _memcachedNodesManager.getStorageKeyFormat().prefix + "\n- locking mode: " + _lockingMode + " (expiration: " + _lockExpiration + "s)" + "\n--------");
final byte[] object = _storage.get( _memcachedNodesManager.getStorageKeyFormat().format( sessionId ) ); _memcachedNodesManager.onLoadFromMemcachedSuccess( sessionId ); _log.warn( "Could not deserialize session with id " + sessionId + " from memcached, session will be purged from storage.", e ); releaseIfLocked( sessionId, lockStatus ); _storage.delete( _memcachedNodesManager.getStorageKeyFormat().format(sessionId) ); _invalidSessionsCache.put( sessionId, Boolean.TRUE ); } catch ( final Exception e ) {