@ Override public void put ( String id , Session session ) throws Exception { if ( id == null || session == null ) { throw new IllegalArgumentException ( "Put key=" + id + " session=" + ( session == null ? "null" : session . getId ( ) ) ) ; } try ( Lock ignored = session . lock ( ) ) { if ( ! session . isValid ( ) ) { return ; } if ( sessionDataStore == null ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "No SessionDataStore, putting into SessionCache only id=" + id ) ; } session . setResident ( true ) ; if ( doPutIfAbsent ( id , session ) == null ) { // ensure it is in our map session . updateInactivityTimer ( ) ; } return ; } // don't do anything with the session until the last request for it has finished if ( ( session . getRequests ( ) <= 0 ) ) { // save the session if ( ! sessionDataStore . isPassivating ( ) ) { // if our backing datastore isn't the passivating kind, just save the session sessionDataStore . store ( id , session . getSessionData ( ) ) ; // if we evict on session exit, boot it from the cache if ( getEvictionPolicy ( ) == EVICT_ON_SESSION_EXIT ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Eviction on request exit id=" + id ) ; } doDelete ( session . getId ( ) ) ; session . setResident ( false ) ; } else { session . setResident ( true ) ; if ( doPutIfAbsent ( id , session ) == null ) { // ensure it is in our map session . updateInactivityTimer ( ) ; } if ( log . isDebugEnabled ( ) ) { log . debug ( "Non passivating SessionDataStore, session in SessionCache only id=" + id ) ; } } } else { // backing store supports passivation, call the listeners sessionHandler . willPassivate ( session ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Session passivating id=" + id ) ; } sessionDataStore . store ( id , session . getSessionData ( ) ) ; if ( getEvictionPolicy ( ) == EVICT_ON_SESSION_EXIT ) { // throw out the passivated session object from the map doDelete ( id ) ; session . setResident ( false ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Evicted on request exit id=" + id ) ; } } else { // reactivate the session sessionHandler . didActivate ( session ) ; session . setResident ( true ) ; if ( doPutIfAbsent ( id , session ) == null ) // ensure it is in our map session . updateInactivityTimer ( ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Session reactivated id=" + id ) ; } } } } else { if ( log . isDebugEnabled ( ) ) { log . debug ( "Req count=" + session . getRequests ( ) + " for id=" + id ) ; } session . setResident ( true ) ; if ( doPutIfAbsent ( id , session ) == null ) { // ensure it is the map, but don't save it to the backing store until the last request exists session . updateInactivityTimer ( ) ; } } } }
Put the Session object back into the session store .