private void doWork ( boolean hasWritten ) throws SIConnectionDroppedException { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . entry ( this , tc , "doWork" , Boolean . valueOf ( hasWritten ) ) ; final BlockingQueue < Pair < SendListener , Conversation > > readySendCallbacks = new LinkedBlockingQueue < Pair < SendListener , Conversation > > ( ) ; boolean hasGoneAsync = false ; do { boolean hasMoreWork ; do { if ( hasWritten ) { sendCallbacks . drainTo ( readySendCallbacks ) ; } hasWritten = false ; hasMoreWork = false ; synchronized ( priorityQueue ) { synchronized ( this ) { if ( ! isWorkAvailable ( ) ) break ; } } final WsByteBuffer writeBuffer = getWriteContextBuffer ( ) ; writeBuffer . clear ( ) ; if ( dequeueTransmissionData ( writeBuffer ) ) { synchronized ( connectionClosedLock ) { if ( ! connectionClosed ) { writeBuffer . flip ( ) ; if ( connection . isLoggingIOEvents ( ) ) connection . getConnectionEventRecorder ( ) . logDebug ( "invoking writeCtx.write() on context " + System . identityHashCode ( writeCtx ) + " to write all data with no timeout" ) ; final NetworkConnection vc = writeCtx . write ( IOWriteRequestContext . WRITE_ALL_DATA , this , false , IOWriteRequestContext . NO_TIMEOUT ) ; hasGoneAsync = ( vc == null ) ; hasWritten = true ; hasMoreWork = ! hasGoneAsync ; } } } } while ( hasMoreWork ) ; } while ( ! hasGoneAsync && ! switchToIdle ( ) ) ; // This thread is no longer tasked with writing activity, so it is now safe to notify the "ready" send listeners - // i.e. those whose messages have been completely sent. // (It was not safe to do so prior to this point, as the listeners may create more messages to be sent, which // could end in deadlock if this thread were still tasked with the writing.) notifyReadySendListeners ( readySendCallbacks ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . exit ( this , tc , "doWork" ) ; }
Looks to initiate write operations to write all available data from the priority queue to the network . Continues until all data has been sent or until the return from a write call indicates its completion will be asynchronous . Once it has finished writing on this thread calls the registered send listeners for all messages that have been completely sent .