private synchronized JsMessage [ ] getBatch ( int batchSize , ConversationHelper convHelper ) throws SIResourceException , SIConnectionDroppedException { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . entry ( this , tc , "getBatch" , new Object [ ] { batchSize , convHelper } ) ; if ( batchesReady == 0 ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) SibTr . debug ( this , tc , "No batches are ready!!" ) ; // We are getting a batch of messages from the queue but there are none ready. Oops. SIErrorException e = new SIErrorException ( nls . getFormattedMessage ( "ASYNC_BATCH_NOT_READY_SICO1033" , null , null ) ) ; FFDCFilter . processException ( e , CLASS_NAME + ".getBatch" , CommsConstants . ASYNCHPQ_GETBATCH_01 , this ) ; throw e ; } int currentSessionId = 0 ; JsMessage [ ] msg = new JsMessage [ batchSize ] ; QueueData data = null ; for ( int i = 0 ; i < msg . length ; ++ i ) { data = queue . removeFirst ( ) ; currentSessionId = data . getProxyQueue ( ) . getId ( ) ; msg [ i ] = ( JsMessage ) data . getMessage ( ) ; // Is this the last bit of data? If so - out we go if ( data . isLastInBatch ( ) ) break ; } batchesReady -- ; // Have a quick check and see if there is any data left on the queue. If there is, it is // probably for another session and we should therefore transistion that session into // delivery by calling batch() if ( ! isQueueEmpty ( ) ) { QueueData qd = queue . get ( 0 ) ; AsynchConsumerProxyQueue pq = ( AsynchConsumerProxyQueue ) qd . getProxyQueue ( ) ; if ( pq . getId ( ) != currentSessionId ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) SibTr . debug ( tc , "Next data on the queue is for a different session:" , pq ) ; pq . nudge ( ) ; } } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . exit ( tc , "getBatch" , msg ) ; return msg ; }
Gets a batch of messages from the queue .