dxFeed Graal CXX API
|
Manages network connections to feed or publisher. More...
#include <DXEndpoint.hpp>
Classes | |
class | Builder |
Builder class for DXEndpoint that supports additional configuration properties. More... | |
Public Types | |
enum class | Role : std::int32_t { FEED , ON_DEMAND_FEED , STREAM_FEED , PUBLISHER , STREAM_PUBLISHER , LOCAL_HUB } |
Represents the role of endpoint that was specified during its creation. More... | |
enum class | State : std::int32_t { NOT_CONNECTED , CONNECTING , CONNECTED , CLOSED } |
Represents the current state of endpoint. More... | |
using | Ptr = std::shared_ptr<DXEndpoint> |
The alias to a type of shared pointer to the DXEndpoint object. | |
using | Unique = std::unique_ptr<DXEndpoint> |
The alias to a type of unique pointer to the DXEndpoint object. | |
Public Types inherited from dxfcpp::SharedEntity | |
using | Ptr = std::shared_ptr<SharedEntity> |
The alias to a type of shared pointer to the SharedEntity object. | |
Public Member Functions | |
Role | getRole () const |
Returns the role of this endpoint. | |
State | getState () const |
Returns the state of this endpoint. | |
bool | isClosed () const |
const std::string & | getName () const & |
template<typename StateChangeListener > | |
std::size_t | addStateChangeListener (StateChangeListener &&listener) noexcept |
Adds listener that is notified about changes in state property. | |
void | removeStateChangeListener (std::size_t listenerId) noexcept |
Removes listener that is notified about changes in state property. | |
auto & | onStateChange () noexcept |
Returns the onStateChange handler that can be used to add or remove listeners. | |
std::shared_ptr< DXEndpoint > | user (const std::string &user) |
Changes user name for this endpoint. | |
std::shared_ptr< DXEndpoint > | password (const std::string &password) |
Changes password for this endpoint. | |
std::shared_ptr< DXEndpoint > | connect (const std::string &address) |
Connects to the specified remote address. | |
void | reconnect () |
Terminates all established network connections and initiates connecting again with the same address. | |
void | disconnect () |
Terminates all remote network connections. | |
void | disconnectAndClear () |
Terminates all remote network connections and clears stored data. | |
void | close () |
Closes this endpoint. | |
void | awaitNotConnected () |
Waits while this endpoint state becomes NOT_CONNECTED or CLOSED. | |
void | awaitProcessed () |
Waits until this endpoint stops processing data (becomes quiescent). | |
void | closeAndAwaitTermination () |
Closes this endpoint and wait until all pending data processing tasks are completed. | |
std::shared_ptr< DXFeed > | getFeed () |
std::shared_ptr< DXPublisher > | getPublisher () |
std::string | toString () const noexcept override |
Returns a string representation of the current object. | |
Public Member Functions inherited from dxfcpp::SharedEntity | |
template<typename T > | |
bool | is () const noexcept |
Checks that pointer to the current type could be converted to type T* In other words: whether type T belongs to the type hierarchy in which the current type resides. | |
template<typename T > | |
std::shared_ptr< T > | sharedAs () noexcept |
Returns a pointer to the current object wrapped in a smart pointer to type T. | |
template<typename T > | |
std::shared_ptr< T > | sharedAs () const noexcept |
Returns a pointer to the current object wrapped in a smart pointer to type T. | |
Public Member Functions inherited from dxfcpp::Entity | |
virtual | ~Entity () noexcept=default |
The default virtual d-tor. | |
Static Public Member Functions | |
static std::shared_ptr< DXEndpoint > | getInstance () |
Returns a default application-wide singleton instance of DXEndpoint with a FEED role. | |
static std::shared_ptr< DXEndpoint > | getInstance (Role role) |
Returns a default application-wide singleton instance of DXEndpoint for a specific role. | |
static std::shared_ptr< DXEndpoint > | create () |
Creates an endpoint with FEED role. | |
static std::shared_ptr< DXEndpoint > | create (Role role) |
Creates an endpoint with a specified role. | |
static std::shared_ptr< Builder > | newBuilder () noexcept |
Creates new Builder instance. | |
Static Public Attributes | |
static const std::string | NAME_PROPERTY = "name" |
"name" | |
static const std::string | DXFEED_PROPERTIES_PROPERTY = "dxfeed.properties" |
"dxfeed.properties" | |
static const std::string | DXFEED_ADDRESS_PROPERTY = "dxfeed.address" |
"dxfeed.address" | |
static const std::string | DXFEED_USER_PROPERTY = "dxfeed.user" |
"dxfeed.user" | |
static const std::string | DXFEED_PASSWORD_PROPERTY = "dxfeed.password" |
"dxfeed.password" | |
static const std::string | DXFEED_THREAD_POOL_SIZE_PROPERTY = "dxfeed.threadPoolSize" |
"dxfeed.threadPoolSize" | |
static const std::string | DXFEED_AGGREGATION_PERIOD_PROPERTY = "dxfeed.aggregationPeriod" |
"dxfeed.aggregationPeriod" | |
static const std::string | DXFEED_WILDCARD_ENABLE_PROPERTY = "dxfeed.wildcard.enable" |
"dxfeed.wildcard.enable" | |
static const std::string | DXPUBLISHER_PROPERTIES_PROPERTY = "dxpublisher.properties" |
"dxpublisher.properties" | |
static const std::string | DXPUBLISHER_ADDRESS_PROPERTY = "dxpublisher.address" |
"dxpublisher.address" | |
static const std::string | DXPUBLISHER_THREAD_POOL_SIZE_PROPERTY = "dxpublisher.threadPoolSize" |
"dxpublisher.threadPoolSize" | |
static const std::string | DXENDPOINT_EVENT_TIME_PROPERTY = "dxendpoint.eventTime" |
"dxendpoint.eventTime" | |
static const std::string | DXENDPOINT_STORE_EVERYTHING_PROPERTY = "dxendpoint.storeEverything" |
"dxendpoint.storeEverything" | |
static const std::string | DXSCHEME_NANO_TIME_PROPERTY = "dxscheme.nanoTime" |
"dxscheme.nanoTime" | |
static const std::string | DXSCHEME_ENABLED_PROPERTY_PREFIX = "dxscheme.enabled." |
"dxscheme.enabled." | |
Manages network connections to feed or publisher.
There are per-process (per GraalVM Isolate for now) ready-to-use singleton instances that are available with DXEndpoint::getInstance() and DXEndpoint::getInstance(Role) methods as well as factory methods DXEndpoint::create() and DXEndpoint::create(Role), and a number of configuration methods. Advanced properties can be configured using newBuilder().withProperty(key, value).build().
See DXFeed for details on how to subscribe to symbols and receive events.
Each endpoint has a role that is specified on its creation and cannot be changed afterwards. The default factory method DXEndpoint::create() creates an endpoint with a FEED role. Endpoints with other roles are created with DXEndpoint::create(Role) factory method. Endpoint role is represented by DXEndpoint::Role enumeration.
Endpoint role defines the behavior of its connect method:
FEED connects to the remote data feed provider and is optimized for real-time or delayed data processing (this is a default role). DXEndpoint::getFeed() method returns a feed object that subscribes to this remote data feed provider and receives events from it. When event processing threads cannot keep up (don't have enough CPU time), data is dynamically conflated to minimize latency between received events and their processing time. For example:
DXEndpoint::create()->connect("demo.dxfeed.com:7300")->getFeed()
returns a demo feed from dxFeed with sample market quotes.DXEndpoint::create()->connect("localhost:7400")->getFeed()
returns a feed that is connected to a publisher that is running on the same host. See example below.DXEndpoint::create()->connect("file:demo-sample.data")->getFeed()
returns a feed that is connected to a "demo-sample.data" file and plays back it as if it was received in real time.This endpoint is automatically connected to the configured data feed as explained in default properties section.
DXEndpoint->create(DXEndpoint::Role::PUBLISHER)->connect(":7400")->getPublisher()
returns a publisher that is waiting for connections on TCP/IP port 7400. The published events will be delivered to all feeds that are connected to this publisher. This endpoint is automatically connected to the configured data feed as explained in default properties section.Each endpoint has a state that can be retrieved with DXEndpoint::getState() method. When endpoint is created with any role and default address is not specified in default properties, then it is not connected to any remote endpoint. Its state is NOT_CONNECTED.
Feed and publisher endpoints can connect to remote endpoints of the opposite role. Connection is initiated by connect method. The endpoint state becomes CONNECTING.
When the actual connection to the remote endpoint is established, the endpoint state becomes CONNECTED.
Network connections can temporarily break and return endpoint back into CONNECTING state. File connections can be completed and return endpoint into NOT_CONNECTED state.
Connection to the remote endpoint can be terminated with DXEndpoint::disconnect() method. The endpoint state becomes NOT_CONNECTED.
Endpoint can be closed with DXEndpoint::close() method. The endpoint state becomes CLOSED. This is a final state. All connection are terminated and all internal resources that are held by this endpoint are freed. No further connections can be initiated.
The EventType::getEventTime() on received events is available only when the endpoint is created with DXEndpoint::DXENDPOINT_EVENT_TIME_PROPERTY property and the data source has embedded event times. This is typically true only for data events that are read from historical tape files (see above) and from OnDemandService. Events that are coming from a network connections do not have an embedded event time information and event time is not available for them anyway.
Default properties are loaded from "dxfeed.properties" or "dxpublisher.properties" file depending on the role of created endpoint. "dxfeed.properties" is used for FEED and ON_DEMAND_FEED, "dxpublisher.properties" is used for PUBLISHER}. STREAM_FEED and LOCAL_HUB do not support properties file.
The location of this file can be specified using withProperty(DXFEED_PROPERTIES_PROPERTY, path) or withProperty(DXPUBLISHER_PROPERTIES_PROPERTY, path) correspondingly. When the location of this file is not explicitly specified using withProperty method, then the file path is taken from a system property with the corresponding name.
When the path to the above properties file is not provided, then a resource named "dxfeed.properties" or "dxpublisher.properties" is loaded from classpath. When classpath is set to "." (current directory), it means that the corresponding file can be placed into the current directory with any need to specify additional properties.
Defaults for individual properties can be also provided using system properties when they are not specified in the configuration file. System properties override configuration loaded from classpath resource, but don't override configuration from the user-specified configuration file.
The DXEndpoint::NAME_PROPERTY is the exception from the above rule. It is never loaded from system properties. It can be only specified in configuration file or programmatically. There is a convenience Builder.withName method for it. It is recommended to assign short and meaningful endpoint names when multiple endpoints are used in the same process (one GraalVM Isolate for now). The name of the endpoint shall describe its role in the particular application.
Note, that individual properties that are programmatically set using withProperty method always take precedence.
FEED and PUBLISHER automatically establish connection on creation when the corresponding DXEndpoint::DXFEED_ADDRESS_PROPERTY or DXEndpoint::DXPUBLISHER_ADDRESS_PROPERTY is specified.
Endpoint properties can define permanent subscription for specific sets of symbols and event types in the data feed, so that DXFeed methods like getLastEventIfSubscribed, getIndexedEventsIfSubscribed, and getTimeSeriesIfSubscribed can be used without a need to create a separate DXFeedSubscription object. Please, contact dxFeed support for details on the required configuration.
This class is thread-safe and can be used concurrently from multiple threads without external synchronization.
|
strong |
Represents the role of endpoint that was specified during its creation.
Enumerator | |
---|---|
FEED |
DXEndpoint::getFeed() method returns feed object that subscribes to the remote data feed provider and receives events from it. When event processing threads cannot keep up (don't have enough CPU time), data is dynamically conflated to minimize latency between received events and their processing time. This endpoint is automatically connected to the configured data feed as explained in default properties section. |
ON_DEMAND_FEED |
It is configured with default properties, but is not connected automatically to the data provider until OnDemandService.replay method is invoked.
|
STREAM_FEED |
DXEndpoint::getFeed() method returns feed object that subscribes to the data from the opened files and receives events from them. Events from the files are not conflated, are not skipped, and are processed as fast as possible. Note, that in this role, DXFeed::getLastEvent method does not work. |
PUBLISHER |
DXEndpoint::getPublisher() method returns a publisher object that publishes events to all connected feeds. Note, that in this role, DXFeed::getLastEvent method does not work and time-series subscription is not supported. This endpoint is automatically connected to the configured data feed as explained in default properties section. |
STREAM_PUBLISHER |
DXEndpoint::getPublisher() method returns a publisher object that publishes events to all connected feeds. Published events are not conflated, are not skipped, and are processed as fast as possible. Note, that in this role, DXFeed::getLastEvent method does not work and time-series subscription is not supported. |
LOCAL_HUB |
Events that are published via publisher are delivered to local feed only. |
|
strong |
Represents the current state of endpoint.
Enumerator | |
---|---|
NOT_CONNECTED | Endpoint was created by is not connected to remote endpoints. |
CONNECTING | The connect method was called to establish connection to remove endpoint, but connection is not actually established yet or was lost. |
CONNECTED | The connection to remote endpoint is established. |
CLOSED | Endpoint was closed. |
|
inlinenoexcept |
Adds listener that is notified about changes in state property.
Installed listener can be removed by id
with DXEndpoint::removeStateChangeListener method or by call onStateChange() -= id
;
StateChangeListener | The listener type. It can be any callable with signature: void(State, State) |
listener | The listener to add |
void dxfcpp::DXEndpoint::awaitNotConnected | ( | ) |
Waits while this endpoint state becomes NOT_CONNECTED or CLOSED.
It is a signal that any files that were opened with connect("file:...") method were finished reading, but not necessary were completely processed by the corresponding subscription listeners. Use closeAndAwaitTermination() after this method returns to make sure that all processing has completed.
This method is blocking.
void dxfcpp::DXEndpoint::awaitProcessed | ( | ) |
Waits until this endpoint stops processing data (becomes quiescent).
This is important when writing data to file via "tape:..." connector to make sure that all published data was written before closing this endpoint.
|
inline |
Closes this endpoint.
All network connection are terminated as with disconnect() method and no further connections can be established.
The endpoint state immediately becomes CLOSED. All resources associated with this endpoint are released.
void dxfcpp::DXEndpoint::closeAndAwaitTermination | ( | ) |
Closes this endpoint and wait until all pending data processing tasks are completed.
This method performs the same actions as close close(), but also awaits termination of all outstanding data processing tasks. It is designed to be used with STREAM_FEED role after awaitNotConnected() method returns to make sure that file was completely processed.
This method is blocking.
std::shared_ptr< DXEndpoint > dxfcpp::DXEndpoint::connect | ( | const std::string & | address | ) |
Connects to the specified remote address.
Previously established connections are closed if the new address is different from the old one. This method does nothing if address does not change or if this endpoint is CLOSED. The endpoint state immediately becomes CONNECTING otherwise.
The address string is provided with the market data vendor agreement. Use "demo.dxfeed.com:7300" for a demo quote feed.
The simplest address strings have the following format:
host:port
to establish a TCP/IP connection.:port
to listen for a TCP/IP connection with a plain socket connector (good for up to a few hundred of connections).For premium services access credentials must be configured before invocation of connect
method using user and password methods.
This method does not wait until connection actually gets established. The actual connection establishment happens asynchronously after the invocation of this method. However, this method waits until notification about state transition from State::NOT_CONNECTED to State::CONNECTING gets processed by all listeners.
address | The data source address. |
|
inlinestatic |
Creates an endpoint with FEED role.
The result of this method is the same as create(DXEndpoint::Role::FEED)
. This is a shortcut to newBuilder()->build()
|
inlinestatic |
Creates an endpoint with a specified role.
This is a shortcut to newBuilder()->withRole(role)->build()
role | the role. |
void dxfcpp::DXEndpoint::disconnect | ( | ) |
Terminates all remote network connections.
This method does nothing if this endpoint is CLOSED. The endpoint state immediately becomes NOT_CONNECTED otherwise.
This method does not release all resources that are associated with this endpoint. Use close() method to release all resources.
void dxfcpp::DXEndpoint::disconnectAndClear | ( | ) |
Terminates all remote network connections and clears stored data.
This method does nothing if this endpoint is CLOSED. The endpoint state immediately becomes NOT_CONNECTED otherwise.
This method does not release all resources that are associated with this endpoint. Use close() method to release all resources.
std::shared_ptr< DXFeed > dxfcpp::DXEndpoint::getFeed | ( | ) |
|
inlinestatic |
Returns a default application-wide singleton instance of DXEndpoint with a FEED role.
Most applications use only a single data-source and should rely on this method to get one. This method creates an endpoint on the first use with a default configuration as explained in default properties section of DXEndpoint class documentation. You can provide configuration via system properties as explained there.
This is a shortcut to getInstance(DXEndpoint::Role::FEED).
|
inlinestatic |
Returns a default application-wide singleton instance of DXEndpoint for a specific role.
Most applications use only a single data-source and should rely on this method to get one. This method creates an endpoint with the corresponding role on the first use with a default configuration as explained in default properties section of DXEndpoint class documentation. You can provide configuration via system properties as explained there.
The configuration does not have to include an address. You can use connect(address) and DXEndpoint::disconnect() methods on the instance that is returned by this method to programmatically establish and tear-down connection to a user-provided address.
If you need a fully programmatic configuration and/or multiple endpoints of the same role in your application, then create a custom instance of DXEndpoint with DXEndpoint::newBuilder() method, configure it, and use Builder::build() method.
role | The role of DXEndpoint instance |
|
inline |
std::shared_ptr< DXPublisher > dxfcpp::DXEndpoint::getPublisher | ( | ) |
|
inline |
DXEndpoint::State dxfcpp::DXEndpoint::getState | ( | ) | const |
|
inline |
true
if the endpoint is closed
|
inlinestaticnoexcept |
Creates new Builder instance.
Use Builder::build() to build an instance of DXEndpoint when all configuration properties were set.
|
inlinenoexcept |
Returns the onStateChange handler that can be used to add or remove listeners.
void(State, State)
signature std::shared_ptr< DXEndpoint > dxfcpp::DXEndpoint::password | ( | const std::string & | password | ) |
Changes password for this endpoint.
This method shall be called before connect together with user to configure service access credentials.
password | The password. |
void dxfcpp::DXEndpoint::reconnect | ( | ) |
Terminates all established network connections and initiates connecting again with the same address.
The effect of the method is alike to invoking disconnect() and connect(const std::string&) with the current address, but internal resources used for connections may be reused by implementation. TCP connections with multiple target addresses will try switch to an alternative address, configured reconnect timeouts will apply.
Note: The method will not connect endpoint that was not initially connected with connect(const std::string&) method or was disconnected with disconnect() method.
The method initiates a short-path way for reconnecting, so whether observers will have a chance to see an intermediate state State::NOT_CONNECTED depends on the implementation.
|
inlinenoexcept |
Removes listener that is notified about changes in state property.
It removes the listener that was previously installed with DXEndpoint::addStateChangeListener method.
listenerId | The listener id to remove |
|
overridevirtualnoexcept |
Returns a string representation of the current object.
Reimplemented from dxfcpp::SharedEntity.
std::shared_ptr< DXEndpoint > dxfcpp::DXEndpoint::user | ( | const std::string & | user | ) |
Changes user name for this endpoint.
This method shall be called before connect together with password to configure service access credentials.
user | The user name. |
|
static |
"dxendpoint.eventTime"
Set this property to true
to enable event time support. By default, the endpoint does not support event time.
The event time is available only when the corresponding DXEndpoint is created with this property and the data source has embedded event times. This is typically true only for data events that are read from historical tape files and from OnDemandService. Events that are coming from a network connections do not have an embedded event time information and event time is not available for them anyway.
Use this property if you need to work with historical data coming from files or from OnDemandService or writing data with times to file via DXPublisher using "tape:..." address.
|
static |
"dxendpoint.storeEverything"
Set this property to to store all lasting and indexed events even when there is no subscription on them. By default, the endpoint stores only events from subscriptions. It works in the same way both for DXFeed and DXPublisher.
Use this property with extreme care, since API does not currently provide any means to remove those events from the storage and there might be an effective memory leak if the spaces of symbols on which events are published grows without bound.
|
static |
"dxfeed.address"
Defines default connection address for an endpoint with role FEED or ON_DEMAND_FEED. Connection is established to this address by role FEED as soon as endpoint is created, while role ON_DEMAND_FEED waits until OnDemandService::replay(Date, double) is invoked before connecting.
By default, without this property, connection is not established until connect(address) is invoked.
Credentials for access to premium services may be configured with DXEndpoint::DXFEED_USER_PROPERTY and DXEndpoint::DXFEED_PASSWORD_PROPERTY.
|
static |
"dxfeed.aggregationPeriod"
Defines data aggregation period an endpoint with role FEED that limits the rate of data notifications. For example, setting the value of this property to "0.1s" limits notification to once every 100ms (at most 10 per second).
|
static |
"dxfeed.password"
Defines default password for an endpoint with role FEED or ON_DEMAND_FEED.
|
static |
"dxfeed.properties"
Defines path to a file with properties for an endpoint with role FEED or ON_DEMAND_FEED. By default, properties a loaded from a path resource named "dxfeed.properties".
|
static |
"dxfeed.threadPoolSize"
Defines thread pool size for an endpoint with role FEED. By default, the thread pool size is equal to the number of available processors.
|
static |
"dxfeed.user"
Defines default user name for an endpoint with role FEED or ON_DEMAND_FEED.
|
static |
"dxfeed.wildcard.enable"
Set this property to true
to turns on wildcard support. By default, the endpoint does not support wildcards. This property is needed for WildcardSymbol support and for the use of "tape:..." address in DXPublisher.
|
static |
"dxpublisher.address"
Defines default connection address for an endpoint with role PUBLISHER. Connection is established to this address as soon as endpoint is created. By default, connection is not established until DXEndpoint::connect(const std::string&) is invoked.
|
static |
"dxpublisher.properties"
Defines path to a file with properties for an endpoint with role PUBLISHER. By default, properties a loaded from a classpath resource named "dxpublisher.properties".
|
static |
"dxpublisher.threadPoolSize"
Defines thread pool size for an endpoint with role PUBLISHER. By default, the thread pool size is equal to the number of available processors.
|
static |
"dxscheme.enabled."
Defines whether a specified field from the scheme should be enabled instead of it's default behaviour. Use it according to following format:
dxscheme.enabled.<field_property_name>=<event_name_mask_glob>
For example, dxscheme.enabled.TimeNanoPart=Trade
enables NanoTimePart
internal field only in Trade events.
There is a shortcut for turning on nano-time support using DXEndpoint::DXSCHEME_NANO_TIME_PROPERTY.
|
static |
"dxscheme.nanoTime"
Set this property to true
to turn on nanoseconds precision business time. By default, this feature is turned off. Business time in most events is available with millisecond precision by default, while Quote events business time is available with seconds precision.
This method provides a higher-level control than turning on individual properties that are responsible for nano-time via DXEndpoint::DXSCHEME_ENABLED_PROPERTY_PREFIX. The later can be used to override of fine-time nano-time support for individual fields. Setting this property to true
is essentially equivalent to setting:
|
static |
"name"
Defines property for endpoint name that is used to distinguish multiple endpoints in the same process in logs and in other diagnostic means. Use Builder::withProperty(const std::string&, const std::string&) method. This property is also changed by Builder::withName(const std::string&) method.