aeron-client/src/main/java/io/aeron/ConcurrentPublication.java
public long tryClaim(final int length, final BufferClaim bufferClaim)
    {
        checkPayloadLength(length);
        long newPosition = CLOSED;

        if (!isClosed)
        {
            final long limit = positionLimit.getVolatile();
            final int termCount = activeTermCount(logMetaDataBuffer);
            final TermAppender termAppender = termAppenders[indexByTermCount(termCount)];
            final long rawTail = termAppender.rawTailVolatile();
            final long termOffset = rawTail & 0xFFFF_FFFFL;
            final int termId = termId(rawTail);
            final long position = computeTermBeginPosition(termId, positionBitsToShift, initialTermId) + termOffset;

            if (termCount != (termId - initialTermId))
            {
                return ADMIN_ACTION;
            }

            if (position < limit)
            {
                final int resultingOffset = termAppender.claim(headerWriter, length, bufferClaim, termId);
                newPosition = newPosition(termCount, (int)termOffset, termId, position, resultingOffset);
            }
            else
            {
                newPosition = backPressureStatus(position, length);
            }
        }

        return newPosition;
    }
public long tryClaim(final int length, final BufferClaim bufferClaim)
    {
        checkPayloadLength(length);
        long newPosition = CLOSED;

        if (!isClosed)
        {
            final long limit = positionLimit.getVolatile();
            final int termCount = activeTermCount(logMetaDataBuffer);
            final TermAppender termAppender = termAppenders[indexByTermCount(termCount)];
            final long rawTail = termAppender.rawTailVolatile();
            final long termOffset = rawTail & 0xFFFF_FFFFL;
            final int termId = termId(rawTail);
            final long position = computeTermBeginPosition(termId, positionBitsToShift, initialTermId) + termOffset;

            if (termCount != (termId - initialTermId))
            {
                return ADMIN_ACTION;
            }

            if (position < limit)
            {
                final int resultingOffset = termAppender.claim(headerWriter, length, bufferClaim, termId);
                newPosition = newPosition(termCount, (int)termOffset, termId, position, resultingOffset);
            }
            else
            {
                newPosition = backPressureStatus(position, length);
            }
        }

        return newPosition;
    }
public long tryClaim ( final int length , final BufferClaim bufferClaim ) { checkPayloadLength ( length ) ; long newPosition = CLOSED ; if ( ! isClosed ) { final long limit = positionLimit . getVolatile ( ) ; final int termCount = activeTermCount ( logMetaDataBuffer ) ; final TermAppender termAppender = termAppenders [ indexByTermCount ( termCount ) ] ; final long rawTail = termAppender . rawTailVolatile ( ) ; final long termOffset = rawTail & 0xFFFF_FFFF L ; final int termId = termId ( rawTail ) ; final long position = computeTermBeginPosition ( termId , positionBitsToShift , initialTermId ) + termOffset ; if ( termCount != ( termId - initialTermId ) ) { return ADMIN_ACTION ; } if ( position < limit ) { final int resultingOffset = termAppender . claim ( headerWriter , length , bufferClaim , termId ) ; newPosition = newPosition ( termCount , ( int ) termOffset , termId , position , resultingOffset ) ; } else { newPosition = backPressureStatus ( position , length ) ; } } return newPosition ; }
Try to claim a range in the publication log into which a message can be written with zero copy semantics.
Once the message has been written then {@link BufferClaim#commit()} should be called thus making it available.
<p>
<b>Note:</b> This method can only be used for message lengths less than MTU length minus header.
If the claim is held for more than the aeron.publication.unblock.timeout system property then the driver will
assume the publication thread is dead and will unblock the claim thus allowing other threads to make progress or
to reach end-of-stream (EOS).
<pre>{@code
final BufferClaim bufferClaim = new BufferClaim(); // Can be stored and reused to avoid allocation

if (publication.tryClaim(messageLength, bufferClaim) > 0L)
{
try
{
final MutableDirectBuffer buffer = bufferClaim.buffer();
final int offset = bufferClaim.offset();

// Work with buffer directly or wrap with a flyweight
}
finally
{
bufferClaim.commit();
}
}
}</pre>

@param length      of the range to claim, in bytes..
@param bufferClaim to be populated if the claim succeeds.
@return The new stream position, otherwise a negative error value of {@link #NOT_CONNECTED},
{@link #BACK_PRESSURED}, {@link #ADMIN_ACTION}, {@link #CLOSED}, or {@link #MAX_POSITION_EXCEEDED}.
@throws IllegalArgumentException if the length is greater than {@link #maxPayloadLength()} within an MTU.
@see BufferClaim#commit()
@see BufferClaim#abort()
Try to claim a range in the publication log into which a message can be written with zero copy semantics . Once the message has been written then { @link BufferClaim#commit () } should be called thus making it available . <p > <b > Note : < / b > This method can only be used for message lengths less than MTU length minus header . If the claim is held for more than the aeron . publication . unblock . timeout system property then the driver will assume the publication thread is dead and will unblock the claim thus allowing other threads to make progress or to reach end - of - stream ( EOS ) . <pre > { @code final BufferClaim bufferClaim = new BufferClaim () ; // Can be stored and reused to avoid allocation