/// <inheritdoc />
        public override long Offer(IDirectBuffer bufferOne, int offsetOne, int lengthOne, IDirectBuffer bufferTwo,
                                   int offsetTwo, int lengthTwo, ReservedValueSupplier reservedValueSupplier = null)
        {
            long newPosition = CLOSED;

            if (!_isClosed)
            {
                long limit = _positionLimit.GetVolatile();
                ExclusiveTermAppender termAppender = _termAppenders[_activePartitionIndex];
                long position = _termBeginPosition + _termOffset;
                int  length   = ValidateAndComputeLength(lengthOne, lengthTwo);

                if (position < limit)
                {
                    int result;
                    if (length <= MaxPayloadLength)
                    {
                        CheckPositiveLength(length);
                        result = termAppender.AppendUnfragmentedMessage(
                            _termId,
                            _termOffset,
                            _headerWriter,
                            bufferOne,
                            offsetOne,
                            lengthOne,
                            bufferTwo,
                            offsetTwo,
                            lengthTwo,
                            reservedValueSupplier);
                    }
                    else
                    {
                        CheckMaxMessageLength(length);
                        result = termAppender.AppendFragmentedMessage(
                            _termId,
                            _termOffset,
                            _headerWriter,
                            bufferOne,
                            offsetOne,
                            lengthOne,
                            bufferTwo,
                            offsetTwo,
                            lengthTwo,
                            MaxPayloadLength,
                            reservedValueSupplier);
                    }

                    newPosition = NewPosition(result);
                }
                else
                {
                    newPosition = BackPressureStatus(position, length);
                }
            }

            return(newPosition);
        }
Example #2
0
        /// <inheritdoc />
        public override long Offer(DirectBufferVector[] vectors, ReservedValueSupplier reservedValueSupplier = null)
        {
            int length      = DirectBufferVector.ValidateAndComputeLength(vectors);
            var newPosition = CLOSED;

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

                if (position < limit)
                {
                    int result;
                    if (length <= MaxPayloadLength)
                    {
                        result = termAppender.AppendUnfragmentedMessage(
                            _termId, _termOffset, _headerWriter, vectors, length, reservedValueSupplier);
                    }
                    else
                    {
                        CheckMaxMessageLength(length);
                        result = termAppender.AppendFragmentedMessage(
                            _termId,
                            _termOffset,
                            _headerWriter,
                            vectors,
                            length,
                            MaxPayloadLength,
                            reservedValueSupplier);
                    }

                    newPosition = NewPosition(result);
                }
                else
                {
                    newPosition = BackPressureStatus(position, length);
                }
            }

            return(newPosition);
        }
Example #3
0
        public long Offer(
            UnsafeBuffer buffer,
            int offset,
            int length,
            ReservedValueSupplier reservedValueSupplier = null)
        {
            var newPosition = CLOSED;

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

                if (position < limit)
                {
                    int result;
                    if (length <= MaxPayloadLength)
                    {
                        result = termAppender.AppendUnfragmentedMessage(_termId, _termOffset, _headerWriter, buffer, offset, length, reservedValueSupplier);
                    }
                    else
                    {
                        CheckForMaxMessageLength(length);
                        result = termAppender.AppendFragmentedMessage(_termId, _termOffset, _headerWriter, buffer, offset, length, MaxPayloadLength, reservedValueSupplier);
                    }

                    newPosition = NewPosition(result);
                }
                else if (_conductor.IsPublicationConnected(LogBufferDescriptor.TimeOfLastStatusMessage(_logMetaDataBuffer)))
                {
                    newPosition = BACK_PRESSURED;
                }
                else
                {
                    newPosition = NOT_CONNECTED;
                }
            }

            return(newPosition);
        }
        public long Offer(
            UnsafeBuffer buffer,
            int offset,
            int length,
            ReservedValueSupplier reservedValueSupplier = null)
        {
            var newPosition = CLOSED;

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

                if (position < limit)
                {
                    int result;
                    if (length <= MaxPayloadLength)
                    {
                        result = termAppender.AppendUnfragmentedMessage(_termId, _termOffset, _headerWriter, buffer,
                                                                        offset, length, reservedValueSupplier);
                    }
                    else
                    {
                        CheckForMaxMessageLength(length);
                        result = termAppender.AppendFragmentedMessage(_termId, _termOffset, _headerWriter, buffer,
                                                                      offset, length, MaxPayloadLength, reservedValueSupplier);
                    }

                    newPosition = NewPosition(result);
                }
                else
                {
                    newPosition = BackPressureStatus(position, length);
                }
            }

            return(newPosition);
        }