Package io.aeron.logbuffer
Class FrameDescriptor
java.lang.Object
io.aeron.logbuffer.FrameDescriptor
Description of the structure for message framing in a log buffer.
All messages are logged in frames that have a minimum header layout as follows plus a reserve then the encoded message follows:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |R| Frame Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-------------------------------+ | Version |B|E| Flags | Type | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-------------------------------+ |R| Term Offset | +-+-------------------------------------------------------------+ | Additional Fields ... ... | +---------------------------------------------------------------+ | Encoded Message ... ... | +---------------------------------------------------------------+
The (B)egin and (E)nd flags are used for message fragmentation. R is for reserved bit. Both (B)egin and (E)nd flags are set for a message that does not span frames.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final byte
Beginning fragment of a frame.static final byte
End fragment of a frame.static final int
Offset within a frame at which the flags field beginsstatic final int
Alignment as a multiple of bytes for each frame.static final int
Set a pragmatic maximum message length regardless of term length to encourage better design.static final int
Padding frame type to indicate the message should be ignored.static final int
Offset within a frame at which the session id field beginsstatic final int
Offset within a frame at which the term id field beginsstatic final int
Offset within a frame at which the term offset field beginsstatic final int
Offset within a frame at which the type field beginsstatic final byte
End fragment of a frame.static final int
Offset within a frame at which the version field begins -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
computeMaxMessageLength
(int termLength) Compute the maximum supported message length for a buffer of given termLength.static int
flagsOffset
(int termOffset) The buffer offset at which the flags field begins.static byte
frameFlags
(UnsafeBuffer buffer, int termOffset) Get the flags field for a frame.static void
frameFlags
(UnsafeBuffer buffer, int termOffset, byte flags) Write the flags field for a frame.static int
frameLength
(UnsafeBuffer buffer, int termOffset) Get the length of a frame from the header.static void
frameLengthOrdered
(UnsafeBuffer buffer, int termOffset, int frameLength) Write the length header for a frame in a memory ordered fashion.static int
frameLengthVolatile
(UnsafeBuffer buffer, int termOffset) Get the length of a frame from the header as a volatile read.static int
frameSessionId
(UnsafeBuffer buffer, int termOffset) Get the session id of a frame from the header.static void
frameSessionId
(UnsafeBuffer buffer, int termOffset, int sessionId) Write the session id field for a frame.static int
frameTermId
(UnsafeBuffer buffer, int termOffset) Get the term id of a frame from the header.static void
frameTermId
(UnsafeBuffer buffer, int termOffset, int termId) Write the term id field for a frame.static void
frameTermOffset
(UnsafeBuffer buffer, int termOffset) Write the term offset field for a frame.static int
frameType
(UnsafeBuffer buffer, int termOffset) Read the type of the frame from header.static void
frameType
(UnsafeBuffer buffer, int termOffset, int type) Write the type field for a frame.static int
frameVersion
(UnsafeBuffer buffer, int termOffset) Read the type of the frame from header.static boolean
isPaddingFrame
(UnsafeBuffer buffer, int termOffset) Is the frame starting at the termOffset a padding frame at the end of a buffer?static int
lengthOffset
(int termOffset) The buffer offset at which the length field begins.static int
sessionIdOffset
(int termOffset) The buffer offset at which the session id field begins.static int
termIdOffset
(int termOffset) The buffer offset at which the term id field begins.static int
termOffsetOffset
(int termOffset) The buffer offset at which the term offset field begins.static int
typeOffset
(int termOffset) The buffer offset at which the type field begins.static int
versionOffset
(int termOffset) The buffer offset at which the version field begins.
-
Field Details
-
MAX_MESSAGE_LENGTH
public static final int MAX_MESSAGE_LENGTHSet a pragmatic maximum message length regardless of term length to encourage better design. Messages larger than half the cache size should be broken up into chunks and streamed.- See Also:
-
FRAME_ALIGNMENT
public static final int FRAME_ALIGNMENTAlignment as a multiple of bytes for each frame. The length field will store the unaligned length in bytes.- See Also:
-
BEGIN_FRAG_FLAG
public static final byte BEGIN_FRAG_FLAGBeginning fragment of a frame.- See Also:
-
END_FRAG_FLAG
public static final byte END_FRAG_FLAGEnd fragment of a frame.- See Also:
-
UNFRAGMENTED
public static final byte UNFRAGMENTEDEnd fragment of a frame.- See Also:
-
VERSION_OFFSET
public static final int VERSION_OFFSETOffset within a frame at which the version field begins- See Also:
-
FLAGS_OFFSET
public static final int FLAGS_OFFSETOffset within a frame at which the flags field begins- See Also:
-
TYPE_OFFSET
public static final int TYPE_OFFSETOffset within a frame at which the type field begins- See Also:
-
TERM_OFFSET
public static final int TERM_OFFSETOffset within a frame at which the term offset field begins- See Also:
-
TERM_ID_OFFSET
public static final int TERM_ID_OFFSETOffset within a frame at which the term id field begins- See Also:
-
SESSION_ID_OFFSET
public static final int SESSION_ID_OFFSETOffset within a frame at which the session id field begins- See Also:
-
PADDING_FRAME_TYPE
public static final int PADDING_FRAME_TYPEPadding frame type to indicate the message should be ignored.- See Also:
-
-
Constructor Details
-
FrameDescriptor
public FrameDescriptor()
-
-
Method Details
-
computeMaxMessageLength
public static int computeMaxMessageLength(int termLength) Compute the maximum supported message length for a buffer of given termLength.- Parameters:
termLength
- of the log buffer.- Returns:
- the maximum supported length for a message.
-
lengthOffset
public static int lengthOffset(int termOffset) The buffer offset at which the length field begins.- Parameters:
termOffset
- at which the frame begins.- Returns:
- the offset at which the length field begins.
-
versionOffset
public static int versionOffset(int termOffset) The buffer offset at which the version field begins.- Parameters:
termOffset
- at which the frame begins.- Returns:
- the offset at which the version field begins.
-
flagsOffset
public static int flagsOffset(int termOffset) The buffer offset at which the flags field begins.- Parameters:
termOffset
- at which the frame begins.- Returns:
- the offset at which the flags field begins.
-
typeOffset
public static int typeOffset(int termOffset) The buffer offset at which the type field begins.- Parameters:
termOffset
- at which the frame begins.- Returns:
- the offset at which the type field begins.
-
termOffsetOffset
public static int termOffsetOffset(int termOffset) The buffer offset at which the term offset field begins.- Parameters:
termOffset
- at which the frame begins.- Returns:
- the offset at which the term offset field begins.
-
termIdOffset
public static int termIdOffset(int termOffset) The buffer offset at which the term id field begins.- Parameters:
termOffset
- at which the frame begins.- Returns:
- the offset at which the term id field begins.
-
sessionIdOffset
public static int sessionIdOffset(int termOffset) The buffer offset at which the session id field begins.- Parameters:
termOffset
- at which the frame begins.- Returns:
- the offset at which the session id field begins.
-
frameVersion
Read the type of the frame from header.- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.- Returns:
- the value of the frame type header.
-
frameFlags
Get the flags field for a frame.- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.- Returns:
- the value of the flags.
-
frameType
Read the type of the frame from header.- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.- Returns:
- the value of the frame type header.
-
isPaddingFrame
Is the frame starting at the termOffset a padding frame at the end of a buffer?- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.- Returns:
- true if the frame is a padding frame otherwise false.
-
frameLength
Get the length of a frame from the header.- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.- Returns:
- the value for the frame length.
-
frameTermId
Get the term id of a frame from the header.- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.- Returns:
- the value for the term id field.
-
frameSessionId
Get the session id of a frame from the header.- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.- Returns:
- the value for the session id field.
-
frameLengthVolatile
Get the length of a frame from the header as a volatile read.- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.- Returns:
- the value for the frame length.
-
frameLengthOrdered
Write the length header for a frame in a memory ordered fashion.- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.frameLength
- field to be set for the frame.
-
frameType
Write the type field for a frame.- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.type
- type value for the frame.
-
frameFlags
Write the flags field for a frame.- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.flags
- value for the frame.
-
frameTermOffset
Write the term offset field for a frame.- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.
-
frameTermId
Write the term id field for a frame.- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.termId
- value for the frame.
-
frameSessionId
Write the session id field for a frame.- Parameters:
buffer
- containing the frame.termOffset
- at which a frame begins.sessionId
- value for the frame.
-