@ Override public Session get ( String id ) throws Exception { Session session ; Exception ex = null ; while ( true ) { session = doGet ( id ) ; if ( sessionDataStore == null ) { break ; // can't load any session data so just return null or the session object } if ( session == null ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Session " + id + " not found locally, attempting to load" ) ; } // didn't get a session, try and create one and put in a placeholder for it PlaceHolderSession phs = new PlaceHolderSession ( new SessionData ( id , 0 , 0 , 0 , 0 ) ) ; Lock phsLock = phs . lock ( ) ; Session s = doPutIfAbsent ( id , phs ) ; if ( s == null ) { // My placeholder won, go ahead and load the full session data try { session = loadSession ( id ) ; if ( session == null ) { // session does not exist, remove the placeholder doDelete ( id ) ; phsLock . close ( ) ; break ; } try ( Lock ignored = session . lock ( ) ) { // swap it in instead of the placeholder boolean success = doReplace ( id , phs , session ) ; if ( ! success ) { // something has gone wrong, it should have been our placeholder doDelete ( id ) ; session = null ; log . warn ( "Replacement of placeholder for session " + id + " failed" ) ; phsLock . close ( ) ; break ; } else { // successfully swapped in the session session . setResident ( true ) ; session . updateInactivityTimer ( ) ; phsLock . close ( ) ; break ; } } } catch ( Exception e ) { ex = e ; // remember a problem happened loading the session doDelete ( id ) ; // remove the placeholder phsLock . close ( ) ; session = null ; break ; } } else { // my placeholder didn't win, check the session returned phsLock . close ( ) ; try ( Lock ignored = s . lock ( ) ) { // is it a placeholder? or is a non-resident session? In both cases, chuck it away and start again if ( ! s . isResident ( ) || s instanceof PlaceHolderSession ) { continue ; } session = s ; break ; } } } else { // check the session returned try ( Lock ignored = session . lock ( ) ) { // is it a placeholder? or is it passivated? In both cases, chuck it away and start again if ( ! session . isResident ( ) || session instanceof PlaceHolderSession ) { continue ; } // got the session break ; } } } if ( ex != null ) { throw ex ; } return session ; }
Get a session object . If the session object is not in this session store try getting the data for it from a SessionDataStore associated with the session manager .