public class RecordBuffer
extends java.lang.Object
The buffer has a position field at the start, then a variable sized header, then a series of records. Each record has a status tag and a key.
NB: its possible for an element to be overwritten as you're reading Out of the buffer, take care.
+----------------------------+ | Header | | ... +----------------------------+ | Position Field | +----------------------------+ | Status Field 0 | +----------------------------+ | Key Field 0 | +----------------------------+ | Record 0 | | ... +----------------------------+ | Status Field 1 | +----------------------------+ | Key Field 1 | +----------------------------+ | Record 1 | | ... +----------------------------+ | ...
Modifier and Type | Class and Description |
---|---|
static interface |
RecordBuffer.RecordHandler
Callback interface for reading elements out of the buffer.
|
static interface |
RecordBuffer.RecordWriter
Interface for safely writing to the buffer.
|
Modifier and Type | Field and Description |
---|---|
static int |
DID_NOT_CLAIM_RECORD |
Constructor and Description |
---|
RecordBuffer(AtomicBuffer buffer,
int headerSize,
int recordSize) |
Modifier and Type | Method and Description |
---|---|
int |
claimRecord(int key)
Claim a record in the buffer.
|
void |
commit(int claimedOffset)
Commit a claimed record into the buffer.
|
void |
forEach(RecordBuffer.RecordHandler handler)
Read each record out of the buffer in turn.
|
int |
get(int key)
Search for the first record with the specified key.
|
void |
initialise()
Initialise the buffer if you're the first thread to begin writing
|
boolean |
isInitialised()
Check if the buffer has been initialised.
|
boolean |
withRecord(int key,
RecordBuffer.RecordWriter writer)
High level and safe way of writing a record to the buffer.
|
public static final int DID_NOT_CLAIM_RECORD
public RecordBuffer(AtomicBuffer buffer, int headerSize, int recordSize)
public void initialise()
public boolean isInitialised()
public void forEach(RecordBuffer.RecordHandler handler)
handler
- the handler is called once for each record in the buffer.public int get(int key)
key
- the key to search for.DID_NOT_CLAIM_RECORD
if no record with
the specified key.public boolean withRecord(int key, RecordBuffer.RecordWriter writer)
key
- the key to associate the record withwriter
- the callback which is passed the record to write.public int claimRecord(int key)
key
- the key to claim the record with.DID_NOT_CLAIM_RECORD
if the claim failed.commit(int)
public void commit(int claimedOffset)
claimedOffset
- the offset of the record to commit.claimRecord(int)
Copyright © 2014-2019 Real Logic Ltd. All Rights Reserved.