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