seqeron 0.18.0
Loading...
Searching...
No Matches
Application.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
6#include "org/limitless/seqeron/hosted/detail/ClientLink.hpp"
8
9#include "org_limitless_seqeron_sbe_hosted/Publish.h"
10#include "org_limitless_seqeron_sbe_hosted/Reply.h"
11
13
24template<typename Listener>
25class Application : public detail::ClientLink<Application<Listener>, Listener>
26{
27 using Base = detail::ClientLink<Application<Listener>, Listener>;
28 friend Base;
29
30 public:
31 struct Config
32 {
33 // The source the host runs, the one its <applications> row declares; never -1.
34 std::int32_t sourceId = -1;
35 // Answers the host's SnapshotCut and restores its RestoreRecords; without it every cut is abandoned.
37 // The host's heartbeat counter may be silent this long before the stub gives it up (H-9, section 17.6).
38 std::int64_t hostTimeoutMs = 3000;
39 std::int64_t attachTimeoutMs = 90'000;
40 // Names the host this attaches to, the one its proxy.hostName gives; the attach is refused otherwise.
42 };
43
44 Application(Config config, Listener& listener) :
45 Base{ listener, wire::Kind::APPLICATION, config.sourceId,
46 config.snapshots, config.hostTimeoutMs, config.attachTimeoutMs,
47 config.hostName },
48 m_config{ config }
49 {
51 this->retainPublishes();
52 }
53
55 [[nodiscard]] bool canPublish() const noexcept
56 {
57 return this->m_canPublish;
58 }
59
60 [[nodiscard]] bool isLeading() const noexcept
61 {
62 return m_leading;
63 }
64
72 [[nodiscard]] protocol::Publish publish(const std::uint16_t payloadId, const std::uint8_t* payload,
73 const std::uint16_t payloadLength)
74 {
75 return publish(0, payloadId, payload, payloadLength);
76 }
77
86 [[nodiscard]] protocol::Publish publish(const std::uint16_t groupMask, const std::uint16_t payloadId,
87 const std::uint8_t* payload, const std::uint16_t payloadLength)
88 {
89 if (m_config.sourceId == -1)
90 {
92 }
93 return this->template offerPayload<wire::Publish>(
94 groupMask, payloadId, payloadLength, [&](wire::Publish& command) {
95 command.connectionId(-1).groupMask(groupMask).payloadId(payloadId).putBody(
96 reinterpret_cast<const char*>(payload), payloadLength);
97 });
98 }
99
109 [[nodiscard]] protocol::Publish reply(const app::ReplyAddress& request, const std::uint16_t payloadId,
110 const std::uint8_t* payload, const std::uint16_t payloadLength)
111 {
112 if (m_config.sourceId == -1)
113 {
115 }
116 return this->template offerPayload<wire::Reply>(
117 request.groupMask, payloadId, payloadLength, [&](wire::Reply& command) {
118 command.sourceId(request.sourceId)
119 .connectionId(request.connectionId)
120 .groupMask(request.groupMask)
121 .payloadId(payloadId)
122 .putBody(reinterpret_cast<const char*>(payload), payloadLength);
123 });
124 }
125
126 private:
127 // The hooks of ClientLink.
128 void onGate(const bool leading)
129 {
130 if (leading != m_leading)
131 {
132 m_leading = leading;
133 this->m_listener.onLeadershipChanged(leading);
134 }
135 }
136
137 void onOther(std::uint16_t, char*, aeron::util::index_t, std::uint16_t, std::uint16_t)
138 {}
139
140 Config m_config;
141 bool m_leading = false;
142};
143
144} // namespace org::limitless::seqeron::hosted
What a source that takes part in snapshot rounds serializes, and restores from (doc/snapshot....
Definition SnapshotListener.hpp:18
The client stub of a hosted Application (doc/seqeron-protocol-spec.md ยง17): the surface of app::Appli...
Definition Application.hpp:26
protocol::Publish publish(const std::uint16_t groupMask, const std::uint16_t payloadId, const std::uint8_t *payload, const std::uint16_t payloadLength)
The same to the groups groupMask names as well as its own.
Definition Application.hpp:86
Application(Config config, Listener &listener)
Definition Application.hpp:44
bool canPublish() const noexcept
What the last Gate said (H-16); lags the host by a hop.
Definition Application.hpp:55
protocol::Publish reply(const app::ReplyAddress &request, const std::uint16_t payloadId, const std::uint8_t *payload, const std::uint16_t payloadLength)
The same on behalf of the producer that asked for it (H-11): the reply carries the request's sourceId...
Definition Application.hpp:109
bool isLeading() const noexcept
Definition Application.hpp:60
protocol::Publish publish(const std::uint16_t payloadId, const std::uint8_t *payload, const std::uint16_t payloadLength)
Offers one payload of this application's own to its own group (H-4).
Definition Application.hpp:72
What an Application's Listener provides.
Definition Listeners.hpp:19
Definition Application.hpp:12
Publish
Definition Publish.hpp:13
constexpr const char * PROXY_DEFAULT_HOST_NAME
Definition ProxyProtocol.hpp:11
What a reply needs of the request it answers: the requester's sourceId, connectionId and groupMask.
Definition Payload.hpp:17
std::uint16_t groupMask
Definition Payload.hpp:20
std::int64_t attachTimeoutMs
Definition Application.hpp:39
app::SnapshotListener * snapshots
Definition Application.hpp:36
std::string hostName
Definition Application.hpp:41
std::int32_t sourceId
Definition Application.hpp:34
std::int64_t hostTimeoutMs
Definition Application.hpp:38