dxFeed Graal CXX API v5.0.0
Loading...
Searching...
No Matches
Handler.hpp
1// Copyright (c) 2025 Devexperts LLC.
2// SPDX-License-Identifier: MPL-2.0
3
4#pragma once
5
6#include "./Conf.hpp"
7
9
10#include <functional>
11#include <future>
12#include <mutex>
13#include <unordered_map>
14#include <vector>
15
17
18/**
19 * A thread-safe class that allows to asynchronously notify listeners with a given signature.
20 * Listeners can be any callable entities.
21 * Listeners are placed in a future. Within one batch, listeners will be called sequentially. Futures are placed in
22 * a circular buffer and executed asynchronously.
23 *
24 * If you need synchronous execution of listeners, but it was possible to execute them in another thread, then limit
25 * the buffer size to one.
26 *
27 * @tparam Signature The arguments "signature" (example: `void(int, int)`)
28 */
29template <typename Signature> struct Handler;
30
31/**
32 * A thread-safe class that allows to asynchronously notify listeners with a given signature.
33 * Listeners can be any callable entities.
34 * Listeners are placed in a future. Within one batch, listeners will be called sequentially. Futures are placed in
35 * a circular buffer and executed asynchronously.
36 *
37 * If you need synchronous execution of listeners, but it was possible to execute them in another thread, then limit
38 * the buffer size to one.
39 *
40 * @tparam ArgTypes The arguments "signature" (example: `void(int, int)`)
41 */
42template <typename... ArgTypes> struct Handler<void(ArgTypes...)> final {
43 /// The listener type
44 using ListenerType = std::function<void(ArgTypes...)>;
45 static constexpr std::size_t FAKE_ID{static_cast<std::size_t>(-1)};
46
47 private:
48 static constexpr unsigned MAIN_FUTURES_DEFAULT_SIZE = 1;
49
50 std::recursive_mutex listenersMutex_{};
51 std::unordered_map<std::size_t, ListenerType> listeners_{};
52 std::unordered_map<std::size_t, ListenerType> lowPriorityListeners_{};
53
54 inline static std::atomic<std::size_t> lastId_{};
55
56 std::recursive_mutex mainFuturesMutex_{};
57 std::vector<std::shared_future<void>> mainFutures_{};
58 std::size_t mainFuturesCurrentIndex_{};
59 std::size_t mainFuturesSize_{};
60
61 std::shared_future<void> handleImpl(ArgTypes... args) {
62 return std::async(
63 std::launch::async,
64 [this](ArgTypes... args) {
65 std::lock_guard guard{listenersMutex_};
66
67 for (auto &listener : listeners_) {
68 listener.second(args...);
69 }
70
71 for (auto &listener : lowPriorityListeners_) {
72 listener.second(args...);
73 }
74 },
75 args...);
76 }
77
78 public:
79 /**
80 * Creates the new handler by specified size of circular buffer of futures
81 *
82 * @param mainFuturesSize The size of the circular buffer of futures
83 */
84 explicit Handler(std::size_t mainFuturesSize = MAIN_FUTURES_DEFAULT_SIZE) noexcept
85 : mainFuturesCurrentIndex_{0ULL}, mainFuturesSize_{mainFuturesSize} {
86 if (mainFuturesSize > 1) {
87 mainFutures_.reserve(mainFuturesSize);
88 }
89 }
90
91 Handler(const Handler &) = delete;
92
93 Handler(Handler &&other) noexcept {
94 std::scoped_lock lock(other.listenersMutex_, other.mainFuturesMutex_);
95
96 listeners_.swap(other.listeners_);
97 lowPriorityListeners_.swap(other.lowPriorityListeners_);
98 mainFutures_.swap(other.mainFutures_);
99 mainFuturesCurrentIndex_ = other.mainFuturesCurrentIndex_;
100 mainFuturesSize_ = other.mainFuturesSize_;
101 }
102
103 Handler &operator=(const Handler &) = delete;
104
105 Handler &operator=(Handler &&other) noexcept {
106 std::scoped_lock lock(listenersMutex_, mainFuturesMutex_, other.listenersMutex_, other.mainFuturesMutex_);
107
108 listeners_.swap(other.listeners_);
109 lowPriorityListeners_.swap(other.lowPriorityListeners_);
110 mainFutures_.swap(other.mainFutures_);
111 mainFuturesCurrentIndex_ = other.mainFuturesCurrentIndex_;
112 mainFuturesSize_ = other.mainFuturesSize_;
113
114 return *this;
115 }
116
117 /**
118 * Calls the listeners and pass the args to them
119 *
120 * @param args The listeners arguments
121 */
122 void handle(ArgTypes... args) {
123 auto f = handleImpl(args...);
124
125 if (mainFuturesSize_ <= 1) {
126 f.wait();
127 } else {
128 std::lock_guard guard{mainFuturesMutex_};
129
130 if (mainFutures_.size() < mainFuturesSize_) {
131 mainFutures_.emplace_back(f);
132 } else {
133 mainFuturesCurrentIndex_ %= mainFuturesSize_;
134 mainFutures_[mainFuturesCurrentIndex_].wait();
135 mainFutures_[mainFuturesCurrentIndex_] = f;
136 mainFuturesCurrentIndex_++;
137 }
138 }
139 }
140
141 /**
142 * Calls the listeners and pass the ars to them
143 *
144 * @param args The listeners arguments
145 */
146 void operator()(ArgTypes... args) {
147 return handle(args...);
148 }
149
150 /**
151 * Adds the listener to "main" group
152 *
153 * @param listener The listener
154 * @return The listener id
155 */
156 std::size_t add(ListenerType &&listener) {
157 std::lock_guard guard{listenersMutex_};
158
159 if (lastId_ >= FAKE_ID - 1) {
160 return FAKE_ID;
161 }
162
163 auto id = ++lastId_;
164
165 listeners_.emplace(id, std::forward<ListenerType>(listener));
166
167 return id;
168 }
169
170 /**
171 * Adds the low priority listener (to the "low priority" group)
172 * It will be called after the "main" listeners
173 *
174 * @param listener The listener
175 * @return The listener id
176 */
177 std::size_t addLowPriority(ListenerType &&listener) {
178 std::lock_guard guard{listenersMutex_};
179
180 if (lastId_ >= FAKE_ID - 1) {
181 return FAKE_ID;
182 }
183
184 auto id = ++lastId_;
185
186 lowPriorityListeners_.emplace(id, std::forward<ListenerType>(listener));
187
188 return id;
189 }
190
191 /**
192 * Adds the listener to "main" group
193 *
194 * @param listener The listener
195 * @return The listener id
196 */
197 std::size_t operator+=(ListenerType &&listener) {
198 return add(std::forward<ListenerType>(listener));
199 }
200
201 /**
202 * Adds the low priority listener (to the "low priority" group).
203 * It will be called after the "main" listeners
204 *
205 * @param listener The listener
206 * @return The listener id
207 */
208 std::size_t operator%=(ListenerType &&listener) {
209 return addLowPriority(std::forward<ListenerType>(listener));
210 }
211
212 /**
213 * Removes a listener by the id
214 *
215 * @param id The listener id
216 */
217 void remove(std::size_t id) {
218 std::lock_guard guard{listenersMutex_};
219
220 if (id == FAKE_ID) {
221 return;
222 }
223
224 if (listeners_.count(id) > 0) {
225 listeners_.erase(id);
226 } else if (lowPriorityListeners_.count(id) > 0) {
227 lowPriorityListeners_.erase(id);
228 }
229 }
230
231 /**
232 * Removes a listener by the id
233 *
234 * @param id The listener id
235 */
236 void operator-=(std::size_t id) {
237 return remove(id);
238 }
239};
240
241/**
242 * A thread-safe class that allows to asynchronously notify listeners with a given signature.
243 * Listeners can be any callable entities.
244 * Listeners are placed in one future without queues.
245 *
246 * @tparam Signature The arguments "signature" (example: `void(int, int)`)
247 */
248template <typename Signature> struct SimpleHandler;
249
250/**
251 * A thread-safe class that allows to asynchronously notify listeners with a given signature.
252 * Listeners can be any callable entities.
253 * Listeners are placed in one future without queues.
254 *
255 * @tparam ArgTypes The arguments "signature" (example: `void(int, int)`)
256 */
257template <typename... ArgTypes> struct SimpleHandler<void(ArgTypes...)> final {
258 using ListenerType = std::function<void(ArgTypes...)>;
259 static constexpr std::size_t FAKE_ID{static_cast<std::size_t>(-1)};
260
261 private:
262 std::recursive_mutex listenersMutex_{};
263 std::unordered_map<std::size_t, ListenerType> listeners_{};
264 std::unordered_map<std::size_t, ListenerType> lowPriorityListeners_{};
265
266 inline static std::atomic<std::size_t> lastId_{};
267
268 std::shared_future<void> handleImpl(ArgTypes... args) {
269 return std::async(
270 std::launch::async,
271 [this](ArgTypes... args) {
272 std::lock_guard guard{listenersMutex_};
273
274 for (auto &listener : listeners_) {
275 listener.second(args...);
276 }
277
278 for (auto &listener : lowPriorityListeners_) {
279 listener.second(args...);
280 }
281 },
282 args...);
283 }
284
285 public:
286 /**
287 * Creates the new handler
288 */
289 SimpleHandler() noexcept = default;
290 SimpleHandler(const SimpleHandler &) = delete;
291
292 SimpleHandler(SimpleHandler &&other) noexcept {
293 std::scoped_lock lock(other.listenersMutex_);
294
295 listeners_.swap(other.listeners_);
296 lowPriorityListeners_.swap(other.lowPriorityListeners_);
297 }
298
299 SimpleHandler &operator=(const SimpleHandler &) = delete;
300
301 SimpleHandler &operator=(SimpleHandler &&other) noexcept {
302 std::scoped_lock lock(listenersMutex_, other.listenersMutex_);
303
304 listeners_.swap(other.listeners_);
305 lowPriorityListeners_.swap(other.lowPriorityListeners_);
306
307 return *this;
308 }
309
310 /**
311 * Calls the listeners and pass the args to them
312 *
313 * @param args The listeners arguments
314 */
315 void handle(ArgTypes... args) {
316 auto f = handleImpl(args...);
317
318 f.wait();
319 }
320
321 /**
322 * Calls the listeners and pass the ars to them
323 *
324 * @param args The listeners arguments
325 */
326 void operator()(ArgTypes... args) {
327 return handle(args...);
328 }
329
330 /**
331 * Adds the listener to "main" group
332 *
333 * @param listener The listener
334 * @return The listener id
335 */
336 std::size_t add(ListenerType &&listener) {
337 std::lock_guard guard{listenersMutex_};
338
339 if (lastId_ >= FAKE_ID - 1) {
340 return FAKE_ID;
341 }
342
343 auto id = ++lastId_;
344
345 listeners_.emplace(id, std::forward<ListenerType>(listener));
346
347 return id;
348 }
349
350 /**
351 * Adds the low priority listener (to the "low priority" group)
352 * It will be called after the "main" listeners
353 *
354 * @param listener The listener
355 * @return The listener id
356 */
357 std::size_t addLowPriority(ListenerType &&listener) {
358 std::lock_guard guard{listenersMutex_};
359
360 if (lastId_ >= FAKE_ID - 1) {
361 return FAKE_ID;
362 }
363
364 auto id = ++lastId_;
365
366 lowPriorityListeners_.emplace(id, std::forward<ListenerType>(listener));
367
368 return id;
369 }
370
371 /**
372 * Adds the listener to "main" group
373 *
374 * @param listener The listener
375 * @return The listener id
376 */
377 std::size_t operator+=(ListenerType &&listener) {
378 return add(std::forward<ListenerType>(listener));
379 }
380
381 /**
382 * Adds the low priority listener (to the "low priority" group).
383 * It will be called after the "main" listeners
384 *
385 * @param listener The listener
386 * @return The listener id
387 */
388 std::size_t operator%=(ListenerType &&listener) {
389 return addLowPriority(std::forward<ListenerType>(listener));
390 }
391
392 /**
393 * Removes a listener by the id
394 *
395 * @param id The listener id
396 */
397 void remove(std::size_t id) {
398 std::lock_guard guard{listenersMutex_};
399
400 if (id == FAKE_ID) {
401 return;
402 }
403
404 if (listeners_.count(id) > 0) {
405 listeners_.erase(id);
406 } else if (lowPriorityListeners_.count(id) > 0) {
407 lowPriorityListeners_.erase(id);
408 }
409 }
410
411 /**
412 * Removes a listener by the id
413 *
414 * @param id The listener id
415 */
416 void operator-=(std::size_t id) {
417 return remove(id);
418 }
419};
420
422
#define DXFCPP_MACRO_CONCAT_INNER(a, b)
Definition Common.hpp:129
#define DXFCPP_MACRO_CONCAT(a, b)
Definition Common.hpp:128
#define DXFCPP_MACRO_UNIQUE_NAME(base)
Definition Common.hpp:130
#define DXFCXX_DISABLE_MSC_WARNINGS_POP()
Definition Conf.hpp:31
#define DXFCPP_END_NAMESPACE
Definition Conf.hpp:97
#define DXFCPP_BEGIN_NAMESPACE
Definition Conf.hpp:94
#define DXFCXX_DISABLE_GCC_WARNINGS_PUSH(warnings)
Definition Conf.hpp:47
#define DXFCXX_DISABLE_GCC_WARNINGS_POP()
Definition Conf.hpp:49
#define DXFCXX_DISABLE_MSC_WARNINGS_PUSH(warnings)
Definition Conf.hpp:30
#define DXFCPP_TRACE_ISOLATES
Definition Debug.hpp:19
#define DXFCPP_DEBUG
Definition Debug.hpp:15
#define DXFCPP_TRACE_LISTS
Definition Debug.hpp:22
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_name(dxfc_dxendpoint_builder_t builderHandle, const char *name)
Changes the name used to distinguish multiple endpoints in the same process (GraalVM Isolate) in logs...
Definition DXEndpoint.cpp:680
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_properties(dxfc_dxendpoint_builder_t builder, const dxfc_dxendpoint_property_t **properties, size_t size)
Sets all supported properties from the provided properties object.
Definition DXEndpoint.cpp:713
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_password(dxfc_dxendpoint_t endpoint, const char *password)
Changes password for this endpoint.
Definition DXEndpoint.cpp:961
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_publisher(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxpublisher_t *publisher)
Definition DXEndpoint.cpp:1151
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_supports_property(dxfc_dxendpoint_builder_t builder, const char *key, DXFC_OUT int *supports)
Checks if a property is supported.
Definition DXEndpoint.cpp:740
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_add_state_change_listener(dxfc_dxendpoint_t endpoint, dxfc_dxendpoint_state_change_listener listener)
Adds a listener notified about changes in state property.
Definition DXEndpoint.cpp:1097
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_disconnect(dxfc_dxendpoint_t endpoint)
Terminates all remote network connections.
Definition DXEndpoint.cpp:1012
#define DXFCPP_EXPORT
Definition api.h:35
void * dxfc_dxendpoint_builder_t
The dxFeed endpoint's builder handle.
Definition api.h:207
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_close_and_await_termination(dxfc_dxendpoint_t endpoint)
Closes this endpoint and wait until all pending data processing tasks are completed.
Definition DXEndpoint.cpp:910
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_await_not_connected(dxfc_dxendpoint_t endpoint)
Waits while this endpoint state becomes NOT_CONNECTED or CLOSED.
Definition DXEndpoint.cpp:1063
dxfc_dxendpoint_state_t
Represents the current state of endpoint.
Definition api.h:149
@ DXFC_DXENDPOINT_STATE_CLOSED
Endpoint was closed.
Definition api.h:169
@ DXFC_DXENDPOINT_STATE_NOT_CONNECTED
Endpoint was created by is not connected to remote endpoints.
Definition api.h:153
@ DXFC_DXENDPOINT_STATE_CONNECTING
The connect function was called to establish connection to remove endpoint, but the connection is not...
Definition api.h:159
@ DXFC_DXENDPOINT_STATE_CONNECTED
The connection to the remote endpoint is established.
Definition api.h:164
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_instance(void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Returns a default application-wide singleton instance of dxFeed endpoint with a FEED role.
Definition DXEndpoint.cpp:799
#define DXFC_OUT
Definition api.h:17
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_state(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxendpoint_state_t *state)
Returns the state of this endpoint.
Definition DXEndpoint.cpp:1080
void * dxfc_dxendpoint_t
The dxFeed endpoint handle.
Definition api.h:198
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_property(dxfc_dxendpoint_builder_t builder, const char *key, const char *value)
Sets the specified property.
Definition DXEndpoint.cpp:696
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_free(dxfc_dxendpoint_builder_t builder)
Removes a builder from the registry.
Definition DXEndpoint.cpp:787
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_connect(dxfc_dxendpoint_t endpoint, const char *address)
Connects to the specified remote address.
Definition DXEndpoint.cpp:978
dxfc_error_code_t
List of error codes.
Definition api.h:49
@ DXFC_EC_ERROR
The error returned if the current operation cannot be completed.
Definition api.h:60
@ DXFC_EC_SUCCESS
OK.
Definition api.h:53
@ DXFC_EC_G_ERR
dxFeed Graal Native API error.
Definition api.h:57
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_remove_state_change_listener(dxfc_dxendpoint_t endpoint, dxfc_dxendpoint_state_change_listener listener)
Removes a listener notified about changes in state property.
Definition DXEndpoint.cpp:1123
DXFCPP_EXPORT dxfc_error_code_t dxfc_system_set_property(const char *key, const char *value)
Sets the system property indicated by the specified key.
Definition System.cpp:73
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_build(dxfc_dxendpoint_builder_t builder, void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Builds the new dxFeed endpoint instance.
Definition DXEndpoint.cpp:757
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_feed(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxfeed_t *feed)
Definition DXEndpoint.cpp:1146
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_await_processed(dxfc_dxendpoint_t endpoint)
Waits until this endpoint stops processing data (becomes quiescent).
Definition DXEndpoint.cpp:1046
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_close(dxfc_dxendpoint_t endpoint)
Closes this endpoint.
Definition DXEndpoint.cpp:893
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_new_builder(DXFC_OUT dxfc_dxendpoint_builder_t *builder)
Creates a new dxFeed endpoint's builder instance.
Definition DXEndpoint.cpp:647
void(* dxfc_dxendpoint_state_change_listener)(dxfc_dxendpoint_state_t old_state, dxfc_dxendpoint_state_t new_state, void *user_data)
The endpoint current state change listener.
Definition api.h:178
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_reconnect(dxfc_dxendpoint_t endpoint)
Terminates all established network connections and initiates connecting again with the same address.
Definition DXEndpoint.cpp:995
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_role(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxendpoint_role_t *role)
Returns the role of this endpoint.
Definition DXEndpoint.cpp:927
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_user(dxfc_dxendpoint_t endpoint, const char *user)
Changes username for this endpoint.
Definition DXEndpoint.cpp:944
DXFCPP_EXPORT dxfc_error_code_t dxfc_system_get_property(const char *key, DXFC_OUT char *buffer, size_t buffer_size)
Gets the system property indicated by the specified key.
dxfc_dxendpoint_role_t
Represents the role of an endpoint that was specified during its creation.
Definition api.h:89
@ DXFC_DXENDPOINT_ROLE_PUBLISHER
PUBLISHER endpoint connects to the remote publisher hub (also known as multiplexor) or creates a publ...
Definition api.h:127
@ DXFC_DXENDPOINT_ROLE_STREAM_FEED
STREAM_FEED endpoint is similar to DXFC_DXENDPOINT_ROLE_FEED and also connects to the remote data fee...
Definition api.h:116
@ DXFC_DXENDPOINT_ROLE_FEED
FEED endpoint connects to the remote data feed provider and is optimized for real-time or delayed dat...
Definition api.h:99
@ DXFC_DXENDPOINT_ROLE_STREAM_PUBLISHER
STREAM_PUBLISHER endpoint is similar to DXFC_DXENDPOINT_ROLE_PUBLISHER and also connects to the remot...
Definition api.h:136
@ DXFC_DXENDPOINT_ROLE_LOCAL_HUB
LOCAL_HUB endpoint is a local hub without the ability to establish network connections.
Definition api.h:143
@ DXFC_DXENDPOINT_ROLE_ON_DEMAND_FEED
ON_DEMAND_FEED endpoint is similar to DXFC_DXENDPOINT_ROLE_FEED, but it is designed to be used with d...
Definition api.h:107
void * dxfc_dxpublisher_t
The dxFeed publisher handle.
Definition api.h:217
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_create(void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Creates an endpoint with FEED role.
Definition DXEndpoint.cpp:846
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_instance2(dxfc_dxendpoint_role_t role, void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Returns a default application-wide singleton instance of DXEndpoint for a specific role.
Definition DXEndpoint.cpp:822
void * dxfc_dxfeed_t
The dxFeed handle.
Definition api.h:212
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_role(dxfc_dxendpoint_builder_t builder, dxfc_dxendpoint_role_t role)
Sets role for the created dxFeed endpoint.
Definition DXEndpoint.cpp:663
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_create2(dxfc_dxendpoint_role_t role, void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Creates an endpoint with a specified role.
Definition DXEndpoint.cpp:869
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_free(dxfc_dxendpoint_t endpoint)
Removes the dxFeed endpoint from the registry.
Definition DXEndpoint.cpp:1156
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_disconnect_and_clear(dxfc_dxendpoint_t endpoint)
Terminates all remote network connections and clears stored data.
Definition DXEndpoint.cpp:1029
Builder class for DXEndpoint that supports additional configuration properties.
Definition DXEndpoint.hpp:842
std::shared_ptr< DXEndpoint > build()
Builds DXEndpoint instance.
Definition DXEndpoint.cpp:323
std::shared_ptr< Builder > withName(const StringLike &name)
Changes the name used to distinguish multiple endpoints in the same process (GraalVM Isolate) in logs...
Definition DXEndpoint.cpp:366
bool supportsProperty(const StringLike &key) const
Checks if a property is supported.
Definition DXEndpoint.cpp:313
std::shared_ptr< Builder > withProperties(Properties &&properties)
Sets all supported properties from the provided properties object.
Definition DXEndpoint.hpp:931
~Builder() noexcept override
Releases the GraalVM handle.
Definition DXEndpoint.cpp:355
std::shared_ptr< Builder > withRole(Role role)
Sets role for the created DXEndpoint.
Definition DXEndpoint.cpp:285
std::shared_ptr< Builder > withProperty(const StringLike &key, const StringLike &value)
Sets the specified property.
Definition DXEndpoint.cpp:298
Manages network connections to feed or publisher.
Definition DXEndpoint.hpp:172
bool isClosed() const
Definition DXEndpoint.cpp:499
SimpleHandler< void(DXEndpoint::State, DXEndpoint::State)> & onStateChange() noexcept
Returns the onStateChange handler that can be used to add or remove listeners.
Definition DXEndpoint.cpp:511
static const std::string DXFEED_PASSWORD_PROPERTY
"dxfeed.password"
Definition DXEndpoint.hpp:238
static std::shared_ptr< DXEndpoint > create(Role role)
Creates an endpoint with a specified role.
Definition DXEndpoint.cpp:486
std::shared_ptr< DXFeed > getFeed() const
Definition DXEndpoint.cpp:212
std::shared_ptr< DXEndpoint > password(const StringLike &password)
Changes password for this endpoint.
Definition DXEndpoint.cpp:139
State
Represents the current state of endpoint.
Definition DXEndpoint.hpp:436
@ CLOSED
Endpoint was closed.
Definition DXEndpoint.hpp:456
@ CONNECTING
The connect method was called to establish connection to remove endpoint, but the connection is not e...
Definition DXEndpoint.hpp:446
@ CONNECTED
The connection to the remote endpoint is established.
Definition DXEndpoint.hpp:451
@ NOT_CONNECTED
Endpoint was created by is not connected to remote endpoints.
Definition DXEndpoint.hpp:440
std::shared_ptr< DXEndpoint > user(const StringLike &user)
Changes username for this endpoint.
Definition DXEndpoint.cpp:132
void reconnect() const
Terminates all established network connections and initiates connecting again with the same address.
Definition DXEndpoint.cpp:158
static std::shared_ptr< DXEndpoint > create()
Creates an endpoint with FEED role.
Definition DXEndpoint.cpp:477
void removeStateChangeListener(std::size_t listenerId) noexcept
Removes a listener notified about changes in state property.
Definition DXEndpoint.cpp:507
const std::string & getName() const &noexcept
Definition DXEndpoint.cpp:503
Role
Represents the role of an endpoint that was specified during its creation.
Definition DXEndpoint.hpp:365
@ PUBLISHER
PUBLISHER endpoint connects to the remote publisher hub (also known as multiplexor) or creates a publ...
Definition DXEndpoint.hpp:410
@ STREAM_FEED
STREAM_FEED endpoint is similar to DXEndpoint::FEED and also connects to the remote data feed provide...
Definition DXEndpoint.hpp:398
@ LOCAL_HUB
LOCAL_HUB endpoint is a local hub without the ability to establish network connections.
Definition DXEndpoint.hpp:426
@ ON_DEMAND_FEED
ON_DEMAND_FEED endpoint is similar to DXEndpoint::FEED, but it is designed to be used with OnDemandSe...
Definition DXEndpoint.hpp:389
@ STREAM_PUBLISHER
STREAM_PUBLISHER endpoint is similar to DXEndpoint::PUBLISHER and also connects to the remote publish...
Definition DXEndpoint.hpp:419
@ FEED
FEED endpoint connects to the remote data feed provider and is optimized for real-time or delayed dat...
Definition DXEndpoint.hpp:376
std::string toString() const override
Returns a string representation of the current object.
Definition DXEndpoint.cpp:376
void awaitProcessed() const
Waits until this endpoint stops processing data (becomes quiescent).
Definition DXEndpoint.cpp:194
std::shared_ptr< DXPublisher > getPublisher() const
Definition DXEndpoint.cpp:221
static const std::string DXFEED_WILDCARD_ENABLE_PROPERTY
"dxfeed.wildcard.enable"
Definition DXEndpoint.hpp:266
std::size_t addStateChangeListener(std::function< void(State, State)> listener) noexcept
Adds a listener notified about changes in state property.
Definition DXEndpoint.hpp:611
static const std::string DXENDPOINT_EVENT_TIME_PROPERTY
"dxendpoint.eventTime"
Definition DXEndpoint.hpp:311
static const std::string DXPUBLISHER_THREAD_POOL_SIZE_PROPERTY
"dxpublisher.threadPoolSize"
Definition DXEndpoint.hpp:294
State getState() const
Returns the state of this endpoint.
Definition DXEndpoint.cpp:128
static const std::string DXENDPOINT_STORE_EVERYTHING_PROPERTY
"dxendpoint.storeEverything"
Definition DXEndpoint.hpp:324
void awaitNotConnected() const
Waits while this endpoint state becomes NOT_CONNECTED or CLOSED.
Definition DXEndpoint.cpp:185
static std::shared_ptr< DXEndpoint > getInstance(Role role)
Returns a default application-wide singleton instance of DXEndpoint for a specific role.
Definition DXEndpoint.cpp:459
static const std::string DXFEED_AGGREGATION_PERIOD_PROPERTY
"dxfeed.aggregationPeriod"
Definition DXEndpoint.hpp:257
void close() const
Closes this endpoint.
Definition DXEndpoint.cpp:515
static const std::string DXFEED_THREAD_POOL_SIZE_PROPERTY
"dxfeed.threadPoolSize"
Definition DXEndpoint.hpp:247
void disconnect() const
Terminates all remote network connections.
Definition DXEndpoint.cpp:167
void closeAndAwaitTermination() const
Closes this endpoint and wait until all pending data processing tasks are completed.
Definition DXEndpoint.cpp:203
static std::shared_ptr< DXEndpoint > getInstance()
Returns a default application-wide singleton instance of DXEndpoint with a FEED role.
Definition DXEndpoint.cpp:450
static const std::string DXPUBLISHER_ADDRESS_PROPERTY
"dxpublisher.address"
Definition DXEndpoint.hpp:285
static const std::string DXFEED_USER_PROPERTY
"dxfeed.user"
Definition DXEndpoint.hpp:228
static const std::string NAME_PROPERTY
"name"
Definition DXEndpoint.hpp:189
static const std::string DXSCHEME_ENABLED_PROPERTY_PREFIX
"dxscheme.enabled."
Definition DXEndpoint.hpp:358
static const std::string DXPUBLISHER_PROPERTIES_PROPERTY
"dxpublisher.properties"
Definition DXEndpoint.hpp:275
static const std::string DXSCHEME_NANO_TIME_PROPERTY
"dxscheme.nanoTime"
Definition DXEndpoint.hpp:344
static const std::string DXFEED_ADDRESS_PROPERTY
"dxfeed.address"
Definition DXEndpoint.hpp:218
void disconnectAndClear() const
Terminates all remote network connections and clears stored data.
Definition DXEndpoint.cpp:176
Role getRole() const noexcept
Returns the role of this endpoint.
Definition DXEndpoint.cpp:495
static const std::string DXFEED_PROPERTIES_PROPERTY
"dxfeed.properties"
Definition DXEndpoint.hpp:200
static std::shared_ptr< Builder > newBuilder()
Creates a new Builder instance.
Definition DXEndpoint.cpp:468
std::shared_ptr< DXEndpoint > connect(const StringLike &address)
Connects to the specified remote address.
Definition DXEndpoint.cpp:146
Main entry class for dxFeed API (read it first).
Definition DXFeed.hpp:115
Provides API for publishing of events to local or remote DXFeed.
Definition DXPublisher.hpp:56
Base abstract class for all dxFeed C++ API entities.
Definition Entity.hpp:13
virtual ~Entity() noexcept=default
The default virtual d-tor.
Marks all event types that can be received via dxFeed API.
Definition EventType.hpp:31
void handle(ArgTypes... args)
Calls the listeners and pass the args to them.
Definition Handler.hpp:122
std::size_t add(ListenerType &&listener)
Adds the listener to "main" group.
Definition Handler.hpp:156
std::size_t operator%=(ListenerType &&listener)
Adds the low priority listener (to the "low priority" group).
Definition Handler.hpp:208
std::size_t operator+=(ListenerType &&listener)
Adds the listener to "main" group.
Definition Handler.hpp:197
void operator()(ArgTypes... args)
Calls the listeners and pass the ars to them.
Definition Handler.hpp:146
Handler(std::size_t mainFuturesSize=MAIN_FUTURES_DEFAULT_SIZE) noexcept
Creates the new handler by specified size of circular buffer of futures.
Definition Handler.hpp:84
void operator-=(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:236
std::size_t addLowPriority(ListenerType &&listener)
Adds the low priority listener (to the "low priority" group) It will be called after the "main" liste...
Definition Handler.hpp:177
void remove(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:217
Provides on-demand historical tick data replay controls.
Definition OnDemandService.hpp:71
A helper class needed to construct smart pointers to objects and does not allow explicit construction...
Definition SharedEntity.hpp:88
static auto createShared(Args &&...args)
Creates a smart pointer to an object.
Definition SharedEntity.hpp:102
A base abstract "shared entity" class. Has some helpers for dynamic polymorphism.
Definition SharedEntity.hpp:20
virtual std::string toString() const
Returns a string representation of the current object.
Definition SharedEntity.hpp:77
std::shared_ptr< T > sharedAs() const noexcept
Returns a pointer to the current object wrapped in a smart pointer to type T.
Definition SharedEntity.hpp:68
std::shared_ptr< T > sharedAs() noexcept
Returns a pointer to the current object wrapped in a smart pointer to type T.
Definition SharedEntity.hpp:55
bool is() const noexcept
Checks that the pointer to the current type could be converted to type T* In other words: whether typ...
Definition SharedEntity.hpp:34
std::size_t operator+=(ListenerType &&listener)
Adds the listener to "main" group.
Definition Handler.hpp:377
void remove(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:397
void handle(ArgTypes... args)
Calls the listeners and pass the args to them.
Definition Handler.hpp:315
void operator()(ArgTypes... args)
Calls the listeners and pass the ars to them.
Definition Handler.hpp:326
SimpleHandler() noexcept=default
Creates the new handler.
std::size_t addLowPriority(ListenerType &&listener)
Adds the low priority listener (to the "low priority" group) It will be called after the "main" liste...
Definition Handler.hpp:357
void operator-=(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:416
std::size_t operator%=(ListenerType &&listener)
Adds the low priority listener (to the "low priority" group).
Definition Handler.hpp:388
std::size_t add(ListenerType &&listener)
Adds the listener to "main" group.
Definition Handler.hpp:336
Universal functional object that allows searching std::unordered_map for string-like keys.
Definition Common.hpp:959
Universal functional object that allows searching std::unordered_map for string-like keys.
Definition StringUtils.hpp:171
A simple wrapper around strings or something similar to strings to reduce the amount of code for meth...
Definition Common.hpp:842
A lightweight wrapper around strings or string-like inputs.
Definition StringUtils.hpp:27
The simple key-value structure that represents an endpoint's property.
Definition api.h:184
const char * key
The property's key.
Definition api.h:186
const char * value
The property's value.
Definition api.h:188