7#include "concurrent/logbuffer/LogBufferDescriptor.h"
10#include "org_limitless_seqeron_sbe_frame/ApplicationRegistered.h"
11#include "org_limitless_seqeron_sbe_frame/ClusterHeartbeat.h"
12#include "org_limitless_seqeron_sbe_frame/ClusterStarted.h"
13#include "org_limitless_seqeron_sbe_frame/ClusterStopped.h"
14#include "org_limitless_seqeron_sbe_frame/ConnectionClosed.h"
15#include "org_limitless_seqeron_sbe_frame/ConnectionOpened.h"
16#include "org_limitless_seqeron_sbe_frame/GatewayActivationRequested.h"
17#include "org_limitless_seqeron_sbe_frame/GatewayActive.h"
18#include "org_limitless_seqeron_sbe_frame/GatewayRegistered.h"
19#include "org_limitless_seqeron_sbe_frame/GatewayStarted.h"
20#include "org_limitless_seqeron_sbe_frame/GroupsRegistered.h"
21#include "org_limitless_seqeron_sbe_frame/LeadershipChanged.h"
22#include "org_limitless_seqeron_sbe_frame/MessageHeader.h"
23#include "org_limitless_seqeron_sbe_frame/PayloadIdRegistered.h"
24#include "org_limitless_seqeron_sbe_frame/Sequenced.h"
25#include "org_limitless_seqeron_sbe_frame/SequencedHeader.h"
26#include "org_limitless_seqeron_sbe_frame/SequencedSystem.h"
27#include "org_limitless_seqeron_sbe_frame/SequencedSystemHeader.h"
28#include "org_limitless_seqeron_sbe_frame/SessionClosed.h"
29#include "org_limitless_seqeron_sbe_frame/SnapshotEnd.h"
30#include "org_limitless_seqeron_sbe_frame/SnapshotPolicyRegistered.h"
31#include "org_limitless_seqeron_sbe_frame/SnapshotRequested.h"
32#include "org_limitless_seqeron_sbe_frame/SnapshotStarted.h"
33#include "org_limitless_seqeron_sbe_frame/Unsequenced.h"
34#include "org_limitless_seqeron_sbe_frame/UnsequencedHeader.h"
47inline constexpr const char*
QUEUE_CHANNEL =
"aeron:ipc?alias=seqeron-queue";
85 sbe::frame::MessageHeader::encodedLength() + sbe::frame::UnsequencedHeader::encodedLength() +
86 sbe::frame::Unsequenced::payloadHeaderLength());
96inline constexpr std::uint16_t
CONNECTION_OPENED = sbe::frame::ConnectionOpened::sbeTemplateId();
97inline constexpr std::uint16_t
CONNECTION_CLOSED = sbe::frame::ConnectionClosed::sbeTemplateId();
99inline constexpr std::uint16_t
CLUSTER_STARTED = sbe::frame::ClusterStarted::sbeTemplateId();
100inline constexpr std::uint16_t
CLUSTER_STOPPED = sbe::frame::ClusterStopped::sbeTemplateId();
104inline constexpr std::uint16_t
GATEWAY_STARTED = sbe::frame::GatewayStarted::sbeTemplateId();
109inline constexpr std::uint16_t
SNAPSHOT_END = sbe::frame::SnapshotEnd::sbeTemplateId();
113inline constexpr std::uint16_t
GROUPS_REGISTERED = sbe::frame::GroupsRegistered::sbeTemplateId();
127 switch (systemEventType)
130 return sbe::frame::ConnectionOpened::sbeBlockLength();
132 return sbe::frame::ConnectionClosed::sbeBlockLength();
134 return sbe::frame::ClusterStarted::sbeBlockLength();
136 return sbe::frame::ClusterStopped::sbeBlockLength();
138 return sbe::frame::GatewayRegistered::sbeBlockLength();
140 return sbe::frame::GatewayStarted::sbeBlockLength();
142 return sbe::frame::PayloadIdRegistered::sbeBlockLength();
144 return sbe::frame::GatewayActivationRequested::sbeBlockLength();
146 return sbe::frame::ApplicationRegistered::sbeBlockLength();
148 return sbe::frame::SnapshotRequested::sbeBlockLength();
150 return sbe::frame::SnapshotEnd::sbeBlockLength();
152 return sbe::frame::SnapshotPolicyRegistered::sbeBlockLength();
154 return sbe::frame::GroupsRegistered::sbeBlockLength();
262 char*
const bytes =
const_cast<char*
>(frame);
263 if (length < sbe::frame::MessageHeader::encodedLength())
268 sbe::frame::MessageHeader hdr;
269 hdr.wrap(bytes, 0U, 0U, length);
270 if (hdr.schemaId() != sbe::frame::Sequenced::sbeSchemaId())
274 const std::uint64_t blockOffset = sbe::frame::MessageHeader::encodedLength();
275 const std::uint16_t frameTemplateId = hdr.templateId();
277 if (frameTemplateId == sbe::frame::Sequenced::sbeTemplateId())
279 if (length < sbe::frame::Sequenced::sbeBlockAndHeaderLength() + sbe::frame::Sequenced::payloadHeaderLength())
283 sbe::frame::Sequenced sequenced;
284 sequenced.wrapForDecode(bytes, blockOffset, hdr.blockLength(), hdr.version(), length);
285 sbe::frame::SequencedHeader& header = sequenced.header();
286 view.payloadId = header.payloadId();
287 view.sourceId = header.sourceId();
288 view.connectionId = header.connectionId();
289 view.groupMask = header.groupMask();
290 view.sourceSessionId = header.sessionId();
291 view.clusterSeqNo = header.clusterSeqNo();
292 view.groupSeqNo = header.groupSeqNo();
293 view.clusterTimestampNs = header.timestamp();
295 const std::uint64_t payloadLength = sequenced.payloadLength();
299 if (sbe::frame::Sequenced::sbeBlockAndHeaderLength() + sbe::frame::Sequenced::payloadHeaderLength() +
305 const char*
const payload = sequenced.payload();
306 view.payload = payload;
307 view.payloadLength = payloadLength;
311 if (payloadLength < sbe::frame::MessageHeader::encodedLength())
315 sbe::frame::MessageHeader payloadHdr;
316 payloadHdr.wrap(
const_cast<char*
>(payload), 0U, 0U, payloadLength);
317 view.templateId = payloadHdr.templateId();
318 view.blockLength = payloadHdr.blockLength();
319 view.version = payloadHdr.version();
323 if (frameTemplateId == sbe::frame::SequencedSystem::sbeTemplateId())
326 sbe::frame::SequencedSystem::sbeBlockAndHeaderLength() + sbe::frame::SequencedSystem::bodyHeaderLength())
330 sbe::frame::SequencedSystem sequenced;
331 sequenced.wrapForDecode(bytes, blockOffset, hdr.blockLength(), hdr.version(), length);
335 const std::uint64_t bodyLength = sequenced.bodyLength();
336 if (sbe::frame::SequencedSystem::sbeBlockAndHeaderLength() + sbe::frame::SequencedSystem::bodyHeaderLength() +
342 view.payloadLength = bodyLength;
343 view.payload = sequenced.body();
348 if (frameTemplateId == sbe::frame::ClusterHeartbeat::sbeTemplateId() ||
349 frameTemplateId == sbe::frame::LeadershipChanged::sbeTemplateId() ||
350 frameTemplateId == sbe::frame::GatewayActive::sbeTemplateId() ||
351 frameTemplateId == sbe::frame::SnapshotStarted::sbeTemplateId() ||
352 frameTemplateId == sbe::frame::SessionClosed::sbeTemplateId())
354 if (length < blockOffset + sbe::frame::SequencedSystemHeader::encodedLength())
358 sbe::frame::SequencedSystemHeader header;
359 header.wrap(bytes, blockOffset, hdr.version(), length);
363 view.payload = frame + blockOffset;
364 view.payloadLength = length - blockOffset;
379template<
typename Decoder>
380Decoder
decodeSequenced(
const char* payload,
const std::uint64_t payloadLength,
const std::uint16_t blockLength,
381 const std::uint16_t version)
384 decoder.wrapForDecode(
const_cast<char*
>(payload), sbe::frame::MessageHeader::encodedLength(), blockLength, version,
398template<
typename Decoder>
399Decoder
decodeSystem(
const char* message,
const std::uint64_t messageLength)
402 decoder.wrapForDecode(
const_cast<char*
>(message), 0, Decoder::sbeBlockLength(), Decoder::sbeSchemaVersion(),
413template<
typename Decoder>
426template<
typename Decoder>
439 return aeron::concurrent::logbuffer::LogBufferDescriptor::computePosition(
440 header.termId(), header.termOffset(), header.positionBitsToShift(), header.initialTermId());
472template<
typename Decoder>
488 const std::int64_t position)
497 .receiveTimeNs = receiveTimeNs,
506 .position = position };
522 .receiveTimeNs = receiveTimeNs,
530 using namespace std::chrono;
531 return duration_cast<nanoseconds>(system_clock::now().time_since_epoch()).count();
Definition ProxyProtocol.hpp:8
constexpr std::int32_t ingressBlockLength(const std::uint16_t systemEventType)
Looks up the compiled block length of a submittable system event: §9.2 conditions 8 and 9 in one look...
Definition SequencedFrame.hpp:125
constexpr std::uint16_t GATEWAY_STARTED
Definition SequencedFrame.hpp:104
constexpr std::uint16_t SESSION_CLOSED
Definition SequencedFrame.hpp:112
constexpr std::uint16_t LEADERSHIP_CHANGED
Definition SequencedFrame.hpp:98
constexpr std::int32_t MAX_GROUPS
Definition SequencedFrame.hpp:50
constexpr std::uint16_t CONNECTION_CLOSED
Definition SequencedFrame.hpp:97
SequencedEvent sequencedEventOf(const FrameView &view, const std::int64_t receiveTimeNs, const std::int64_t position)
Fills a SequencedEvent from an unwrapped frame, plus the two stamps that belong to the delivery rathe...
Definition SequencedFrame.hpp:487
constexpr std::uint16_t CONNECTION_OPENED
Definition SequencedFrame.hpp:96
constexpr std::uint16_t GROUPS_REGISTERED
Definition SequencedFrame.hpp:113
constexpr std::uint16_t MAX_INGRESS_LENGTH
Definition SequencedFrame.hpp:89
constexpr std::int32_t NOT_INGRESS_LEGAL
Definition SequencedFrame.hpp:116
constexpr std::uint16_t PAYLOAD_ID_REGISTERED
Definition SequencedFrame.hpp:105
constexpr std::uint16_t SNAPSHOT_STARTED
Definition SequencedFrame.hpp:111
constexpr std::uint16_t MAX_PAYLOAD_LENGTH
Definition SequencedFrame.hpp:79
constexpr std::uint16_t SNAPSHOT_END
Definition SequencedFrame.hpp:109
std::int64_t frameStartPosition(const aeron::Header &header)
Computes the stream position of a frame's first byte; what SequencedEvent::position carries.
Definition SequencedFrame.hpp:437
constexpr std::uint16_t GATEWAY_ACTIVATION_REQUESTED
Definition SequencedFrame.hpp:106
constexpr std::uint16_t GATEWAY_ACTIVE
Definition SequencedFrame.hpp:103
constexpr std::uint16_t CLUSTER_STARTED
Definition SequencedFrame.hpp:99
FrameView unwrapFrame(const char *const frame, const std::uint64_t length)
Reads one fragment into a FrameView, stripping the envelope.
Definition SequencedFrame.hpp:259
LifecycleEvent lifecycleEventOf(const FrameView &view, const std::int64_t receiveTimeNs)
Fills a LifecycleEvent from an unwrapped ConnectionOpened/ConnectionClosed.
Definition SequencedFrame.hpp:515
Decoder decodeSystem(const char *message, const std::uint64_t messageLength)
Wraps a system frame's message in its decoder.
Definition SequencedFrame.hpp:399
constexpr std::int64_t CLUSTER_HEARTBEAT_INTERVAL_MS
Definition SequencedFrame.hpp:69
constexpr std::uint16_t GATEWAY_REGISTERED
Definition SequencedFrame.hpp:102
Decoder decodeSequenced(const char *payload, const std::uint64_t payloadLength, const std::uint16_t blockLength, const std::uint16_t version)
Wraps an application payload held as loose bytes in its decoder, past its own messageHeader.
Definition SequencedFrame.hpp:380
constexpr std::uint16_t MIN_INGRESS_LENGTH
Definition SequencedFrame.hpp:84
void readSystemHeader(FrameView &view, sbe::frame::SequencedSystemHeader &header)
Copies the identity every system message carries; the two composites are the same 44 bytes.
Definition SequencedFrame.hpp:235
constexpr std::int32_t queueStreamId(const std::int32_t groupId)
Names the stream of a group's queue.
Definition SequencedFrame.hpp:61
constexpr std::uint16_t CLUSTER_STOPPED
Definition SequencedFrame.hpp:100
constexpr std::uint16_t APPLICATION_REGISTERED
Definition SequencedFrame.hpp:107
constexpr std::uint16_t SNAPSHOT_REQUESTED
Definition SequencedFrame.hpp:108
constexpr const char * QUEUE_CHANNEL
Definition SequencedFrame.hpp:47
constexpr std::int32_t QUEUE_STREAM_ID_BASE
Definition SequencedFrame.hpp:53
constexpr std::int64_t CLUSTER_HEARTBEAT_INTERVAL_NS
Definition SequencedFrame.hpp:70
constexpr std::uint16_t SNAPSHOT_POLICY_REGISTERED
Definition SequencedFrame.hpp:110
std::int64_t nowNs()
Definition SequencedFrame.hpp:528
constexpr std::uint16_t CLUSTER_HEARTBEAT
Definition SequencedFrame.hpp:101
One frame off the queue, unwrapped: everything a consumer dispatches on, with the envelope stripped.
Definition SequencedFrame.hpp:205
std::uint16_t payloadId
Definition SequencedFrame.hpp:208
bool valid
false for a fragment that is not a frame, or too short to read
Definition SequencedFrame.hpp:206
std::uint64_t payloadLength
Definition SequencedFrame.hpp:226
std::uint16_t systemEventType
Definition SequencedFrame.hpp:209
std::uint16_t version
Definition SequencedFrame.hpp:221
std::int64_t sourceSessionId
Aeron Cluster client session id (header.sessionId)
Definition SequencedFrame.hpp:213
std::int64_t groupSeqNo
this frame's place on its queue (header.groupSeqNo, F-6)
Definition SequencedFrame.hpp:215
std::int32_t connectionId
Definition SequencedFrame.hpp:211
std::int64_t clusterSeqNo
Definition SequencedFrame.hpp:214
std::uint16_t blockLength
The payload's own, to wrap its decoder with; both 0 on any system frame, whose message carries no dec...
Definition SequencedFrame.hpp:220
std::int64_t clusterTimestampNs
cluster consensus time (epoch ns) when committed (header.timestamp)
Definition SequencedFrame.hpp:216
bool system
true: one of the six system messages; payloadId/templateId mean nothing
Definition SequencedFrame.hpp:207
std::uint16_t templateId
application family: the payload's own, never the envelope's
Definition SequencedFrame.hpp:217
std::uint16_t groupMask
the groups whose queues carry it (header.groupMask, §7.4)
Definition SequencedFrame.hpp:212
std::int32_t sourceId
Definition SequencedFrame.hpp:210
const char * payload
What a consumer decodes: the payload, its 8-byte messageHeader included, on an application frame; the...
Definition SequencedFrame.hpp:225
A connection at a producer opening (ConnectionOpened) or closing (ConnectionClosed).
Definition SequencedFrame.hpp:454
std::int32_t sourceId
publishing producer process (header.sourceId)
Definition SequencedFrame.hpp:456
const char * payload
the event's message, for decodeSystem; valid only during the callback
Definition SequencedFrame.hpp:461
std::int64_t receiveTimeNs
wall-clock ns at receipt by this client
Definition SequencedFrame.hpp:460
std::int64_t sourceSessionId
Aeron Cluster session the event was submitted on.
Definition SequencedFrame.hpp:458
std::int64_t clusterSeqNo
Definition SequencedFrame.hpp:455
std::int32_t connectionId
connection at that producer (header.connectionId)
Definition SequencedFrame.hpp:457
std::uint64_t payloadLength
total byte count
Definition SequencedFrame.hpp:462
std::int64_t clusterTimestampNs
cluster consensus time (epoch ns) when committed
Definition SequencedFrame.hpp:459
Carries one message from the cluster stream.
Definition SequencedFrame.hpp:175
std::uint16_t blockLength
payload messageHeader blockLength; 0 on a system frame (see decodeSystem)
Definition SequencedFrame.hpp:188
std::int32_t sourceId
Fixed constant identifying the submitting producer process (header.sourceId)
Definition SequencedFrame.hpp:178
std::uint16_t templateId
the message's messageHeader templateId; picks the specific decode
Definition SequencedFrame.hpp:187
std::int64_t sourceSessionId
Aeron Cluster client session id (header.sessionId)
Definition SequencedFrame.hpp:181
std::uint16_t version
payload messageHeader version; 0 on a system frame
Definition SequencedFrame.hpp:189
std::uint16_t systemEventType
which of §7's eighteen events; 0 on an application frame
Definition SequencedFrame.hpp:186
bool system
true: a system frame, named by systemEventType, and payloadId means nothing
Definition SequencedFrame.hpp:184
std::int64_t groupSeqNo
this frame's place on its queue: 1 for the first, then one per frame (F-6)
Definition SequencedFrame.hpp:177
std::uint64_t payloadLength
total byte count
Definition SequencedFrame.hpp:192
std::int64_t receiveTimeNs
wall-clock ns at receipt by this client
Definition SequencedFrame.hpp:183
std::int64_t clusterTimestampNs
cluster consensus time (epoch ns) when message was committed
Definition SequencedFrame.hpp:182
std::int64_t position
recording/stream position of this frame's first byte; pass to ReplayParams::position() to replay from...
Definition SequencedFrame.hpp:193
const char * payload
the payload's own bytes, its 8-byte messageHeader included; on a system frame, the message with no fr...
Definition SequencedFrame.hpp:190
std::uint16_t payloadId
which protocol templateId belongs to; 0 on a system frame
Definition SequencedFrame.hpp:185
std::int32_t connectionId
Connection id at that producer; routes the reply (header.connectionId)
Definition SequencedFrame.hpp:179
std::uint16_t groupMask
the groups whose queues carry it (header.groupMask); 0 on a system frame
Definition SequencedFrame.hpp:180
std::int64_t clusterSeqNo
Definition SequencedFrame.hpp:176