/** * Called from the {@link Receiver} thread to processing any pending loss of packets. * * @return number of work items processed. */ int processPendingLoss() { int workCount = 0; final long changeNumber = endLossChange; if (changeNumber != lastLossChangeNumber) { final int termId = lossTermId; final int termOffset = lossTermOffset; final int length = lossLength; UNSAFE .loadFence(); // LoadLoad required so previous loads don't move past version check below. if (changeNumber == beginLossChange) { if (isReliable) { channelEndpoint.sendNakMessage( controlAddress, sessionId, streamId, termId, termOffset, length); nakMessagesSent.orderedIncrement(); } else { final UnsafeBuffer termBuffer = termBuffers[indexByTerm(initialTermId, termId)]; if (tryFillGap(rawLog.logMetaData(), termBuffer, termId, termOffset, length)) { lossGapFills.orderedIncrement(); } } lastLossChangeNumber = changeNumber; workCount = 1; } } return workCount; }
/** * Called from the {@link Receiver} to send any pending Status Messages. * * @return number of work items processed. */ int sendPendingStatusMessage() { int workCount = 0; if (ACTIVE == status) { final long changeNumber = endSmChange; if (changeNumber != lastSmChangeNumber) { final long smPosition = nextSmPosition; final int receiverWindowLength = nextSmReceiverWindowLength; UNSAFE.loadFence(); // LoadLoad required so previous loads don't move past version check // below. if (changeNumber == beginSmChange) { final int termId = computeTermIdFromPosition(smPosition, positionBitsToShift, initialTermId); final int termOffset = (int) smPosition & termLengthMask; channelEndpoint.sendStatusMessage( controlAddress, sessionId, streamId, termId, termOffset, receiverWindowLength, (byte) 0); statusMessagesSent.orderedIncrement(); lastSmChangeNumber = changeNumber; workCount = 1; } } } return workCount; }