private void createContextPool ( Integer poolSize , String providerURL ) throws NamingException { final String METHODNAME = "createContextPool" ; /* * Validate provider URL */ if ( providerURL == null ) { providerURL = getPrimaryURL ( ) ; } /* * Default the pool size if one was not provided. */ if ( poolSize == null ) { poolSize = DEFAULT_INIT_POOL_SIZE ; } /* * Enable the context pool */ if ( iContextPoolEnabled ) { long currentTimeMillisec = System . currentTimeMillis ( ) ; long currentTimeSeconds = roundToSeconds ( currentTimeMillisec ) ; // Don't purge the pool more than once per second // This prevents multiple threads from purging the pool if ( currentTimeMillisec - iPoolCreateTimestampMillisec > 1000 ) { List < TimedDirContext > contexts = new Vector < TimedDirContext > ( poolSize ) ; Hashtable < String , Object > env = getEnvironment ( URLTYPE_SEQUENCE , providerURL ) ; String currentURL = null ; try { for ( int i = 0 ; i < poolSize ; i ++ ) { TimedDirContext ctx = createDirContext ( env , currentTimeSeconds ) ; currentURL = getProviderURL ( ctx ) ; if ( ! providerURL . equalsIgnoreCase ( currentURL ) ) { env = getEnvironment ( URLTYPE_SEQUENCE , currentURL ) ; providerURL = currentURL ; } contexts . add ( ctx ) ; //iLiveContexts++; } } catch ( NamingException e ) { if ( tc . isDebugEnabled ( ) ) { Tr . debug ( tc , METHODNAME + " Context Pool creation FAILED for " + Thread . currentThread ( ) + ", iLiveContext=" + iLiveContexts , e ) ; } if ( tc . isDebugEnabled ( ) ) { Tr . debug ( tc , METHODNAME + " Cleanup contexts in temp pool: " + contexts . size ( ) ) ; } for ( int j = 0 ; j < contexts . size ( ) ; j ++ ) { try { TimedDirContext ctx = contexts . get ( j ) ; ctx . close ( ) ; } catch ( Exception ee ) { } } throw e ; } iLiveContexts += poolSize ; // set active URL setActiveURL ( providerURL ) ; List < TimedDirContext > oldCtxs = iContexts ; iContexts = contexts ; iPoolCreateTimestampSeconds = currentTimeSeconds ; iPoolCreateTimestampMillisec = currentTimeMillisec ; closeContextPool ( oldCtxs ) ; if ( tc . isDebugEnabled ( ) ) { Tr . debug ( tc , METHODNAME + " Active Provider URL: " + getActiveURL ( ) ) ; Tr . debug ( tc , METHODNAME + " ContextPool: total=" + iLiveContexts + ", poolSize=" + iContexts . size ( ) , ", iPoolCreateTimestampSeconds=" + iPoolCreateTimestampSeconds ) ; } } else if ( tc . isDebugEnabled ( ) ) { Tr . debug ( tc , METHODNAME + " Pool has already been purged within past second... skipping purge" ) ; } } else { setActiveURL ( providerURL ) ; } }
Create a directory context pool of the specified size .