dxFeed Graal CXX API v9.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 "../detail/Conf.hpp"
7
8DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251)
9
10#include "../exceptions/ErrorManager.hpp"
11
12#include <algorithm>
13#include <condition_variable>
14#include <cstddef>
15#include <exception>
16#include <functional>
17#include <memory>
18#include <mutex>
19#include <string_view>
20#include <utility>
21#include <vector>
22
23/**
24 * \addtogroup dxfcpp_util
25 * @{
26 */
27
28DXFCPP_BEGIN_NAMESPACE
29
30/**
31 * The call of a listener of SimpleHandler in progress on the current thread.
32 *
33 * SimpleHandler::remove() does not wait for the calls in progress when the current thread calls a listener or a
34 * callback of the library: the wait could deadlock (a listener that removes itself, two listeners that remove each
35 * other on two threads). The counter is in the library, so it is one for the process, not one for each module.
36 */
37struct DXFCPP_EXPORT ListenerCallScope final {
38 ListenerCallScope() noexcept;
39 ~ListenerCallScope() noexcept;
40
41 ListenerCallScope(const ListenerCallScope &) = delete;
42 ListenerCallScope &operator=(const ListenerCallScope &) = delete;
43
44 /**
45 * @return `true` if the current thread calls a listener of SimpleHandler or a callback of the library.
46 */
47 static bool isActive() noexcept;
48};
49
50/**
51 * A thread-safe list of listeners with a given signature. Listeners can be any callable entities.
52 *
53 * handle() calls the listeners on the current thread (the thread that notifies): the "main" listeners, then the "low
54 * priority" ones, in the order of addition. It takes a snapshot of the list under a lock and calls the listeners
55 * outside of it, so a listener can add or remove listeners and call handle() of the same handler. A listener added
56 * during a notification is called from the next one. If the source notifies on several threads at once, the listeners
57 * are called on these threads at once.
58 *
59 * An exception of a listener is reported to ErrorManager; the other listeners are still called.
60 *
61 * @tparam Signature The arguments "signature" (example: `void(int, int)`)
62 */
63template <typename Signature> struct SimpleHandler;
64
65/**
66 * A thread-safe list of listeners with a given signature. See SimpleHandler.
67 *
68 * @tparam ArgTypes The arguments "signature" (example: `void(int, int)`)
69 */
70template <typename... ArgTypes> struct SimpleHandler<void(ArgTypes...)> final {
71 using ListenerType = std::function<void(ArgTypes...)>;
72 static constexpr std::size_t FAKE_ID{static_cast<std::size_t>(-1)};
73
74 private:
75 struct Listener final {
76 const std::size_t id;
77 const ListenerType function;
78
79 std::mutex mutex{};
80 std::condition_variable callsEnded{};
81 std::size_t calls{};
82 bool removed{};
83
84 Listener(std::size_t listenerId, ListenerType &&listener)
85 : id{listenerId}, function{std::forward<ListenerType>(listener)} {
86 }
87 };
88
89 // The list is not changed after it is published: add() and remove() publish a new one, so handle() takes a
90 // snapshot by copying the pointer. A null list is empty.
91 using List = std::vector<std::shared_ptr<Listener>>;
92
93 const char *component_{"SimpleHandler"};
94
95 std::mutex mutex_{};
96 std::shared_ptr<const List> listeners_{};
97 std::size_t mainListenersCount_{}; // the "main" listeners go first in the list, then the "low priority" ones
98
99 // The listener ids are unique within this handler only: they identify the listener for remove(). The counter is not
100 // static: a static member of a template has a copy in every module that instantiates it (on Windows: the shared
101 // library and each executable), so the ids of listeners added from the application and from the library collided.
102 // Guarded by mutex_.
103 std::size_t lastId_{};
104
105 // After the listeners are swapped, both handlers continue after the larger of the two counters, so that no id that
106 // is in use in either handler is given out again. Called with the mutexes of both handlers held.
107 template <typename OtherHandler> void syncLastIds(OtherHandler &other) noexcept {
108 const auto last = (std::max)(lastId_, other.lastId_);
109
110 lastId_ = last;
111 other.lastId_ = last;
112 }
113
114 void call(Listener &listener, ArgTypes &...args) noexcept {
115 {
116 std::lock_guard guard{listener.mutex};
117
118 if (listener.removed) {
119 return;
120 }
121
122 listener.calls++;
123 }
124
125 try {
126 listener.function(args...);
127 } catch (...) {
128 // A view of the name: copying it into a string could throw std::bad_alloc out of this noexcept function.
129 ErrorManager::reportException(std::string_view{component_}, std::current_exception());
130 }
131
132 std::lock_guard guard{listener.mutex};
133
134 if (--listener.calls == 0 && listener.removed) {
135 listener.callsEnded.notify_all();
136 }
137 }
138
139 // A removed listener is not called anymore.
140 static void markRemoved(Listener &listener) {
141 std::lock_guard guard{listener.mutex};
142
143 listener.removed = true;
144 }
145
146 // Waits for the calls of a removed listener in progress on the other threads, unless the current thread calls a
147 // listener or a callback of the library (see ListenerCallScope).
148 static void waitForCalls(Listener &listener) {
149 if (ListenerCallScope::isActive()) {
150 return;
151 }
152
153 std::unique_lock lock{listener.mutex};
154
155 listener.callsEnded.wait(lock, [&listener] {
156 return listener.calls == 0;
157 });
158 }
159
160 std::size_t addImpl(ListenerType &&listener, bool lowPriority) {
161 std::lock_guard guard{mutex_};
162
163 if (lastId_ >= FAKE_ID - 1) {
164 return FAKE_ID;
165 }
166
167 const auto id = lastId_ + 1;
168 auto list = listeners_ ? std::make_shared<List>(*listeners_) : std::make_shared<List>();
169 const auto position = lowPriority ? list->size() : mainListenersCount_;
170
171 list->insert(list->begin() + static_cast<typename List::difference_type>(position),
172 std::make_shared<Listener>(id, std::forward<ListenerType>(listener)));
173
174 listeners_ = std::move(list);
175 lastId_ = id;
176
177 if (!lowPriority) {
178 mainListenersCount_++;
179 }
180
181 return id;
182 }
183
184 public:
185 /**
186 * Creates the new handler. An exception of a listener is reported to ErrorManager with the component
187 * "SimpleHandler".
188 */
189 SimpleHandler() noexcept = default;
190
191 /**
192 * Creates the new handler.
193 *
194 * @param component The part of the library that owns the handler, for ErrorInfo::component of an exception of a
195 * listener. The string must outlive the handler (a string literal).
196 */
197 explicit SimpleHandler(const char *component) noexcept : component_{component} {
198 }
199
200 SimpleHandler(const SimpleHandler &) = delete;
201
202 SimpleHandler(SimpleHandler &&other) noexcept : component_{other.component_} {
203 std::lock_guard guard{other.mutex_};
204
205 listeners_ = std::exchange(other.listeners_, nullptr);
206 mainListenersCount_ = std::exchange(other.mainListenersCount_, 0);
207 lastId_ = other.lastId_; // the moved listeners keep their ids
208 }
209
210 SimpleHandler &operator=(const SimpleHandler &) = delete;
211
212 SimpleHandler &operator=(SimpleHandler &&other) noexcept {
213 std::scoped_lock lock(mutex_, other.mutex_);
214
215 listeners_.swap(other.listeners_);
216 std::swap(mainListenersCount_, other.mainListenersCount_);
217 syncLastIds(other);
218
219 return *this;
220 }
221
222 ~SimpleHandler() noexcept = default;
223
224 /**
225 * Calls the listeners on the current thread and passes the args to them.
226 *
227 * @param args The listeners arguments
228 */
229 void handle(ArgTypes... args) noexcept {
230 std::shared_ptr<const List> listeners{};
231
232 {
233 std::lock_guard guard{mutex_};
234
235 listeners = listeners_;
236 }
237
238 if (!listeners) {
239 return;
240 }
241
242 const ListenerCallScope callScope{};
243
244 for (const auto &listener : *listeners) {
245 call(*listener, args...);
246 }
247 }
248
249 /**
250 * Calls the listeners on the current thread and passes the args to them.
251 *
252 * @param args The listeners arguments
253 */
254 void operator()(ArgTypes... args) noexcept {
255 return handle(args...);
256 }
257
258 /**
259 * Adds the listener to "main" group
260 *
261 * @param listener The listener
262 * @return The listener id, unique within this handler (not across handlers)
263 */
264 std::size_t add(ListenerType &&listener) {
265 return addImpl(std::forward<ListenerType>(listener), false);
266 }
267
268 /**
269 * Adds the low priority listener (to the "low priority" group)
270 * It will be called after the "main" listeners
271 *
272 * @param listener The listener
273 * @return The listener id, unique within this handler (not across handlers)
274 */
275 std::size_t addLowPriority(ListenerType &&listener) {
276 return addImpl(std::forward<ListenerType>(listener), true);
277 }
278
279 /**
280 * Adds the listener to "main" group
281 *
282 * @param listener The listener
283 * @return The listener id, unique within this handler (not across handlers)
284 */
285 std::size_t operator+=(ListenerType &&listener) {
286 return add(std::forward<ListenerType>(listener));
287 }
288
289 /**
290 * Adds the low priority listener (to the "low priority" group).
291 * It will be called after the "main" listeners
292 *
293 * @param listener The listener
294 * @return The listener id, unique within this handler (not across handlers)
295 */
296 std::size_t operator%=(ListenerType &&listener) {
297 return addLowPriority(std::forward<ListenerType>(listener));
298 }
299
300 /**
301 * Removes a listener by the id.
302 *
303 * The listener is not called after this function returns: it waits for the calls of the listener in progress on
304 * the other threads. Called from a listener or a callback of the library, it does not wait (see
305 * ListenerCallScope): a call in progress on another thread may then still run.
306 *
307 * @param id The listener id
308 */
309 void remove(std::size_t id) {
310 if (id == FAKE_ID) {
311 return;
312 }
313
314 std::shared_ptr<Listener> removed{};
315
316 {
317 std::lock_guard guard{mutex_};
318
319 if (!listeners_) {
320 return;
321 }
322
323 const auto found = std::find_if(listeners_->begin(), listeners_->end(), [id](const auto &listener) {
324 return listener->id == id;
325 });
326
327 if (found == listeners_->end()) {
328 return;
329 }
330
331 const auto index = static_cast<std::size_t>(found - listeners_->begin());
332 auto list = std::make_shared<List>(*listeners_);
333
334 removed = *found;
335 list->erase(list->begin() + static_cast<typename List::difference_type>(index));
336 listeners_ = std::move(list);
337
338 if (index < mainListenersCount_) {
339 mainListenersCount_--;
340 }
341 }
342
343 markRemoved(*removed);
344 waitForCalls(*removed);
345 }
346
347 /**
348 * Removes all the listeners.
349 *
350 * The listeners are not called after this function returns, as after remove(). The handler can be used again.
351 */
352 void removeAll() {
353 std::shared_ptr<const List> removed{};
354
355 {
356 std::lock_guard guard{mutex_};
357
358 removed = std::exchange(listeners_, nullptr);
359 mainListenersCount_ = 0;
360 }
361
362 if (!removed) {
363 return;
364 }
365
366 // All are marked first: a listener that follows the one in progress in a notification is not called.
367 for (const auto &listener : *removed) {
368 markRemoved(*listener);
369 }
370
371 for (const auto &listener : *removed) {
372 waitForCalls(*listener);
373 }
374 }
375
376 /**
377 * Removes a listener by the id. See remove().
378 *
379 * @param id The listener id
380 */
381 void operator-=(std::size_t id) {
382 return remove(id);
383 }
384};
385
386DXFCPP_END_NAMESPACE
387
388/// @}
389
390DXFCXX_DISABLE_MSC_WARNINGS_POP()
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:1125
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:1168
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_password(dxfc_dxendpoint_t endpoint, const char *password)
Changes password for this endpoint.
Definition DXEndpoint.cpp:1451
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_publisher(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxpublisher_t *publisher)
Definition DXEndpoint.cpp:1652
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:1200
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:1598
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_disconnect(dxfc_dxendpoint_t endpoint)
Terminates all remote network connections.
Definition DXEndpoint.cpp:1513
#define DXFCPP_EXPORT
Definition api.h:35
void * dxfc_dxendpoint_builder_t
The dxFeed endpoint's builder handle.
Definition api.h:219
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:1395
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:1564
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:190
dxfc_dxendpoint_state_t
Represents the current state of endpoint.
Definition api.h:161
@ DXFC_DXENDPOINT_STATE_CLOSED
Endpoint was closed.
Definition api.h:181
@ DXFC_DXENDPOINT_STATE_NOT_CONNECTED
Endpoint was created by is not connected to remote endpoints.
Definition api.h:165
@ DXFC_DXENDPOINT_STATE_CONNECTING
The connect function was called to establish connection to remove endpoint, but the connection is not...
Definition api.h:171
@ DXFC_DXENDPOINT_STATE_CONNECTED
The connection to the remote endpoint is established.
Definition api.h:176
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:1264
#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:1581
void * dxfc_dxendpoint_t
The dxFeed endpoint handle.
Definition api.h:210
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:1146
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_free(dxfc_dxendpoint_builder_t builder)
Removes a builder from the registry.
Definition DXEndpoint.cpp:1252
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:1473
dxfc_error_code_t
List of error codes.
Definition api.h:61
@ DXFC_EC_ERROR
The error returned if the current operation cannot be completed.
Definition api.h:72
@ DXFC_EC_SUCCESS
OK.
Definition api.h:65
@ DXFC_EC_G_ERR
dxFeed Graal Native API error.
Definition api.h:69
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:1624
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:208
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:1222
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_feed(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxfeed_t *feed)
Definition DXEndpoint.cpp:1647
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:1547
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_close(dxfc_dxendpoint_t endpoint)
Closes this endpoint.
Definition DXEndpoint.cpp:1378
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:1087
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:1496
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:1412
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_user(dxfc_dxendpoint_t endpoint, const char *user)
Changes username for this endpoint.
Definition DXEndpoint.cpp:1429
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:101
@ DXFC_DXENDPOINT_ROLE_PUBLISHER
PUBLISHER endpoint connects to the remote publisher hub (also known as multiplexor) or creates a publ...
Definition api.h:139
@ 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:128
@ 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:111
@ DXFC_DXENDPOINT_ROLE_STREAM_PUBLISHER
STREAM_PUBLISHER endpoint is similar to DXFC_DXENDPOINT_ROLE_PUBLISHER and also connects to the remot...
Definition api.h:148
@ DXFC_DXENDPOINT_ROLE_LOCAL_HUB
LOCAL_HUB endpoint is a local hub without the ability to establish network connections.
Definition api.h:155
@ 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:119
void * dxfc_dxpublisher_t
The dxFeed publisher handle.
Definition api.h:229
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:1321
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:1292
void * dxfc_dxfeed_t
The dxFeed handle.
Definition api.h:224
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:1108
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:1349
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_free(dxfc_dxendpoint_t endpoint)
Removes the dxFeed endpoint from the registry.
Definition DXEndpoint.cpp:1657
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:1530
T & operator*() const noexcept
Definition AutoClose.hpp:173
AutoClose() noexcept=default
Creates an empty AutoClose.
AutoClose(std::shared_ptr< T > entity) noexcept
Creates an AutoClose that closes the entity.
Definition AutoClose.hpp:119
~AutoClose() noexcept
Closes the entity.
Definition AutoClose.hpp:140
const std::shared_ptr< T > & get() const noexcept
Definition AutoClose.hpp:163
std::shared_ptr< T > release() noexcept
Makes this AutoClose empty without closing the entity.
Definition AutoClose.hpp:158
AutoClose & operator=(AutoClose &&other) noexcept
Closes the current entity and takes the entity of the other AutoClose, which becomes empty.
Definition AutoClose.hpp:130
operator bool() const noexcept
Definition AutoClose.hpp:178
AutoClose(AutoClose &&other) noexcept
Takes the entity of the other AutoClose, which becomes empty.
Definition AutoClose.hpp:126
T * operator->() const noexcept
Definition AutoClose.hpp:168
void reset() noexcept
Closes the entity now and makes this AutoClose empty.
Definition AutoClose.hpp:145
Builder class for DXEndpoint that supports additional configuration properties.
Definition DXEndpoint.hpp:1069
std::shared_ptr< DXEndpoint > build()
Builds DXEndpoint instance.
Definition DXEndpoint.cpp:695
std::shared_ptr< Builder > withExecutor(const std::shared_ptr< Executor > &executor)
Sets the executor that is used for notifications (events, state changes, etc.) of the endpoint to bui...
Definition DXEndpoint.hpp:1194
std::shared_ptr< Builder > withProperties(Properties &&properties)
Sets all supported properties from the provided properties object.
Definition DXEndpoint.hpp:1160
~Builder() noexcept override
Releases the GraalVM handle.
Definition DXEndpoint.cpp:733
std::shared_ptr< Builder > withRole(Role role)
Sets role for the created DXEndpoint.
Definition DXEndpoint.cpp:647
Manages network connections to feed or publisher.
Definition DXEndpoint.hpp:189
void removeMessageConnectorListener(std::size_t listenerId) noexcept
Removes a listener added with DXEndpoint::addMessageConnectorListener().
Definition DXEndpoint.cpp:946
bool isClosed() const
Definition DXEndpoint.cpp:901
SimpleHandler< void(DXEndpoint::State, DXEndpoint::State)> & onStateChange() noexcept
Returns the onStateChange handler that can be used to add or remove listeners.
Definition DXEndpoint.cpp:918
static std::shared_ptr< DXEndpoint > create(Role role)
Creates an endpoint with a specified role.
Definition DXEndpoint.cpp:888
void setRequestedAggregationPeriod(const TimePeriod &requestedAggregationPeriod) const
Sets the aggregation period that this endpoint requests from the server.
Definition DXEndpoint.cpp:568
static constexpr char DXFEED_AGGREGATION_PERIOD_PROPERTY[]
"dxfeed.aggregationPeriod"
Definition DXEndpoint.hpp:279
static constexpr char DXENDPOINT_EVENT_TIME_PROPERTY[]
"dxendpoint.eventTime"
Definition DXEndpoint.hpp:366
void setRequestedAggregationPeriod(std::chrono::milliseconds requestedAggregationPeriod) const
Sets the aggregation period that this endpoint requests from the server.
Definition DXEndpoint.cpp:573
static constexpr char NAME_PROPERTY[]
"name"
Definition DXEndpoint.hpp:206
static constexpr char DXFEED_PASSWORD_PROPERTY[]
"dxfeed.password"
Definition DXEndpoint.hpp:260
std::shared_ptr< DXFeed > getFeed() const
Definition DXEndpoint.cpp:528
static constexpr char DXSCHEME_NANO_TIME_PROPERTY[]
"dxscheme.nanoTime"
Definition DXEndpoint.hpp:399
State
Represents the current state of endpoint.
Definition DXEndpoint.hpp:491
@ CLOSED
Endpoint was closed.
Definition DXEndpoint.hpp:511
@ CONNECTING
The connect method was called to establish connection to remove endpoint, but the connection is not e...
Definition DXEndpoint.hpp:501
@ CONNECTED
The connection to the remote endpoint is established.
Definition DXEndpoint.hpp:506
@ NOT_CONNECTED
Endpoint was created by is not connected to remote endpoints.
Definition DXEndpoint.hpp:495
static constexpr char DXFEED_THREAD_POOL_SIZE_PROPERTY[]
"dxfeed.threadPoolSize"
Definition DXEndpoint.hpp:269
TimePeriodInfo getAggregationPeriodInfo() const
Returns the aggregation period that the servers report, over all connections of this endpoint.
Definition DXEndpoint.cpp:586
static constexpr char DXPUBLISHER_THREAD_POOL_SIZE_PROPERTY[]
"dxpublisher.threadPoolSize"
Definition DXEndpoint.hpp:349
void reconnect() const
Terminates all established network connections and initiates connecting again with the same address.
Definition DXEndpoint.cpp:473
std::shared_ptr< DXEndpoint > Ptr
The alias to a type of shared pointer to the DXEndpoint object.
Definition DXEndpoint.hpp:191
static std::shared_ptr< DXEndpoint > create()
Creates an endpoint with FEED role.
Definition DXEndpoint.cpp:879
void removeStateChangeListener(std::size_t listenerId) noexcept
Removes a listener notified about changes in state property.
Definition DXEndpoint.cpp:909
const std::string & getName() const &noexcept
Definition DXEndpoint.cpp:905
Role
Represents the role of an endpoint that was specified during its creation.
Definition DXEndpoint.hpp:420
@ PUBLISHER
PUBLISHER endpoint connects to the remote publisher hub (also known as multiplexor) or creates a publ...
Definition DXEndpoint.hpp:465
@ STREAM_FEED
STREAM_FEED endpoint is similar to DXEndpoint::FEED and also connects to the remote data feed provide...
Definition DXEndpoint.hpp:453
@ LOCAL_HUB
LOCAL_HUB endpoint is a local hub without the ability to establish network connections.
Definition DXEndpoint.hpp:481
@ ON_DEMAND_FEED
ON_DEMAND_FEED endpoint is similar to DXEndpoint::FEED, but it is designed to be used with OnDemandSe...
Definition DXEndpoint.hpp:444
@ STREAM_PUBLISHER
STREAM_PUBLISHER endpoint is similar to DXEndpoint::PUBLISHER and also connects to the remote publish...
Definition DXEndpoint.hpp:474
@ FEED
FEED endpoint connects to the remote data feed provider and is optimized for real-time or delayed dat...
Definition DXEndpoint.hpp:431
std::string toString() const override
Returns a string representation of the current object.
Definition DXEndpoint.cpp:754
void awaitProcessed() const
Waits until this endpoint stops processing data (becomes quiescent).
Definition DXEndpoint.cpp:509
std::shared_ptr< DXPublisher > getPublisher() const
Definition DXEndpoint.cpp:537
static constexpr char DXFEED_PROPERTIES_PROPERTY[]
"dxfeed.properties"
Definition DXEndpoint.hpp:221
std::optional< TimePeriod > getRequestedAggregationPeriod() const
Returns the aggregation period that this endpoint requests from the server, or an empty value if no p...
Definition DXEndpoint.cpp:556
static constexpr char DXSCHEME_ENABLED_PROPERTY_PREFIX[]
"dxscheme.enabled."
Definition DXEndpoint.hpp:413
State getState() const
Returns the state of this endpoint.
Definition DXEndpoint.cpp:433
static constexpr char DXPUBLISHER_ADDRESS_PROPERTY[]
"dxpublisher.address"
Definition DXEndpoint.hpp:340
std::vector< MessageConnectorInfo > getConnectors() const
Returns the snapshots of the message connectors of this endpoint: one for each address it connects to...
Definition DXEndpoint.cpp:926
void awaitNotConnected() const
Waits while this endpoint state becomes NOT_CONNECTED or CLOSED.
Definition DXEndpoint.cpp:500
static constexpr char DXFEED_STRIPE_PROPERTY[]
"dxfeed.stripe"
Definition DXEndpoint.hpp:296
static std::shared_ptr< DXEndpoint > getInstance(Role role)
Returns a default application-wide singleton instance of DXEndpoint for a specific role.
Definition DXEndpoint.cpp:861
void close() const
Closes this endpoint.
Definition DXEndpoint.cpp:956
static constexpr char DXFEED_REQUESTED_AGGREGATION_PERIOD_PROPERTY[]
"dxfeed.requestedAggregationPeriod"
Definition DXEndpoint.hpp:321
void setRequestedAggregationPeriod(std::int64_t requestedAggregationPeriod) const
Sets the aggregation period that this endpoint requests from the server.
Definition DXEndpoint.cpp:577
void disconnect() const
Terminates all remote network connections.
Definition DXEndpoint.cpp:482
void closeAndAwaitTermination() const
Closes this endpoint and wait until all pending data processing tasks are completed.
Definition DXEndpoint.cpp:518
static std::shared_ptr< DXEndpoint > getInstance()
Returns a default application-wide singleton instance of DXEndpoint with a FEED role.
Definition DXEndpoint.cpp:852
static constexpr char DXPUBLISHER_PROPERTIES_PROPERTY[]
"dxpublisher.properties"
Definition DXEndpoint.hpp:330
static constexpr char DXFEED_WILDCARD_ENABLE_PROPERTY[]
"dxfeed.wildcard.enable"
Definition DXEndpoint.hpp:288
static constexpr char DXFEED_ADDRESS_PROPERTY[]
"dxfeed.address"
Definition DXEndpoint.hpp:240
static constexpr char DXFEED_STICKY_SUBSCRIPTION_PROPERTY[]
"dxfeed.stickySubscriptionPeriod"
Definition DXEndpoint.hpp:304
static constexpr char DXFEED_USER_PROPERTY[]
"dxfeed.user"
Definition DXEndpoint.hpp:250
void disconnectAndClear() const
Terminates all remote network connections and clears stored data.
Definition DXEndpoint.cpp:491
Role getRole() const noexcept
Returns the role of this endpoint.
Definition DXEndpoint.cpp:897
std::optional< ConnectionError > getLastConnectionError() const
Returns the last connection error of this endpoint: the newest failed connect attempt or dropped conn...
Definition DXEndpoint.cpp:922
static constexpr char DXENDPOINT_STORE_EVERYTHING_PROPERTY[]
"dxendpoint.storeEverything"
Definition DXEndpoint.hpp:379
static std::shared_ptr< Builder > newBuilder()
Creates a new Builder instance.
Definition DXEndpoint.cpp:870
Main entry class for dxFeed API (read it first).
Definition DXFeed.hpp:142
Provides API for publishing of events to local or remote DXFeed.
Definition DXPublisher.hpp:62
Marks all event types that can be received via dxFeed API.
Definition EventType.hpp:42
std::string toString() const override
Returns a string representation of the current object.
Definition api.cpp:57
virtual std::int64_t getEventTime() const noexcept
Returns time when an event was created or zero when time is not available.
Definition api.cpp:44
virtual void assign(std::shared_ptr< EventType > event)
Replaces the contents of the event.
Definition api.cpp:53
virtual void setEventTime(std::int64_t eventTime) noexcept
Changes event creation time.
Definition api.cpp:48
static bool isActive() noexcept
Provides on-demand historical tick data replay controls.
Definition OnDemandService.hpp:77
A helper class needed to construct smart pointers to objects and does not allow explicit construction...
Definition SharedEntity.hpp:80
static auto createShared(Args &&...args)
Creates a smart pointer to an object.
Definition SharedEntity.hpp:95
A base abstract "shared entity" class. Has some helpers for dynamic polymorphism.
Definition SharedEntity.hpp:25
virtual std::string toString() const
Returns a string representation of the current object.
Definition SharedEntity.hpp:69
std::shared_ptr< T > sharedAs() const noexcept
Returns a pointer to the current object wrapped in a smart pointer to type T or std::shared_ptr<T>{nu...
Definition SharedEntity.hpp:60
std::shared_ptr< T > sharedAs() noexcept
Returns a pointer to the current object wrapped in a smart pointer to type T or std::shared_ptr<T>{nu...
Definition SharedEntity.hpp:49
std::shared_ptr< SharedEntity > Ptr
The alias to a type of shared pointer to the SharedEntity object.
Definition SharedEntity.hpp:27
bool is() const noexcept
Checks that the object is of type T: its dynamic type is T or derived from T.
Definition SharedEntity.hpp:38
void remove(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:309
SimpleHandler(const char *component) noexcept
Creates the new handler.
Definition Handler.hpp:197
void removeAll()
Removes all the listeners.
Definition Handler.hpp:352
SimpleHandler() noexcept=default
Creates the new handler.
void operator-=(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:381
void operator()(ArgTypes... args) noexcept
Calls the listeners on the current thread and passes the args to them.
Definition Handler.hpp:254
void handle(ArgTypes... args) noexcept
Calls the listeners on the current thread and passes the args to them.
Definition Handler.hpp:229
A thread-safe list of listeners with a given signature.
Definition Handler.hpp:63
Immutable value class for a range of time periods: the minimum and the maximum period in milliseconds...
Definition TimePeriodInfo.hpp:30
Value class for a period of time with support for ISO8601 duration format.
Definition TimePeriod.hpp:29
The simple key-value structure that represents an endpoint's property.
Definition api.h:196
const char * key
The property's key.
Definition api.h:198
const char * value
The property's value.
Definition api.h:200