public String changeSessionIdOnMemcachedFailover( final String requestedSessionId ) {

    	if ( !_memcachedNodesManager.isEncodeNodeIdInSessionId() ) {
    		return null;
    	}

        try {
            if ( _sticky ) {
                /* We can just lookup the session in the local session map, as we wouldn't get
                 * the session from memcached if the node was not available - or, the other way round,
                 * if we would get the session from memcached, the session would not have to be relocated.
                 */
                final MemcachedBackupSession session = _manager.getSessionInternal( requestedSessionId );

                if ( session != null && session.isValid() ) {
                	final String newSessionId = _memcachedNodesManager.getNewSessionIdIfNodeFromSessionIdUnavailable( session.getId() );
                    if ( newSessionId != null ) {
                        _log.debug( "Session needs to be relocated, setting new id on session..." );
                        session.setIdForRelocate( newSessionId );
                        _statistics.requestWithMemcachedFailover();
                        return newSessionId;
                    }
                }
            } else {

                /* for non-sticky sessions we check the validity info
                 */
                final String nodeId = getSessionIdFormat().extractMemcachedId( requestedSessionId );
                if ( nodeId == null || _memcachedNodesManager.isNodeAvailable( nodeId ) ) {
                    return null;
                }

                _log.info( "Session needs to be relocated as node "+ nodeId +" is not available, loading backup session for " + requestedSessionId );
                final MemcachedBackupSession backupSession = loadBackupSession( requestedSessionId );
                if ( backupSession != null ) {
                    _log.debug( "Loaded backup session for " + requestedSessionId + ", adding locally with "+ backupSession.getIdInternal() +"." );
                    addValidLoadedSession( backupSession, true );
                    _statistics.requestWithMemcachedFailover();
                    return backupSession.getId();
                }
            }

        } catch ( final RuntimeException e ) {
            _log.warn( "Could not find session in local session map.", e );
        }
        return null;
    }
public String changeSessionIdOnMemcachedFailover ( final String requestedSessionId ) { if ( ! _memcachedNodesManager . isEncodeNodeIdInSessionId ( ) ) { return null ; } try { if ( _sticky ) { final MemcachedBackupSession session = _manager . getSessionInternal ( requestedSessionId ) ; if ( session != null && session . isValid ( ) ) { final String newSessionId = _memcachedNodesManager . getNewSessionIdIfNodeFromSessionIdUnavailable ( session . getId ( ) ) ; if ( newSessionId != null ) { _log . debug ( "Session needs to be relocated, setting new id on session..." ) ; session . setIdForRelocate ( newSessionId ) ; _statistics . requestWithMemcachedFailover ( ) ; return newSessionId ; } } } else { final String nodeId = getSessionIdFormat ( ) . extractMemcachedId ( requestedSessionId ) ; if ( nodeId == null || _memcachedNodesManager . isNodeAvailable ( nodeId ) ) { return null ; } _log . info ( "Session needs to be relocated as node " + nodeId + " is not available, loading backup session for " + requestedSessionId ) ; final MemcachedBackupSession backupSession = loadBackupSession ( requestedSessionId ) ; if ( backupSession != null ) { _log . debug ( "Loaded backup session for " + requestedSessionId + ", adding locally with " + backupSession . getIdInternal ( ) + "." ) ; addValidLoadedSession ( backupSession , true ) ; _statistics . requestWithMemcachedFailover ( ) ; return backupSession . getId ( ) ; } } } catch ( final RuntimeException e ) { _log . warn ( "Could not find session in local session map." , e ) ; } return null ; }
Check if the valid session associated with the provided
requested session Id will be relocated with the next {@link #backupSession(Session, boolean)}
and change the session id to the new one (containing the new memcached node). The
new session id must be returned if the session will be relocated and the id was changed.

@param requestedSessionId
the sessionId that was requested.

@return the new session id if the session will be relocated and the id was changed.
Otherwise <code>null</code>.

@see Request#getRequestedSessionId()