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 ); } }
@Test public void testSerializeSessionFields() { final MemcachedBackupSession session = (MemcachedBackupSession) _manager.createSession( null ); session.setLastBackupTime( System.currentTimeMillis() ); final byte[] data = TranscoderService.serializeSessionFields( session ); final MemcachedBackupSession deserialized = TranscoderService.deserializeSessionFields(data, _manager ).getSession(); assertSessionFields( session, deserialized ); }
@Test public void testSerializeSessionWithoutAttributes() { final MemcachedBackupSession session = (MemcachedBackupSession) _manager.createSession( null ); session.setLastBackupTime( System.currentTimeMillis() ); final TranscoderService transcoderService = new TranscoderService( new JavaSerializationTranscoder( _manager ) ); final byte[] data = transcoderService.serialize( session ); final MemcachedBackupSession deserialized = transcoderService.deserialize( data, _manager ); assertSessionFields( session, deserialized ); }
@Test public void testSerializeSessionWithAttributes() { final MemcachedBackupSession session = (MemcachedBackupSession) _manager.createSession( null ); final TranscoderService transcoderService = new TranscoderService( new JavaSerializationTranscoder( _manager ) ); final String value = "bar"; session.setAttribute( "foo", value ); session.setLastBackupTime( System.currentTimeMillis() ); final byte[] data = transcoderService.serialize( session ); final MemcachedBackupSession deserialized = transcoderService.deserialize( data, _manager ); assertSessionFields( session, deserialized ); Assert.assertEquals( value, deserialized.getAttribute( "foo" ) ); }
@Test public void testSerializeSessionFieldsWithAuthenticatedPrincipal() { final MemcachedBackupSession session = (MemcachedBackupSession) _manager.createSession( null ); session.setAuthType( HttpServletRequest.FORM_AUTH ); session.setPrincipal( createPrincipal() ); session.setLastBackupTime( System.currentTimeMillis() ); final byte[] data = TranscoderService.serializeSessionFields( session ); final MemcachedBackupSession deserialized = TranscoderService.deserializeSessionFields( data, _manager ).getSession(); assertSessionFields( session, deserialized ); }
session.setLastBackupTime( System.currentTimeMillis() ); try { final ConcurrentMap<String, Object> attributes = session.getAttributesFiltered();
result.setIsValidInternal( decodeBoolean( data, 25 ) ); result.setThisAccessedTimeInternal( decodeNum( data, 26, 8 ) ); result.setLastBackupTime( decodeNum( data, 34, 8 ) );
|| _session.authenticationChanged() ) { _session.setLastBackupTime( System.currentTimeMillis() ); final byte[] data = _transcoderService.serialize( _session, attributesData );
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 ); } }
session.setLastBackupTime( System.currentTimeMillis() ); try { final ConcurrentMap<String, Object> attributes = session.getAttributesFiltered();
result.setIsValidInternal( decodeBoolean( data, 25 ) ); result.setThisAccessedTimeInternal( decodeNum( data, 26, 8 ) ); result.setLastBackupTime( decodeNum( data, 34, 8 ) );
|| _session.authenticationChanged() ) { _session.setLastBackupTime( System.currentTimeMillis() ); final byte[] data = _transcoderService.serialize( _session, attributesData );