public TimedDirContext reCreateDirContext ( TimedDirContext oldCtx , String errorMessage ) throws WIMSystemException { final String METHODNAME = "DirContext reCreateDirContext(String errorMessage)" ; if ( tc . isDebugEnabled ( ) ) { Tr . debug ( tc , METHODNAME + " Communication exception occurs: " + errorMessage + " Creating a new connection." ) ; } try { Long oldCreateTimeStampSeconds = oldCtx . getCreateTimestamp ( ) ; TimedDirContext ctx ; /* * If the old context was created before the context pool was created, then * we can just request a context from the pool. * * If the pool is older than the context, then we should create a new context * and also create a new context pool if context pooling is enabled. */ if ( oldCreateTimeStampSeconds < iPoolCreateTimestampSeconds ) { if ( tc . isDebugEnabled ( ) ) { Tr . debug ( tc , METHODNAME + " Pool refreshed, skip to getDirContext. oldCreateTimeStamp: " + oldCreateTimeStampSeconds + " iPoolCreateTimestampSeconds:" + iPoolCreateTimestampSeconds ) ; } ctx = getDirContext ( ) ; } else { String oldURL = getProviderURL ( oldCtx ) ; ctx = createDirContext ( getEnvironment ( URLTYPE_SEQUENCE , getNextURL ( oldURL ) ) ) ; String newURL = getProviderURL ( ctx ) ; synchronized ( iLock ) { // Refresh context pool if another thread hasn't already done so if ( oldCtx . getCreateTimestamp ( ) >= iPoolCreateTimestampSeconds ) { createContextPool ( iLiveContexts - 1 , newURL ) ; ctx . setCreateTimestamp ( iPoolCreateTimestampSeconds ) ; } } } oldCtx . close ( ) ; if ( tc . isDebugEnabled ( ) ) Tr . debug ( tc , WIMMessageKey . CURRENT_LDAP_SERVER , WIMMessageHelper . generateMsgParms ( getActiveURL ( ) ) ) ; return ctx ; } catch ( NamingException e ) { String msg = Tr . formatMessage ( tc , WIMMessageKey . NAMING_EXCEPTION , WIMMessageHelper . generateMsgParms ( e . toString ( true ) ) ) ; throw new WIMSystemException ( WIMMessageKey . NAMING_EXCEPTION , msg , e ) ; } }
Recreate a Directory context where the oldContext failed with the given error message .