public SessionImpl getSession ( SessionInfo info , boolean create ) { ServletContext key = info . getContext ( ) ; Map < String , SessionImpl > sessions = this . groupings . get ( key ) ; if ( null == sessions ) { synchronized ( this . groupings ) { sessions = this . groupings . get ( key ) ; if ( null == sessions ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "Creating session group: " + key ) ; } sessions = new HashMap < String , SessionImpl > ( ) ; this . groupings . put ( key , sessions ) ; } } // end-sync } SessionImpl session = null ; String id = info . getID ( ) ; if ( null != id ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "getSession: existing id=" + id ) ; } session = sessions . get ( id ) ; if ( null != session ) { // check expiration on existing session if ( session . checkExpiration ( true ) ) { if ( ! session . isInvalid ( ) ) { // if it wasn't already invalidated, do so now session . invalidate ( ) ; } session = null ; } } id = null ; } // check-existing // if we don't have a session now (could have been expired above) // and the create flag is true, make a new one now if ( null == session && create ) { id = this . idgen . getID ( ) ; session = new SessionImpl ( id , info . getContext ( ) ) ; synchronized ( sessions ) { sessions . put ( id , session ) ; } // end-sync // created a session, make sure the purge timer is running if ( null == this . future ) { synchronized ( this . timerLock ) { startPurgeTimer ( ) ; } // end-sync } } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "getSession: " + session ) ; } return session ; }
Access and possibly create if not found a session for the given client information .