static void putRecordMarkingAndSend ( Channel channel , Xdr rpcRequest ) { // XDR header buffer List < ByteBuffer > buffers = new LinkedList <> ( ) ; buffers . add ( ByteBuffer . wrap ( rpcRequest . getBuffer ( ) , 0 , rpcRequest . getOffset ( ) ) ) ; // payload buffer if ( rpcRequest . getPayloads ( ) != null ) { buffers . addAll ( rpcRequest . getPayloads ( ) ) ; } List < ByteBuffer > outBuffers = new ArrayList <> ( ) ; int bytesToWrite = 0 ; int remainingBuffers = buffers . size ( ) ; boolean isLast = false ; for ( ByteBuffer buffer : buffers ) { if ( bytesToWrite + buffer . remaining ( ) > MTU_SIZE ) { if ( outBuffers . isEmpty ( ) ) { LOG . error ( "too big single byte buffer {}" , buffer . remaining ( ) ) ; throw new IllegalArgumentException ( String . format ( "too big single byte buffer %d" , buffer . remaining ( ) ) ) ; } else { sendBuffers ( channel , bytesToWrite , outBuffers , isLast ) ; bytesToWrite = 0 ; outBuffers . clear ( ) ; } } outBuffers . add ( buffer ) ; bytesToWrite += buffer . remaining ( ) ; remainingBuffers -= 1 ; isLast = ( remainingBuffers == 0 ) ; } // send out remaining buffers if ( ! outBuffers . isEmpty ( ) ) { sendBuffers ( channel , bytesToWrite , outBuffers , true ) ; } }
Insert record marking into rpcRequest and then send to tcp stream .