Exemplo n.º 1
0
        /// <summary>
        /// Append a padding record log of a given length to make up the log to a position.
        /// </summary>
        /// <param name="length"> of the range to claim, in bytes.. </param>
        /// <returns> The new stream position, otherwise a negative error value of <seealso cref="Publication.NOT_CONNECTED"/>,
        /// <seealso cref="Publication.BACK_PRESSURED"/>, <seealso cref="Publication.ADMIN_ACTION"/>, <seealso cref="Publication.CLOSED"/>, or <seealso cref="Publication.MAX_POSITION_EXCEEDED"/>. </returns>
        /// <exception cref="ArgumentException"> if the length is greater than <seealso cref="Publication.MaxMessageLength"/>. </exception>
        public long AppendPadding(int length)
        {
            CheckMaxMessageLength(length);
            long newPosition = CLOSED;

            if (!_isClosed)
            {
                long limit = _positionLimit.GetVolatile();
                ExclusiveTermAppender termAppender = _termAppenders[_activePartitionIndex];
                long position = _termBeginPosition + _termOffset;

                if (position < limit)
                {
                    CheckPositiveLength(length);
                    int result = termAppender.AppendPadding(_termId, _termOffset, _headerWriter, length);
                    newPosition = NewPosition(result);
                }
                else
                {
                    newPosition = BackPressureStatus(position, length);
                }
            }

            return(newPosition);
        }