Beispiel #1
0
 /// <summary>
 /// 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 <seealso cref="BufferClaim.Commit()"/> should be called thus making it available.
 /// <para>
 /// On successful claim, the Cluster egress header will be written to the start of the claimed buffer section.
 /// Clients <b>MUST</b> write into the claimed buffer region at offset + <seealso cref="AeronCluster.SESSION_HEADER_LENGTH"/>.
 /// <pre>{@code
 ///     final IDirectBuffer srcBuffer = AcquireMessage();
 ///
 ///     if (clientSession.TryClaim(length, bufferClaim) > 0L)
 ///     {
 ///         try
 ///         {
 ///              final IMutableDirectBuffer buffer = bufferClaim.Buffer;
 ///              final int offset = bufferClaim.Offset;
 ///              // ensure that data is written at the correct offset
 ///              buffer.PutBytes(offset + AeronCluster.SESSION_HEADER_LENGTH, srcBuffer, 0, length);
 ///         }
 ///         finally
 ///         {
 ///             bufferClaim.Commit();
 ///         }
 ///     }
 /// }</pre>
 ///
 /// </para>
 /// </summary>
 /// <param name="length">      of the range to claim in bytes. The additional bytes for the session header will be added. </param>
 /// <param name="bufferClaim"> to be populated if the claim succeeds. </param>
 /// <returns> The new stream position, otherwise a negative error value as specified in
 ///         <seealso cref="Publication.TryClaim(int, BufferClaim)"/>.when in <seealso cref="ClusterRole.Leader"/>,
 ///         otherwise <seealso cref="MOCKED_OFFER"/> when a follower.</returns>
 /// <exception cref="ArgumentException"> if the length is greater than <seealso cref="Publication.MaxPayloadLength"/>. </exception>
 /// <seealso cref="Publication.TryClaim(int, BufferClaim)"/>
 /// <seealso cref="BufferClaim.Commit()"/>
 /// <seealso cref="BufferClaim.Abort()"/>
 public long TryClaim(int length, BufferClaim bufferClaim)
 {
     return(_clusteredServiceAgent.TryClaim(Id, _responsePublication, length, bufferClaim));
 }