/// <inheritdoc /> public override long TryClaim(int length, BufferClaim bufferClaim) { CheckPayloadLength(length); long newPosition = CLOSED; if (!_isClosed) { long limit = _positionLimit.GetVolatile(); int termCount = LogBufferDescriptor.ActiveTermCount(_logMetaDataBuffer); TermAppender termAppender = _termAppenders[LogBufferDescriptor.IndexByTermCount(termCount)]; long rawTail = termAppender.RawTailVolatile(); long termOffset = rawTail & 0xFFFF_FFFFL; int termId = LogBufferDescriptor.TermId(rawTail); long position = LogBufferDescriptor.ComputeTermBeginPosition(termId, PositionBitsToShift, InitialTermId) + termOffset; if (termCount != (termId - InitialTermId)) { return(ADMIN_ACTION); } if (position < limit) { int resultingOffset = termAppender.Claim(_headerWriter, length, bufferClaim, termId); newPosition = NewPosition(termCount, (int)termOffset, termId, position, resultingOffset); } else { newPosition = BackPressureStatus(position, length); } } return(newPosition); }
/// <inheritdoc /> public override long Offer(IDirectBuffer buffer, int offset, int length, ReservedValueSupplier reservedValueSupplier = null) { long newPosition = CLOSED; if (!_isClosed) { long limit = _positionLimit.GetVolatile(); int termCount = LogBufferDescriptor.ActiveTermCount(_logMetaDataBuffer); TermAppender termAppender = _termAppenders[LogBufferDescriptor.IndexByTermCount(termCount)]; long rawTail = termAppender.RawTailVolatile(); long termOffset = rawTail & 0xFFFF_FFFFL; int termId = LogBufferDescriptor.TermId(rawTail); long position = LogBufferDescriptor.ComputeTermBeginPosition(termId, PositionBitsToShift, InitialTermId) + termOffset; if (termCount != (termId - InitialTermId)) { return(ADMIN_ACTION); } if (position < limit) { int resultingOffset; if (length <= MaxPayloadLength) { CheckPositiveLength(length); resultingOffset = termAppender.AppendUnfragmentedMessage( _headerWriter, buffer, offset, length, reservedValueSupplier, termId); } else { CheckMaxMessageLength(length); resultingOffset = termAppender.AppendFragmentedMessage( _headerWriter, buffer, offset, length, MaxPayloadLength, reservedValueSupplier, termId); } newPosition = NewPosition(termCount, (int)termOffset, termId, position, resultingOffset); } else { newPosition = BackPressureStatus(position, length); } } return(newPosition); }
internal ExclusivePublication( ClientConductor clientConductor, string channel, int streamId, int sessionId, IReadablePosition positionLimit, int channelStatusId, LogBuffers logBuffers, long originalRegistrationId, long registrationId) : base( clientConductor, channel, streamId, sessionId, positionLimit, channelStatusId, logBuffers, originalRegistrationId, registrationId, FrameDescriptor.ComputeExclusiveMaxMessageLength(logBuffers.TermLength()) ) { var buffers = logBuffers.DuplicateTermBuffers(); var logMetaDataBuffer = logBuffers.MetaDataBuffer(); for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { _termAppenders[i] = new ExclusiveTermAppender(buffers[i], logMetaDataBuffer, i); } var termCount = LogBufferDescriptor.ActiveTermCount(logMetaDataBuffer); var index = LogBufferDescriptor.IndexByTermCount(termCount); _activePartitionIndex = index; var rawTail = LogBufferDescriptor.RawTail(_logMetaDataBuffer, index); _termId = LogBufferDescriptor.TermId(rawTail); _termOffset = LogBufferDescriptor.TermOffset(rawTail); _termBeginPosition = LogBufferDescriptor.ComputeTermBeginPosition(_termId, _positionBitsToShift, InitialTermId); }