Package de.javakaffee.web.msm.BackupSessionTask

Examples of de.javakaffee.web.msm.BackupSessionTask.BackupResult


        }

        @Override
        public Void call() throws Exception {

            final BackupResult backupResult = _result.get();

            if ( _pingSessionIfBackupWasSkipped ) {
                if ( backupResult.getStatus() == BackupResultStatus.SKIPPED ) {
                    pingSession( _session, _backupSessionService );
                }
            }

            /*
             * For non-sticky sessions we store 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 {
                    if ( _log.isDebugEnabled() ) {
                        _log.debug( "Storing backup in secondary memcached for non-sticky session " + _session.getId() );
                    }
                    if ( backupResult.getStatus() == BackupResultStatus.SKIPPED ) {
                        pingSessionBackup( _session );
                    }
                    else {
                        saveSessionBackupFromResult( backupResult );
                    }
View Full Code Here


            final long startBackup = System.currentTimeMillis();

            final Map<String, Object> attributes = _session.getAttributesFiltered();
            final byte[] attributesData = serializeAttributes( _session, attributes );
            final int hashCode = Arrays.hashCode( attributesData );
            final BackupResult result;
            if ( _session.getDataHashCode() != hashCode
                    || _force
                    || _session.authenticationChanged() ) {

                _session.setLastBackupTime( System.currentTimeMillis() );
                final byte[] data = _transcoderService.serialize( _session, attributesData );

                result = doBackupSession( _session, data, attributesData );
                if ( result.isSuccess() ) {
                    _session.setDataHashCode( hashCode );
                }
            } else {
                result = new BackupResult( BackupResultStatus.SKIPPED );
            }

            switch ( result.getStatus() ) {
                case FAILURE:
                    _statistics.requestWithBackupFailure();
                    _session.backupFailed();
                    break;
                case SKIPPED:
                    _statistics.requestWithoutSessionModification();
                    _session.storeThisAccessedTimeFromLastBackupCheck();
                    break;
                case SUCCESS:
                    _statistics.registerSince( BACKUP, startBackup );
                    _session.storeThisAccessedTimeFromLastBackupCheck();
                    _session.backupFinished();
                    break;
            }

            if ( _log.isDebugEnabled() ) {
                _log.debug( "Finished for session id " + _session.getId() +
                        ", returning status " + result.getStatus() );
            }

            return result;

        } finally {
View Full Code Here

            _log.debug( "Trying to store session in memcached: " + session.getId() );
        }

        try {
            storeSessionInMemcached( session, data );
            return new BackupResult( BackupResultStatus.SUCCESS, data, attributesData );
        } catch (final ExecutionException e) {
            handleException(session, e);
            return new BackupResult(BackupResultStatus.FAILURE, data, null);
        } catch (final TimeoutException e) {
            handleException(session, e);
            return new BackupResult(BackupResultStatus.FAILURE, data, null);
        }
    }
View Full Code Here

        final MemcachedBackupSession session = createSession( service );
        final String sessionId = "12345";
        session.setId(sessionId);
        session.setAttribute( "foo", "bar" );

        final BackupResult backupResult = service.backupSession( session.getIdInternal(), false, null ).get();
        assertEquals(backupResult.getStatus(), BackupResultStatus.SUCCESS);

        final MemcachedBackupSession loadedSession = transcoderService.deserialize((byte[])mc.get(sessionId), _tomcat1.getManager());
        checkSession(loadedSession, session);
    }
View Full Code Here

        final MemcachedBackupSession session = createSession( service );
        final String sessionId = "12345";
        session.setId(sessionId);
        session.setAttribute( "foo", "bar" );

        final BackupResult backupResult = service.backupSession( session.getIdInternal(), false, null ).get();
        assertEquals(backupResult.getStatus(), BackupResultStatus.SUCCESS);

        final MemcachedBackupSession loadedSession = transcoderService.deserialize((byte[])mc.get(sessionId), _tomcat1.getManager());
        checkSession(loadedSession, session);
    }
View Full Code Here

        _log.info( String.format( "Serializing %1$,.3f kb session data for session %2$s took %3$d ms.",
                (double)data.length / 1000, session.getIdInternal(), System.currentTimeMillis() - startSerialization ) );
        _sessionData.put( session.getIdInternal(), data );
        _statistics.registerSince( ATTRIBUTES_SERIALIZATION, startSerialization );
        _statistics.register( CACHED_DATA_SIZE, data.length );
        return new SimpleFuture<BackupResult>( new BackupResult( BackupResultStatus.SUCCESS ) );
    }
View Full Code Here

        @SuppressWarnings( "unchecked" )
        final OperationFuture<Boolean> futureMock = mock( OperationFuture.class );
        when( futureMock.get( anyInt(), any( TimeUnit.class ) ) ).thenThrow(new ExecutionException(new RuntimeException("Simulated exception.")));
        when( _memcachedMock.seteq( session.getId() ), anyInt(), any() ) ).thenReturn( futureMock );

        final BackupResult backupResult = _service.backupSession( session.getIdInternal(), false, null ).get();
        assertEquals(backupResult.getStatus(), BackupResultStatus.FAILURE);
        verify( _memcachedMock, times( 1 ) ).set( eq( session.getId() ), anyInt(), any() );
    }
View Full Code Here

TOP

Related Classes of de.javakaffee.web.msm.BackupSessionTask.BackupResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.