Ejemplo n.º 1
0
        public int Claim(
            int termId,
            int termOffset,
            HeaderWriter header,
            int length,
            BufferClaim bufferClaim)
        {
            int          frameLength   = length + DataHeaderFlyweight.HEADER_LENGTH;
            int          alignedLength = BitUtil.Align(frameLength, FrameDescriptor.FRAME_ALIGNMENT);
            UnsafeBuffer termBuffer    = _termBuffer;
            int          termLength    = termBuffer.Capacity;

            int resultingOffset = termOffset + alignedLength;

            PutRawTailOrdered(termId, resultingOffset);

            if (resultingOffset > termLength)
            {
                resultingOffset = HandleEndOfLogCondition(termBuffer, termOffset, header, termLength, termId);
            }
            else
            {
                header.Write(termBuffer, termOffset, frameLength, termId);
                bufferClaim.Wrap(termBuffer, termOffset, frameLength);
            }

            return(resultingOffset);
        }
Ejemplo n.º 2
0
        public long Claim(HeaderWriter header, int length, BufferClaim bufferClaim)
        {
            int  frameLength   = length + DataHeaderFlyweight.HEADER_LENGTH;
            int  alignedLength = BitUtil.Align(frameLength, FrameDescriptor.FRAME_ALIGNMENT);
            long rawTail       = GetAndAddRawTail(alignedLength);
            long termOffset    = rawTail & 0xFFFFFFFFL;

            UnsafeBuffer termBuffer = _termBuffer;
            int          termLength = termBuffer.Capacity;

            long resultingOffset = termOffset + alignedLength;

            if (resultingOffset > termLength)
            {
                resultingOffset = HandleEndOfLogCondition(termBuffer, termOffset, header, termLength, LogBufferDescriptor.TermId(rawTail));
            }
            else
            {
                int offset = (int)termOffset;
                header.Write(termBuffer, offset, frameLength, LogBufferDescriptor.TermId(rawTail));
                bufferClaim.Wrap(termBuffer, offset, frameLength);
            }

            return(resultingOffset);
        }