private boolean processQueue ( K key ) { Queue < AsyncResourceRequest < V >> requestQueue = getRequestQueueForKey ( key ) ; if ( requestQueue . isEmpty ( ) ) { return false ; } // Attempt to get a resource. Pool < V > resourcePool = getResourcePoolForKey ( key ) ; V resource = null ; Exception ex = null ; try { // Must attempt non-blocking checkout to ensure resources are // created for the pool. resource = attemptNonBlockingCheckout ( key , resourcePool ) ; } catch ( Exception e ) { destroyResource ( key , resourcePool , resource ) ; ex = e ; resource = null ; } // Neither we got a resource, nor an exception. So no requests can be // processed return if ( resource == null && ex == null ) { return false ; } // With resource in hand, process the resource requests AsyncResourceRequest < V > resourceRequest = getNextUnexpiredResourceRequest ( requestQueue ) ; if ( resourceRequest == null ) { if ( resource != null ) { // Did not use the resource! Directly check in via super to // avoid // circular call to processQueue(). try { super . checkin ( key , resource ) ; } catch ( Exception e ) { logger . error ( "Exception checking in resource: " , e ) ; } } else { // Poor exception, no request to tag this exception onto // drop it on the floor and continue as usual. } return false ; } else { // We have a request here. if ( resource != null ) { resourceRequest . useResource ( resource ) ; } else { resourceRequest . handleException ( ex ) ; } return true ; } }
Attempts to checkout a resource so that one queued request can be serviced .