dxFeed Graal CXX API v5.0.0
Loading...
Searching...
No Matches
DXEndpoint.hpp
1// Copyright (c) 2025 Devexperts LLC.
2// SPDX-License-Identifier: MPL-2.0
3
4#pragma once
5
6#include "../internal/Conf.hpp"
7
9
10#include "../executors/InPlaceExecutor.hpp"
11#include "../internal/Common.hpp"
12#include "../internal/Handler.hpp"
13#include "../internal/JavaObjectHandle.hpp"
14#include "./DXFeed.hpp"
15#include "./DXPublisher.hpp"
16
17#include <string>
18#include <type_traits>
19#include <unordered_map>
20#include <unordered_set>
21
23
24struct DXPublisher;
25struct DXFeed;
26struct OnDemandService;
27
28/**
29 * Manages network connections to @ref DXFeed "feed" or
30 * @ref DXPublisher "publisher". There are per-process (per GraalVM Isolate for now) ready-to-use singleton instances
31 * that are available with DXEndpoint::getInstance() and DXEndpoint::getInstance(Role) methods as well as
32 * factory methods DXEndpoint::create() and DXEndpoint::create(Role), and a number of configuration methods. Advanced
33 * properties can be configured using
34 * @ref DXEndpoint::newBuilder() "newBuilder()".@ref DXEndpoint::Builder::withProperty(const StringLike&, const StringLike&) "withProperty(key, value)".@ref DXEndpoint::Builder::build() "build()".
35 *
36 * See DXFeed for details on how to subscribe to symbols and receive events.
37 *
38 * <h3>Endpoint role</h3>
39 *
40 * Each endpoint has a role that is specified on its creation and cannot be changed afterward.
41 * The default factory method DXEndpoint::create() creates an endpoint with a @ref Role::FEED "FEED" role.
42 * Endpoints with other roles are created with DXEndpoint::create(Role) factory method. Endpoint role is
43 * represented by @ref Role "DXEndpoint::Role" enumeration.
44 *
45 * Endpoint role defines the behavior of its @ref DXEndpoint::connect(const StringLike&) "connect" method:
46 *
47 * - @ref Role::FEED "FEED" connects to the remote data feed provider and is optimized for real-time or
48 * delayed data processing (<b>this is a default role</b>).
49 * DXEndpoint::getFeed() method returns a feed object that subscribes to this remote data feed provider and receives
50 * events from it. When event processing threads cannot keep up (don't have enough CPU time), data is dynamically
51 * conflated to minimize latency between received events and their processing time. For example,
52 * - <b>`DXEndpoint::create()->connect("demo.dxfeed.com:7300")->getFeed()`</b> returns a demo feed from dxFeed with
53 * sample market quotes.
54 * - <b>`DXEndpoint::create()->connect("localhost:7400")->getFeed()`</b> returns a feed connected to a
55 * publisher that is running on the same host. See the example below.
56 * - <b>`DXEndpoint::create()->connect("file:demo-sample.data")->getFeed()`</b> returns a feed that is connected to
57 * a "demo-sample.data" file and plays back it as if it was received in real time.
58 *
59 * This endpoint is automatically connected to the configured data feed, as explained in the default properties section.
60 * - @ref Role::ON_DEMAND_FEED "ON_DEMAND_FEED" is similar to @ref Role::FEED "FEED", but it is designed to be used with
61 * OnDemandService for historical data replay only. It is configured with default properties but is not connected
62 * automatically to the data provider until the @ref OnDemandService::replay(std::int64_t, double) "OnDemandService::replay" method is invoked.
63 * - @ref Role::STREAM_FEED "STREAM_FEED" is similar to @ref Role::FEED "FEED" and also connects to the remote data
64 * feed provider, but is designed for bulk parsing of data from files. DXEndpoint::getFeed() method returns feed
65 * object that subscribes to the data from the opened files and receives events from them. Events from the files are
66 * not conflated and are processed as fast as possible. Note that in this role, the DXFeed::getLastEvent () method does
67 * not work and time-series subscription is not supported. For example,
68 * ```cpp
69 * auto endpoint = DXEndpoint::create(DXEndpoint::Role::STREAM_FEED);
70 * auto feed = endpoint->getFeed();
71 * ```
72 * creates a feed that is ready to read data from the file as soon as the following code is invoked:
73 * ```cpp
74 * endpoint->connect("file:demo-sample.data[speed=max]");
75 * ```
76 * "[speed=max]" clause forces to the file reader to play back all the data from "demo-sample.data" file as fast as
77 * data subscribers are processing it.
78 * - @ref Role::PUBLISHER "PUBLISHER" connects to the remote publisher hub (also known as multiplexor) or creates a
79 * publisher on the local host. DXEndpoint::getPublisher() method returns a publisher object that publishes events to
80 * all connected feeds. For example,
81 * <b>`DXEndpoint->create(DXEndpoint::Role::PUBLISHER)->connect(":7400")->getPublisher()`</b> returns a publisher
82 * waiting for connections on TCP/IP port 7400. The published events will be delivered to all feeds that are
83 * connected to this publisher. This endpoint is automatically connected to the configured data feed, as explained in
84 * the default properties section.
85 * - @ref Role::LOCAL_HUB "LOCAL_HUB" creates a local hub without the ability to establish network connections.
86 * Events that are published via @ref DXEndpoint::getPublisher() "publisher" are delivered to local @ref
87 * DXEndpoint::getFeed() "feed" only.
88 *
89 * <h3>Endpoint state</h3>
90 *
91 * Each endpoint has a state that can be retrieved with the DXEndpoint::getState () method.
92 * When an endpoint is created with any role and the default address is not specified in default properties, then it is not
93 * connected to any remote endpoint.
94 * Its state is @ref State::NOT_CONNECTED "NOT_CONNECTED".
95 *
96 * @ref Role::FEED "Feed" and @ref Role::PUBLISHER "publisher" endpoints can connect to remote endpoints of the opposite
97 * role. Connection is initiated by @ref DXEndpoint::connect(const StringLike&) "connect" method.
98 * The endpoint state becomes @ref State::CONNECTING "CONNECTING".
99 *
100 * When the actual connection to the remote endpoint is established, the endpoint state becomes
101 * @ref State::CONNECTED "CONNECTED".
102 *
103 * Network connections can temporarily break and return endpoint back into the @ref State::CONNECTING "CONNECTING" state.
104 * File connections can be completed and return endpoint into the @ref State::NOT_CONNECTED "NOT_CONNECTED" state.
105 *
106 * Connection to the remote endpoint can be terminated with the DXEndpoint::disconnect() method.
107 * The endpoint state becomes @ref State::NOT_CONNECTED "NOT_CONNECTED".
108 *
109 * Endpoint can be closed with DXEndpoint::close() method. The endpoint state becomes @ref State::CLOSED "CLOSED". This
110 * is a final state. All connections are terminated and all internal resources that are held by this endpoint are freed.
111 * No further connections can be initiated.
112 *
113 * <h3>Event times</h3>
114 *
115 * The EventType::getEventTime() on received events is available only when the endpoint is created with
116 * DXEndpoint::DXENDPOINT_EVENT_TIME_PROPERTY property and the data source has embedded event times. This is typically
117 * true only for data events that are read from historical tape files (see above) and from OnDemandService. Events that
118 * are coming from network connections do not have embedded event time information, and event time is not available
119 * for them anyway.
120 *
121 * <h3><a name="defaultPropertiesSection">Default properties</a></h3>
122 *
123 * Default properties are loaded from the "dxfeed.properties" or "dxpublisher.properties" file depending on
124 * the @ref Role "role" of the created endpoint. "dxfeed.properties" is used for @ref Role::FEED "FEED" and
125 * @ref Role::ON_DEMAND_FEED "ON_DEMAND_FEED", "dxpublisher.properties" is used for @ref Role::PUBLISHER "PUBLISHER".
126 * @ref Role::STREAM_FEED "STREAM_FEED" and @ref Role::LOCAL_HUB "LOCAL_HUB" do not support the properties file.
127 *
128 * The location of this file can be specified using
129 * @ref Builder::withProperty(const StringLike&, const StringLike&) "withProperty"(::DXFEED_PROPERTIES_PROPERTY, path)
130 * or
131 * @ref Builder::withProperty(const StringLike&, const StringLike&) "withProperty"(::DXPUBLISHER_PROPERTIES_PROPERTY,
132 * path) correspondingly. When the location of this file is not explicitly specified using
133 * @ref Builder::withProperty(const StringLike&, const StringLike&) "withProperty" method, then the file path is taken
134 * from a system property with the corresponding name.
135 *
136 * Defaults for individual properties can be also provided using system properties when they are not specified
137 * in the configuration file.
138 *
139 * The DXEndpoint::NAME_PROPERTY is the exception to the above rule. It is never loaded from system properties.
140 * It can be only specified in the configuration file or programmatically. There is a convenience
141 * @ref Builder::withName(const StringLike&) "Builder.withName" method for it. It is recommended to assign short and
142 * meaningful endpoint names when multiple endpoints are used in the same process (one GraalVM Isolate for now).
143 * The name of the endpoint shall describe its role in the particular application.
144 *
145 * Note that individual properties that are programmatically set using @ref Builder::withProperty(const StringLike&, const StringLike&) "withProperty"
146 * method always take precedence.
147 *
148 * @ref Role::FEED "FEED" and @ref Role::PUBLISHER "PUBLISHER" automatically establish connection on creation
149 * when the corresponding DXEndpoint::DXFEED_ADDRESS_PROPERTY or DXEndpoint::DXPUBLISHER_ADDRESS_PROPERTY is specified.
150 *
151 * <h3>Permanent subscription</h3>
152 *
153 * Endpoint properties can define permanent subscription for specific sets of symbols and event types in
154 * the data feed, so that DXFeed methods like @ref DXFeed::getLastEventIfSubscribed "getLastEventIfSubscribed",
155 * @ref DXFeed::getIndexedEventsIfSubscribed "getIndexedEventsIfSubscribed" and
156 * @ref DXFeed::getTimeSeriesIfSubscribed "getTimeSeriesIfSubscribed" can be used without a need to create a
157 * separate DXFeedSubscription object. Please contact dxFeed support for details
158 * on the required configuration.
159 *
160 * <h3>Threads and locks</h3>
161 *
162 * This class is thread-safe and can be used concurrently from multiple threads without external synchronization.
163 *
164 * [Javadoc.](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXEndpoint.html)
165 *
166 * Some methods that are not marked `noexcept` may throw exceptions:
167 *
168 * @throws InvalidArgumentException if the entity's handle is invalid.
169 * @throws JavaException if something happened with the dxFeed API backend
170 * @throws GraalException if something happened with the GraalVM
171 */
173 /// The alias to a type of shared pointer to the DXEndpoint object
174 using Ptr = std::shared_ptr<DXEndpoint>;
175
176 /// The alias to a type of unique pointer to the DXEndpoint object
178
179 friend struct OnDemandService;
180
181 /**
182 * `"name"`
183 *
184 * Defines property for endpoint name that is used to distinguish multiple endpoints
185 * in the same process in logs and in other diagnostic means.
186 * Use Builder::withProperty(const StringLike&, const StringLike&) method.
187 * This property is also changed by the Builder::withName(const StringLike&) method.
188 */
189 static const std::string NAME_PROPERTY;
190
191 /**
192 * `"dxfeed.properties"`
193 *
194 * Defines a path to a file with properties for an endpoint with the role @ref Role::FEED "FEED" or
195 * @ref Role::ON_DEMAND_FEED "ON_DEMAND_FEED".
196 * By default, properties are loaded from a path resource named "dxfeed.properties".
197 *
198 * @see Builder::withProperty(const StringLike&, const StringLike&)
199 */
200 static const std::string DXFEED_PROPERTIES_PROPERTY;
201
202 /**
203 * `"dxfeed.address"`
204 *
205 * Defines default connection address for an endpoint with the role @ref Role::FEED "FEED"
206 * or @ref Role::ON_DEMAND_FEED "ON_DEMAND_FEED".
207 * Connection is established to this address by the role @ref Role::FEED "FEED" as soon as the endpoint is created, while
208 * the role @ref Role::ON_DEMAND_FEED "ON_DEMAND_FEED" waits until OnDemandService::(std::int64_t, double) is invoked
209 * before connecting.
210 *
211 * By default, without this property, a connection is not established until @ref DXEndpoint::connect(const StringLike&) "connect(address)" is invoked.
212 *
213 * Credentials for access to premium services may be configured with
214 * DXEndpoint::DXFEED_USER_PROPERTY and DXEndpoint::DXFEED_PASSWORD_PROPERTY.
215 *
216 * @see Builder::withProperty(const StringLike&, const StringLike&)
217 */
218 static const std::string DXFEED_ADDRESS_PROPERTY;
219
220 /**
221 * `"dxfeed.user"`
222 *
223 * Defines default username for an endpoint with the role @ref Role::FEED "FEED" or @ref Role::ON_DEMAND_FEED
224 * "ON_DEMAND_FEED".
225 *
226 * @see DXEndpoint::user(const StringLike&)
227 */
228 static const std::string DXFEED_USER_PROPERTY;
229
230 /**
231 * `"dxfeed.password"`
232 *
233 * Defines default password for an endpoint with role @ref Role::FEED "FEED" or @ref Role::ON_DEMAND_FEED
234 * "ON_DEMAND_FEED".
235 *
236 * @see DXEndpoint::password(const StringLike&)
237 */
238 static const std::string DXFEED_PASSWORD_PROPERTY;
239
240 /**
241 * `"dxfeed.threadPoolSize"`
242 *
243 * Defines thread pool size for an endpoint with the role @ref Role::FEED "FEED".
244 * By default, the thread pool size is equal to the number of available processors.
245 * @see Builder::withProperty(const StringLike&, const StringLike&)
246 */
247 static const std::string DXFEED_THREAD_POOL_SIZE_PROPERTY;
248
249 /**
250 * `"dxfeed.aggregationPeriod"`
251 *
252 * Defines a data aggregation period for an endpoint with the role @ref Role::FEED "FEED" that
253 * limits the rate of data notifications. For example, setting the value of this property
254 * to "0.1s" limits notification to once every "100ms" (at most 10 per second).
255 * @see Builder::withProperty(const StringLike&, const StringLike&)
256 */
257 static const std::string DXFEED_AGGREGATION_PERIOD_PROPERTY;
258
259 /**
260 * `"dxfeed.wildcard.enable"`
261 *
262 * Set this property to `true` to turn on wildcard support.
263 * By default, the endpoint does not support wildcards. This property is needed for
264 * WildcardSymbol support and for the use of "tape:..." address in DXPublisher.
265 */
266 static const std::string DXFEED_WILDCARD_ENABLE_PROPERTY;
267
268 /**
269 * `"dxpublisher.properties"`
270 *
271 * Defines a path to a file with properties for an endpoint with the role @ref Role::PUBLISHER "PUBLISHER".
272 * By default, properties are loaded from a classpath resource named "dxpublisher.properties".
273 * @see Builder::withProperty(const StringLike&, const StringLike&)
274 */
275 static const std::string DXPUBLISHER_PROPERTIES_PROPERTY;
276
277 /**
278 * `"dxpublisher.address"`
279 *
280 * Defines default connection address for an endpoint with the role @ref Role::PUBLISHER "PUBLISHER".
281 * Connection is established to this address as soon as an endpoint is created.
282 * By default, the connection is not established until DXEndpoint::connect(const StringLike&) is invoked.
283 * @see Builder::withProperty(const StringLike&, const StringLike&)
284 */
285 static const std::string DXPUBLISHER_ADDRESS_PROPERTY;
286
287 /**
288 * `"dxpublisher.threadPoolSize"`
289 *
290 * Defines thread pool size for an endpoint with the role @ref Role::PUBLISHER "PUBLISHER".
291 * By default, the thread pool size is equal to the number of available processors.
292 * @see Builder#withProperty(const StringLike&, const StringLike&)
293 */
295
296 /**
297 * `"dxendpoint.eventTime"`
298 *
299 * Set this property to `true` to enable @ref EventType::getEventTime() "event time" support.
300 * By default, the endpoint does not support event time.
301 *
302 * The event time is available only when the corresponding DXEndpoint is created with this property and
303 * the data source has embedded event times. This is typically true only for data events
304 * that are read from historical tape files and from OnDemandService.
305 * Events that are coming from network connections do not have embedded event time information, and
306 * event time is not available for them anyway.
307 *
308 * Use this property if you need to work with historical data coming from files
309 * or from OnDemandService or writing data with times to file via DXPublisher using a "tape:..." address.
310 */
311 static const std::string DXENDPOINT_EVENT_TIME_PROPERTY;
312
313 /**
314 * `"dxendpoint.storeEverything"`
315 *
316 * Set this property to store all @ref LastingEvent "lasting" and @ref IndexedEvent "indexed" events even when
317 * there is no subscription on them. By default, the endpoint stores only events from subscriptions. It works in
318 * the same way both for DXFeed and DXPublisher.
319 *
320 * Use this property with extreme care,
321 * since API does not currently provide any means to remove those events from the storage, and there might
322 * be an effective memory leak if the spaces of symbols on which events are published grow without a bound.
323 */
324 static const std::string DXENDPOINT_STORE_EVERYTHING_PROPERTY;
325
326 /**
327 * `"dxscheme.nanoTime"`
328 *
329 * Set this property to `true` to turn on nanoseconds precision business time.
330 * By default, this feature is turned off.
331 * Business time in most events is available with
332 * millisecond precision by default, while Quote events business @ref Quote::getTime() "time" is available with
333 * seconds precision.
334 *
335 * This method provides a higher-level control than turning on individual properties that are responsible
336 * for nano-time via DXEndpoint::DXSCHEME_ENABLED_PROPERTY_PREFIX. The later can be used to override of fine-time
337 * nano-time support for individual fields. Setting this property to `true` is essentially
338 * equivalent to setting:
339 * ```ini
340 * dxscheme.enabled.Sequence=*
341 * dxscheme.enabled.TimeNanoPart=*
342 * ```
343 */
344 static const std::string DXSCHEME_NANO_TIME_PROPERTY;
345
346 /**
347 * `"dxscheme.enabled."`
348 *
349 * Defines whether a specified field from the scheme should be enabled instead of its default behavior.
350 * Use it according to the following format:
351 * <b>`dxscheme.enabled.<field_property_name>=<event_name_mask_glob>`</b>
352 *
353 * For example, <b>`dxscheme.enabled.TimeNanoPart=Trade`</b> enables `NanoTimePart` internal field
354 * only in Trade events.
355 *
356 * There is a shortcut for turning on nano-time support using DXEndpoint::DXSCHEME_NANO_TIME_PROPERTY.
357 */
358 static const std::string DXSCHEME_ENABLED_PROPERTY_PREFIX;
359
360 /**
361 * Represents the role of an endpoint that was specified during its @ref DXEndpoint::create() "creation".
362 *
363 * @see DXEndpoint
364 */
365 enum class Role : std::int32_t {
366 /**
367 * `FEED` endpoint connects to the remote data feed provider and is optimized for real-time or
368 * delayed data processing (<b>this is a default role</b>). DXEndpoint::getFeed() method
369 * returns the feed object that subscribes to the remote data feed provider and receives events from it.
370 * When event processing threads cannot keep up (don't have enough CPU time), data is dynamically conflated to
371 * minimize latency between received events and their processing time.
372 *
373 * This endpoint is automatically connected to the configured data feed, as explained in
374 * <a href="#defaultPropertiesSection">the default properties section</a>.
375 */
377
378 /**
379 * `ON_DEMAND_FEED` endpoint is similar to DXEndpoint::FEED, but it is designed to be used with OnDemandService
380 * for historical data replay only. It is configured with <a href="#defaultPropertiesSection">default properties</a>,
381 * but is not connected automatically to the data provider until @ref OnDemandService::(std::int64_t,double) "OnDemandService.replay"
382 * method is invoked.
383 *
384 * `ON_DEMAND_FEED` endpoint cannot be connected to an ordinary data feed at all.
385 * OnDemandService::stopAndResume() will have a similar effect to OnDemandService::stopAndClear().
386 *
387 * @see OnDemandService
388 */
390
391 /**
392 * `STREAM_FEED` endpoint is similar to DXEndpoint::FEED and also connects to the remote data feed provider,
393 * but is designed for bulk parsing of data from files. DXEndpoint::getFeed() method
394 * returns feed object that subscribes to the data from the opened files and receives events from them.
395 * Events from the files are not conflated, are not skipped, and are processed as fast as possible.
396 * Note that in this role, the DXFeed::getLastEvent method does not work.
397 */
399
400 /**
401 * `PUBLISHER` endpoint connects to the remote publisher hub (also known as multiplexor) or
402 * creates a publisher on the local host. DXEndpoint#getPublisher() method returns
403 * a publisher object that publishes events to all connected feeds.
404 * Note that in this role, the DXFeed::getLastEvent method does not work and
405 * time-series subscription is not supported.
406 *
407 * This endpoint is automatically connected to the configured data feed, as explained in
408 * <a href="#defaultPropertiesSection">the default properties section</a>.
409 */
411
412 /**
413 * `STREAM_PUBLISHER` endpoint is similar to DXEndpoint::PUBLISHER and also connects to the remote publisher
414 * hub, but is designed for bulk publishing of data. DXEndpoint::getPublisher() method returns a
415 * publisher object that publishes events to all connected feeds. Published events are not conflated, are not
416 * skipped, and are processed as fast as possible. Note that in this role, the DXFeed::getLastEvent method
417 * does not work and time-series subscription is not supported.
418 */
420
421 /**
422 * `LOCAL_HUB` endpoint is a local hub without the ability to establish network connections.
423 * Events that are published via @ref DXEndpoint::getPublisher() "publisher" are delivered to local
424 * @ref DXEndpoint::getFeed() "feed" only.
425 */
427 };
428
429 static std::string roleToString(Role role);
430
431 /**
432 * Represents the current state of endpoint.
433 *
434 * @see DXEndpoint
435 */
436 enum class State : std::int32_t {
437 /**
438 * Endpoint was created by is not connected to remote endpoints.
439 */
441
442 /**
443 * The @ref DXEndpoint::connect(const StringLike&) "connect" method was called to establish connection to
444 * remove endpoint, but the connection is not established yet or was lost.
445 */
447
448 /**
449 * The connection to the remote endpoint is established.
450 */
452
453 /**
454 * Endpoint was @ref DXEndpoint::close() "closed".
455 */
457 };
458
459 static std::string stateToString(State state);
460
461 private:
462 JavaObjectHandle<DXEndpoint> handle_{};
463 Role role_ = Role::FEED;
464 std::string name_{};
465 JavaObjectHandle<DXEndpointStateChangeListener> stateChangeListenerHandle_{};
466 SimpleHandler<void(State, State)> onStateChange_{};
467
468 // Throws:
469 // - std::bad_alloc if it was not possible to allocate the required amount of memory
470 // - InvalidArgumentException if endpointHandle is nullptr
471 // - JavaException if something happened with the dxFeed API backend
472 // - GraalException if something happened with the GraalVM
473 static std::shared_ptr<DXEndpoint> create(void *endpointHandle, Role role,
474 const std::unordered_map<std::string, std::string> &properties);
475
476 void executorImpl(const JavaObjectHandle<ExecutorTag> &executor) const;
477
478 struct Impl;
479
480 std::unique_ptr<Impl> impl_;
481
482 public:
483 explicit DXEndpoint(LockExternalConstructionTag);
484 DXEndpoint(LockExternalConstructionTag, JavaObjectHandle<DXEndpoint> &&handle, Role role, std::string name);
485
486 ~DXEndpoint() noexcept override;
487
488 /**
489 * Returns a default application-wide singleton instance of DXEndpoint with a @ref Role::FEED "FEED" role.
490 * Most applications use only a single data-source and should rely on this method to get one.
491 * This method creates an endpoint on the first use with a default configuration, as explained in
492 * <a href="#defaultPropertiesSection">the default properties section</a> of DXEndpoint class documentation.
493 * You can provide configuration via system properties as explained there.
494 *
495 * This is a shortcut to
496 * @ref DXEndpoint::getInstance(Role) "getInstance"(@ref DXEndpoint "DXEndpoint"::@ref DXEndpoint::Role "Role"::@ref
497 * DXEndpoint.Role::FEED "FEED").
498 * @see DXEndpoint::getInstance(Role)
499 * @throws InvalidArgumentException
500 * @throws JavaException
501 * @throws GraalException
502 */
503 static std::shared_ptr<DXEndpoint> getInstance();
504
505 /**
506 * Returns a default application-wide singleton instance of DXEndpoint for a specific role.
507 * Most applications use only a single data-source and should rely on this method to get one.
508 * This method creates an endpoint with the corresponding role on the first use with a default configuration, as explained in
509 * <a href="#defaultPropertiesSection">the default properties section</a> of DXEndpoint class documentation.
510 * You can provide configuration via system properties as explained there.
511 *
512 * The configuration does not have to include an address. You can use @ref DXEndpoint::connect(const StringLike&)
513 * "connect(address)" and DXEndpoint::disconnect() methods on the instance that is returned by this method to
514 * programmatically establish and tear-down connection to a user-provided address.
515 *
516 * If you need a fully programmatic configuration and/or multiple endpoints of the same role in your
517 * application, then create a custom instance of DXEndpoint with DXEndpoint::newBuilder() method, configure it,
518 * and use Builder::build() method.
519 *
520 * @param role The role of DXEndpoint instance
521 * @return The DXEndpoint instance
522 * @throws InvalidArgumentException
523 * @throws JavaException
524 * @throws GraalException
525 */
526 static std::shared_ptr<DXEndpoint> getInstance(Role role);
527
528 class Builder;
529
530 /**
531 * Creates a new Builder instance.
532 * Use Builder::build() to build an instance of DXEndpoint when all configuration properties were set.
533 *
534 * @return the created endpoint builder.
535 * @throws InvalidArgumentException
536 * @throws JavaException
537 * @throws GraalException
538 */
539 static std::shared_ptr<Builder> newBuilder();
540
541 /**
542 * Creates an endpoint with @ref Role::FEED "FEED" role.
543 * The result of this method is the same as <b>`create(DXEndpoint::Role::FEED)`</b>.
544 * This is a shortcut to
545 * @ref DXEndpoint::newBuilder() "newBuilder()"->@ref Builder::build() "build()"
546 *
547 * @return the created endpoint.
548 * @throws InvalidArgumentException
549 * @throws JavaException
550 * @throws GraalException
551 */
552 static std::shared_ptr<DXEndpoint> create();
553
554 /**
555 * Creates an endpoint with a specified role.
556 * This is a shortcut to
557 * @ref DXEndpoint::newBuilder() "newBuilder()"->@ref Builder::withRole(Role) "withRole(role)"->@ref
558 * Builder::build() "build()"
559 *
560 * @param role the role.
561 * @return the created endpoint.
562 * @throws InvalidArgumentException
563 * @throws JavaException
564 * @throws GraalException
565 */
566 static std::shared_ptr<DXEndpoint> create(Role role);
567
568 /**
569 * Returns the role of this endpoint.
570 *
571 * @return the role.
572 *
573 * @see DXEndpoint
574 */
575 Role getRole() const noexcept;
576
577 /**
578 * Returns the state of this endpoint.
579 *
580 * @return the state.
581 *
582 * @see DXEndpoint
583 * @throws InvalidArgumentException
584 * @throws JavaException
585 * @throws GraalException
586 */
587 State getState() const;
588
589 /**
590 * @return `true` if the endpoint is closed
591 * @throws InvalidArgumentException
592 * @throws JavaException
593 * @throws GraalException
594 */
595 bool isClosed() const;
596
597 /**
598 * @return The user defined endpoint's name
599 */
600 const std::string &getName() const & noexcept;
601
602 /**
603 * Adds a listener notified about changes in @ref DXEndpoint::getState() "state" property.
604 *
605 * <p>Installed listener can be removed by `id` with DXEndpoint::removeStateChangeListener method or by call
606 * `::onStateChange() -= id`;
607 *
608 * @param listener The listener to add
609 * @return the listener id
610 */
611 std::size_t addStateChangeListener(std::function<void(State, State)> listener) noexcept {
612 return onStateChange_ += std::move(listener);
613 }
614
615 /**
616 * Removes a listener notified about changes in @ref DXEndpoint::getState() "state" property.
617 * It removes the listener previously installed with DXEndpoint::addStateChangeListener method.
618 *
619 * @param listenerId The listener id to remove
620 */
621 void removeStateChangeListener(std::size_t listenerId) noexcept;
622
623 /**
624 * Returns the onStateChange @ref SimpleHandler<void(ArgTypes...)> "handler" that can be used to add or remove
625 * listeners.
626 *
627 * @return onStateChange handler with `void(State, State)` signature
628 */
629 SimpleHandler<void(DXEndpoint::State, DXEndpoint::State)> &onStateChange() noexcept;
630
631 template <typename Executor> std::shared_ptr<DXEndpoint> executor(const std::shared_ptr<Executor> &executor) {
632 executorImpl(executor->getHandle());
633
634 return sharedAs<DXEndpoint>();
635 }
636
637 /**
638 * Changes username for this endpoint.
639 * This method shall be called before @ref DXEndpoint::connect(const StringLike&) "connect"
640 * with @ref DXEndpoint::password(const StringLike&) "password" to configure service access credentials.
641 *
642 * @param user The username.
643 *
644 * @return this DXEndpoint.
645 * @throws InvalidArgumentException
646 * @throws JavaException
647 * @throws GraalException
648 */
649 std::shared_ptr<DXEndpoint> user(const StringLike &user);
650
651 /**
652 * Changes password for this endpoint.
653 * This method shall be called before @ref DXEndpoint::connect(const StringLike&) "connect"
654 * with @ref DXEndpoint::user(const StringLike&) "user" to configure service access credentials.
655 *
656 * @param password The password.
657 *
658 * @return this DXEndpoint.
659 * @throws InvalidArgumentException
660 * @throws JavaException
661 * @throws GraalException
662 */
663 std::shared_ptr<DXEndpoint> password(const StringLike&password);
664
665 /**
666 * Connects to the specified remote address. Previously established connections are closed if
667 * the new address is different from the old one.
668 * This method does nothing if the address does not change or if this endpoint is @ref State::CLOSED "CLOSED".
669 * The endpoint @ref DXEndpoint::getState() "state" immediately becomes @ref State::CONNECTING "CONNECTING"
670 * otherwise.
671 *
672 * <p> The address string is provided with the market data vendor agreement.
673 * Use "demo.dxfeed.com:7300" for a demo quote feed.
674 *
675 * <p> The simplest address strings have the following format:
676 * * `host:port` to establish a TCP/IP connection.
677 * * `:port` to listen for a TCP/IP connection with a plain socket connector (good for up to a
678 * few hundred of connections).
679 *
680 * <p>For premium services access credentials must be configured before invocation of `connect` method
681 * using @ref ::user(const StringLike&) "user" and @ref ::password(const StringLike&) "password" methods.
682 *
683 * <p> <b>This method does not wait until the connection actually gets established</b>. The actual connection
684 * establishment happens asynchronously after the invocation of this method. However, this method waits until
685 * notification about state transition from State::NOT_CONNECTED to State::CONNECTING gets processed by all
686 * listeners.
687 *
688 * [Javadoc.](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXEndpoint.html#connect-java.lang.String-)
689 *
690 * @param address The data source address.
691 * @return this DXEndpoint.
692 *
693 * @throws InvalidArgumentException
694 * @throws JavaException if something happened with the dxFeed API backend or if the address string is malformed.
695 * @throws GraalException
696 */
697 std::shared_ptr<DXEndpoint> connect(const StringLike&address);
698
699 /**
700 * Terminates all established network connections and initiates connecting again with the same address.
701 *
702 * <p>The effect of the method is alike to invoking :disconnect() and :connect(const StringLike&)
703 * with the current address, but internal resources used for connections may be reused by implementation.
704 * TCP connections with multiple target addresses will try to switch to an alternative address, configured
705 * reconnect timeouts will apply.
706 *
707 * <p><b>Note:</b> The method will not connect an endpoint that was not initially connected with
708 * :connect(const StringLike&) method or was disconnected with ::disconnect() method.
709 *
710 * <p>The method initiates a short-pathway for reconnecting, so whether observers will have a chance to see
711 * an intermediate state State#NOT_CONNECTED depends on the implementation.
712 *
713 * [Javadoc.](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXEndpoint.html#reconnect--)
714 *
715 * @throws InvalidArgumentException
716 * @throws JavaException
717 * @throws GraalException
718 */
719 void reconnect() const;
720
721 /**
722 * Terminates all remote network connections.
723 * This method does nothing if this endpoint is @ref State#CLOSED "CLOSED".
724 * The endpoint @ref ::getState() "state" immediately becomes @ref State::NOT_CONNECTED "NOT_CONNECTED" otherwise.
725 *
726 * <p>This method does not release all resources that are associated with this endpoint.
727 * Use ::close() method to release all resources.
728 *
729 * [Javadoc.](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXEndpoint.html#disconnect--)
730 *
731 * @throws InvalidArgumentException
732 * @throws JavaException
733 * @throws GraalException
734 */
735 void disconnect() const;
736
737 /**
738 * Terminates all remote network connections and clears stored data.
739 * This method does nothing if this endpoint is @ref State::CLOSED "CLOSED".
740 * The endpoint @ref ::getState() "state" immediately becomes @ref State::NOT_CONNECTED "NOT_CONNECTED" otherwise.
741 *
742 * <p>This method does not release all resources that are associated with this endpoint.
743 * Use the close() method to release all resources.
744 *
745 * [Javadoc.](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXEndpoint.html#disconnectAndClear--)
746 *
747 * @throws InvalidArgumentException
748 * @throws JavaException
749 * @throws GraalException
750 */
751 void disconnectAndClear() const;
752
753 /**
754 * Closes this endpoint. All network connections are terminated as with the ::disconnect() method, and no further
755 * connections can be established.
756 *
757 * The endpoint @ref ::getState() "state" immediately becomes @ref State::CLOSED "CLOSED".
758 * All resources associated with this endpoint are released.
759 *
760 * [Javadoc.](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXEndpoint.html#close--)
761 *
762 * @throws InvalidArgumentException
763 * @throws JavaException
764 * @throws GraalException
765 */
766 void close() const;
767
768 /**
769 * Waits while this endpoint @ref ::getState() "state" becomes @ref State::NOT_CONNECTED "NOT_CONNECTED" or
770 * @ref State::CLOSED "CLOSED". It is a signal that any files opened with the
771 * @ref connect(const StringLike&) "connect(\"file:...\")" method were finished reading, but not necessarily were
772 * completely processed by the corresponding subscription listeners. Use closeAndAwaitTermination() after this
773 * method returns to make sure that all processing has completed.
774 *
775 * <p><b>This method is blocking.</b>
776 *
777 * [Javadoc.](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXEndpoint.html#awaitNotConnected--)
778 *
779 * @throws InvalidArgumentException
780 * @throws JavaException
781 * @throws GraalException
782 */
783 void awaitNotConnected() const;
784
785 /**
786 * Waits until this endpoint stops processing data (becomes quiescent).
787 * This is important when writing data to file via "tape:..." connector to make sure that
788 * all published data was written before closing this endpoint.
789 *
790 * [Javadoc.](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXEndpoint.html#awaitProcessed--)
791 *
792 * @throws InvalidArgumentException
793 * @throws JavaException
794 * @throws GraalException
795 */
796 void awaitProcessed() const;
797
798 /**
799 * Closes this endpoint and wait until all pending data processing tasks are completed.
800 * This method performs the same actions as ::close(), but also awaits
801 * termination of all outstanding data processing tasks. It is designed to be used
802 * with @ref Role::STREAM_FEED "STREAM_FEED" role after ::awaitNotConnected() method returns
803 * to make sure that the file was completely processed.
804 *
805 * <p><b>This method is blocking.</b>
806 *
807 * [Javadoc.](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXEndpoint.html#closeAndAwaitTermination--)
808 *
809 * @throws InvalidArgumentException
810 * @throws JavaException
811 * @throws GraalException
812 */
813 void closeAndAwaitTermination() const;
814
815 std::unordered_set<EventTypeEnum> getEventTypes() const;
816
817 /**
818 * @return The feed that is associated with this endpoint.
819 * @throws InvalidArgumentException
820 * @throws JavaException
821 * @throws GraalException
822 */
823 std::shared_ptr<DXFeed> getFeed() const;
824
825 /**
826 * @return The publisher that is associated with this endpoint.
827 * @throws InvalidArgumentException
828 * @throws JavaException
829 * @throws GraalException
830 */
831 std::shared_ptr<DXPublisher> getPublisher() const;
832
833 /**
834 * Builder class for DXEndpoint that supports additional configuration properties.
835 *
836 * Some methods that are not marked `noexcept` may throw exceptions:
837 *
838 * @throws InvalidArgumentException if the handle is invalid.
839 * @throws JavaException if something happened with the dxFeed API backend
840 * @throws GraalException if something happened with the GraalVM
841 */
843 friend DXEndpoint;
844
845 JavaObjectHandle<Builder> handle_{};
846 Role role_ = Role::FEED;
847 std::unordered_map<std::string, std::string> properties_{};
848
849 // Throws:
850 // - std::bad_alloc if it was not possible to allocate the required amount of memory
851 // - JavaException if something happened with the dxFeed API backend
852 // - GraalException if something happened with the GraalVM
853 static std::shared_ptr<Builder> create();
854
855 /**
856 * Tries to load the default properties file for Role::FEED, Role::ON_DEMAND_FEED, or Role::PUBLISHER role.
857 *
858 * The default properties file is loaded only if there are no system properties or user properties set with the
859 * same key, and the file itself exists and is readable.
860 *
861 * This file must be in the <a href="https://en.wikipedia.org/wiki/.properties">Java properties file format</a>.
862 * File be named "dxfeed.properties" for Role::FEED and Role::ON_DEMAND_FEED roles
863 * or "dxpublisher.properties" for the Role::PUBLISHER role.
864 *
865 * Not thread-safe.
866 * @throws InvalidArgumentException
867 * @throws JavaException
868 * @throws GraalException
869 */
870 void loadDefaultPropertiesImpl();
871
872 public:
873 explicit Builder(LockExternalConstructionTag) noexcept;
874
875 /// Releases the GraalVM handle
876 ~Builder() noexcept override;
877
878 /**
879 * Changes the name used to distinguish multiple endpoints
880 * in the same process (GraalVM Isolate) in logs and in other diagnostic means.
881 * This is a shortcut for @ref ::withProperty "withProperty"(::NAME_PROPERTY, `name`)
882 *
883 * @param name The endpoint's name
884 *
885 * @return `this` endpoint builder.
886 * @throws InvalidArgumentException
887 * @throws JavaException
888 * @throws GraalException
889 */
890 std::shared_ptr<Builder> withName(const StringLike&name);
891
892 /**
893 * Sets role for the created DXEndpoint.
894 * The default role is @ref Role::FEED "FEED".
895 *
896 * @param role The endpoint's role
897 *
898 * @return `this` endpoint builder.
899 * @throws InvalidArgumentException
900 * @throws JavaException
901 * @throws GraalException
902 */
903 std::shared_ptr<Builder> withRole(Role role);
904
905 /**
906 * Sets the specified property. Unsupported properties are ignored.
907 *
908 * @param key The endpoint's property key
909 * @param value The endpoint's property value
910 * @return `this` endpoint builder.
911 *
912 * @see ::supportsProperty(const StringLike&)
913 * @throws InvalidArgumentException
914 * @throws JavaException
915 * @throws GraalException
916 */
917 std::shared_ptr<Builder> withProperty(const StringLike&key, const StringLike&value);
918
919 /**
920 * Sets all supported properties from the provided properties object.
921 *
922 * @tparam Properties The properties' type (std::map, std::unordered_map, etc.)
923 * @param properties The endpoint's properties
924 * @return `this` endpoint builder.
925 *
926 * @see ::withProperty(const StringLike&, const StringLike&)
927 * @throws InvalidArgumentException
928 * @throws JavaException
929 * @throws GraalException
930 */
931 template <typename Properties> std::shared_ptr<Builder> withProperties(Properties &&properties) {
932 if constexpr (Debugger::isDebug) {
933 Debugger::debug("DXEndpoint::Builder{" + handle_.toString() + "}::withProperties(properties[" +
934 std::to_string(properties.size()) + "])");
935 }
936
937 for (auto &&[k, v] : properties) {
939 }
940
941 return sharedAs<Builder>();
942 }
943
944 /**
945 * Checks if a property is supported
946 *
947 * @param key The property's key to be checked for support
948 * @return `true` if the corresponding property key is supported.
949 *
950 * @see ::withProperty(const StringLike&, const StringLike&)
951 * @throws InvalidArgumentException
952 * @throws JavaException
953 * @throws GraalException
954 */
955 bool supportsProperty(const StringLike&key) const;
956
957 /**
958 * Builds DXEndpoint instance.
959 *
960 * @return the created endpoint.
961 * @throws InvalidArgumentException
962 * @throws JavaException
963 * @throws GraalException
964 */
965 std::shared_ptr<DXEndpoint> build();
966 };
967
968 std::string toString() const override;
969};
970
972
973template <typename OS> OS &operator<<(OS &os, dxfcpp::DXEndpoint::State state) {
974 os << dxfcpp::DXEndpoint::stateToString(state);
975
976 return os;
977}
978
#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_MSC_WARNINGS_PUSH(warnings)
Definition Conf.hpp:30
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
Marks all event types that can be received via dxFeed API.
Definition EventType.hpp:31
Provides on-demand historical tick data replay controls.
Definition OnDemandService.hpp:71
A base abstract "shared entity" class. Has some helpers for dynamic polymorphism.
Definition SharedEntity.hpp:20
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