Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
reliable_listener.h
1/*
2 * Copyright (c) 2008-2025, Hazelcast, Inc. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include <cstdint>
19
20#include "hazelcast/client/exception/iexception.h"
21#include "hazelcast/util/noop.h"
22#include "hazelcast/util/type_traits.h"
23
24#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
25#pragma warning(push)
26#pragma warning(disable : 4251) // for dll export
27#endif
28
29namespace hazelcast {
30namespace client {
31class reliable_topic;
32namespace topic {
33class message;
34
65class HAZELCAST_API reliable_listener final
66{
67 friend class client::reliable_topic;
68
69public:
83 explicit reliable_listener(bool loss_tolerant,
84 int64_t initial_sequence_id = -1);
85
96 template<typename Handler,
97 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
99 {
100 received_ = std::move(h);
101 return *this;
102 }
103
107 template<typename Handler,
108 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
110 {
111 on_received(std::move(h));
112 return std::move(*this);
113 }
114
123 template<typename Handler,
124 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
126 {
127 store_sequence_id_ = std::move(h);
128 return *this;
129 }
130
134 template<typename Handler,
135 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
137 {
138 on_store_sequence_id(std::move(h));
139 return std::move(*this);
140 }
141
150 template<typename Handler,
151 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
153 {
154 terminal_ = std::move(h);
155 return *this;
156 }
157
161 template<typename Handler,
162 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
164 {
165 terminate_on_exception(std::move(h));
166 return std::move(*this);
167 }
168
175 template<typename Handler,
176 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
178 {
179 on_cancel_ = std::move(h);
180 return *this;
181 }
182
186 template<typename Handler,
187 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
188 reliable_listener&& on_cancel(Handler&& h) &&
189 {
190 on_cancel(std::move(h));
191 return std::move(*this);
192 }
193
194private:
195 using received_handler_t = std::function<void(message&&)>;
196 using store_sequence_id_handler_t = std::function<void(int64_t)>;
197 using exception_handler_t =
198 std::function<bool(const exception::iexception&)>;
199 using on_cancel_handler_t = std::function<void()>;
200
201 bool loss_tolerant_;
202 int64_t initial_sequence_id_;
203
204 received_handler_t received_{ util::noop<message&&> };
205 store_sequence_id_handler_t store_sequence_id_{ util::noop<int64_t> };
206 exception_handler_t terminal_{ [](const exception::iexception&) {
207 return false;
208 } };
209 on_cancel_handler_t on_cancel_{util::noop<>};
210};
211
212} // namespace topic
213} // namespace client
214} // namespace hazelcast
215
216#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
217#pragma warning(pop)
218#endif
Base class for all exception originated from Hazelcast methods.
Definition iexception.h:49
Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subs...
reliable_listener & terminate_on_exception(Handler &&h) &
Set an handler function that checks if the listener should be terminated based on an exception thrown...
reliable_listener && on_received(Handler &&h) &&
Set an handler function to be invoked when a message is received for the added topic.
reliable_listener & on_cancel(Handler &&h) &
Set an handler function which will be called when the listener is cancelled.
reliable_listener && terminate_on_exception(Handler &&h) &&
Set an handler function that checks if the listener should be terminated based on an exception thrown...
reliable_listener && on_cancel(Handler &&h) &&
Set an handler function which will be called when the listener is cancelled.
reliable_listener && on_store_sequence_id(Handler &&h) &&
reliable_listener(bool loss_tolerant, int64_t initial_sequence_id=-1)
Definition proxy.cpp:103
reliable_listener & on_store_sequence_id(Handler &&h) &
Set an handler function to be invoked to informs the listener that it should store the sequence.
reliable_listener & on_received(Handler &&h) &
Set an handler function to be invoked when a message is received for the added topic.