Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
/**
* Ring-buffer for the concurrent exchanging of binary encoded messages from producer(s) to consumer(s)
* in a FIFO manner.
* <p>
* Provides two non-blocking write methods: {@link #write(int, DirectBuffer, int, int)} for copying a message
* to the ring-buffer, and {@link #tryClaim(int, int)} for zero-copy writes where the caller writes directly
* to the ring-buffer memory. Messages are read by consumers using one of the {@code read} or
* {@code controlledRead} methods.
*/
public interface RingBuffer
{
Expand All @@ -44,6 +49,25 @@ public interface RingBuffer
/**
* Non-blocking write of a message to an underlying ring-buffer.
*
* <p>
* Example usage:
* <pre>{@code
* // Create a ring buffer with a direct buffer of 1024 bytes
* ByteBuffer byteBuffer = ByteBuffer.allocateDirect(1024);
* RingBuffer ringBuffer = new OneToOneRingBuffer(new UnsafeBuffer(byteBuffer));
*
* // Pre-allocate a reusable buffer (cached for the lifetime of the writer)
* MutableDirectBuffer srcBuffer =
* new UnsafeBuffer(ByteBuffer.allocateDirect(Long.BYTES));
*
* // Write a message using the cached buffer
* srcBuffer.putLong(0, 12345L);
* if (!ringBuffer.write(1, srcBuffer, 0, Long.BYTES))
* {
* // Handle insufficient capacity (e.g., retry, log, or drop message)
* }
* }</pre>
*
* @param msgTypeId type of the message encoding.
* @param srcBuffer containing the encoded binary message.
* @param offset at which the encoded message begins.
Expand Down Expand Up @@ -155,11 +179,24 @@ public interface RingBuffer
int read(MessageHandler handler);

/**
* Read as many messages as are available to end of the ring buffer to up a supplied maximum.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this text been changed? No changes should be made to existing documentation unless it is really needed.

* Read as many messages as are available to the end of the ring buffer.
*
* <p>
* If the ring buffer wraps or encounters a type of record, such a padding record, then an implementation
* may choose to return and expect the caller to try again. The {@link #size()} method may be called to
* determine of a backlog of message bytes remains in the ring buffer.
* Example usage:
* <pre>{@code
* ringBuffer.read(
* (msgTypeId, buffer, index, length) ->
* {
* final long value = buffer.getLong(index);
* // Process value
* }
* );
* }</pre>
*
* <p>
* If the ring buffer wraps or encounters a padding record, then an implementation
* may choose to return and expect the caller to try again. The {@link #size()} method
* may be called to determine if a backlog of message bytes remains.
*
* @param handler to be called for processing each message in turn.
* @param messageCountLimit the number of messages will be read in a single invocation.
Expand Down