dxFeed Graal CXX API v4.0.0
Loading...
Searching...
No Matches
IndexedTxModel< E > Struct Template Referencefinal

An incremental model for indexed events. More...

#include <IndexedTxModel.hpp>

+ Inheritance diagram for IndexedTxModel< E >:

Classes

struct  Builder
 A builder class for creating an instance of IndexedTxModel. More...
 

Public Member Functions

 ~IndexedTxModel () noexcept override
 Calls close method and destructs this model.
 
bool isBatchProcessing () const
 Returns whether batch processing is enabled.
 
bool isSnapshotProcessing () const
 Returns whether snapshot processing is enabled.
 
void attach (const std::shared_ptr< DXFeed > &feed) const
 Attaches this model to the specified feed.
 
void detach (const std::shared_ptr< DXFeed > &feed) const
 Detaches this model from the specified feed.
 
void close () const
 Closes this model and makes it permanently detached.
 
std::unordered_set< EventSourceWrappergetSources () const
 Returns the current set of sources.
 
template<typename EventSourceIt >
void setSources (EventSourceIt begin, EventSourceIt end) const
 Sets the sources from which to subscribe for indexed events.
 
template<ConvertibleToEventSourceWrapperCollection EventSourceCollection>
void setSources (EventSourceCollection &&sources) const
 Sets the sources from which to subscribe for indexed events.
 
void setSources (std::initializer_list< EventSourceWrapper > sources) const
 Sets the sources from which to subscribe for indexed events.
 
std::string toString () const override
 Returns a string representation of the current object.
 
- Public Member Functions inherited from 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 Entity
virtual ~Entity () noexcept=default
 The default virtual d-tor.
 

Static Public Member Functions

static std::shared_ptr< BuildernewBuilder ()
 Factory method to create a new builder for this model.
 
- Static Public Member Functions inherited from RequireMakeShared< IndexedTxModel< E > >
static auto createShared (Args &&...args)
 Creates smart pointer to object.
 

Additional Inherited Members

- Public Types inherited from SharedEntity
using Ptr = std::shared_ptr<SharedEntity>
 The alias to a type of shared pointer to the SharedEntity object.
 

Detailed Description

template<Derived< IndexedEvent > E>
struct IndexedTxModel< E >

An incremental model for indexed events.

This model manages all snapshot and transaction logic, subscription handling, and listener notifications.

This model is designed to handle incremental transactions. Users of this model only see the list of events in a consistent state. This model delays incoming events that are part of an incomplete snapshot or ongoing transaction until the snapshot is complete or the transaction has ended. This model notifies the user of received transactions through an installed listener.

Configuration

This model must be configured using the builder, as most configuration settings cannot be changed once the model is built. This model requires configuration with a symbol and a IndexedTxModel::Builder::withSources() sources for subscription, and it must be attached to a DXFeed instance to begin operation. For ease of use, some of these configurations can be changed after the model is built, see setSources and attach and their overloads.

This model only supports single symbol subscriptions; multiple symbols cannot be configured.

Resource management and closed models

Attached model is a potential memory leak. If the pointer to attached model is lost, then there is no way to detach this model from the feed.

The convenient way to detach model from the feed is to call its close method (it is automatically called when the destructor is called, i.e. RAII). Closed model becomes permanently detached from all feeds, removes all its listeners.

Threads and locks

This class is thread-safe and can be used concurrently from multiple threads without external synchronization.

Sample:

auto feed = DXEndpoint::getInstance(DXEndpoint::Role::FEED)->connect("demo.dxfeed.com:7300")->getFeed();
auto listener = IndexedTxModelListener<Order>::create([](const auto &, const auto &events, bool isSnapshot) {
if (isSnapshot) {
std::cout << "Snapshot:" << std::endl;
} else {
std::cout << "Update:" << std::endl;
}
for (const auto &e : events) {
std::cout << "[" << e->getEventFlagsMask().toString() << "]:" << e << std::endl;
}
std::cout << std::endl;
});
->withFeed(feed)
->withBatchProcessing(true)
->withSnapshotProcessing(true)
->withListener(listener)
->withSymbol("IBM")
->build();
std::this_thread::sleep_for(10s);
static const OrderSource DEX
Direct-Edge EDGX Exchange.
Definition OrderSource.hpp:202
static const OrderSource NTV
NASDAQ Total View.
Definition OrderSource.hpp:138
@ FEED
FEED endpoint connects to the remote data feed provider and is optimized for real-time or delayed dat...
std::shared_ptr< DXFeed > getFeed()
Definition DXEndpoint.cpp:229
std::shared_ptr< DXEndpoint > connect(const std::string &address)
Connects to the specified remote address.
Definition DXEndpoint.cpp:170
static std::shared_ptr< DXEndpoint > getInstance()
Returns a default application-wide singleton instance of DXEndpoint with a FEED role.
Definition DXEndpoint.cpp:426
static std::shared_ptr< Builder > newBuilder()
Factory method to create a new builder for this model.
Definition IndexedTxModel.hpp:401
static std::shared_ptr< IndexedTxModelListener< E > > create(std::function< void(const IndexedEventSource &, const std::vector< std::shared_ptr< E > > &, bool)> onEventsReceived)
Creates a listener for receiving indexed events (with instantiation by event type E and verification)
Definition TxModelListener.hpp:100
Template Parameters
EThe type of event (derived from IndexedEvent)

Member Function Documentation

◆ attach()

template<Derived< IndexedEvent > E>
void IndexedTxModel< E >::attach ( const std::shared_ptr< DXFeed > & feed) const
inline

Attaches this model to the specified feed.

Technically, this model can be attached to multiple feeds at once, but this is rarely needed and not recommended.

Parameters
feedThe feed to attach to.

◆ close()

template<Derived< IndexedEvent > E>
void IndexedTxModel< E >::close ( ) const
inline

Closes this model and makes it permanently detached.

This method clears installed listener.

Referenced by IndexedTxModel< E >::~IndexedTxModel().

◆ detach()

template<Derived< IndexedEvent > E>
void IndexedTxModel< E >::detach ( const std::shared_ptr< DXFeed > & feed) const
inline

Detaches this model from the specified feed.

Parameters
feedThe feed to detach from.

◆ getSources()

template<Derived< IndexedEvent > E>
std::unordered_set< EventSourceWrapper > IndexedTxModel< E >::getSources ( ) const
inline

Returns the current set of sources.

If no sources have been set, an empty set is returned, indicating that all possible sources have been subscribed to.

Returns
The set of current sources.

◆ isBatchProcessing()

template<Derived< IndexedEvent > E>
bool IndexedTxModel< E >::isBatchProcessing ( ) const
inline

Returns whether batch processing is enabled.

See withBatchProcessing.

Returns
true if batch processing is enabled; false otherwise.

◆ isSnapshotProcessing()

template<Derived< IndexedEvent > E>
bool IndexedTxModel< E >::isSnapshotProcessing ( ) const
inline

Returns whether snapshot processing is enabled.

See withSnapshotProcessing.

Returns
true if snapshot processing is enabled; false otherwise.

◆ newBuilder()

template<Derived< IndexedEvent > E>
static std::shared_ptr< Builder > IndexedTxModel< E >::newBuilder ( )
inlinestatic

Factory method to create a new builder for this model.

auto builder = model->newBuilder();
Returns
A new builder instance.

◆ setSources() [1/3]

template<Derived< IndexedEvent > E>
template<ConvertibleToEventSourceWrapperCollection EventSourceCollection>
void IndexedTxModel< E >::setSources ( EventSourceCollection && sources) const
inline

Sets the sources from which to subscribe for indexed events.

If an empty list is provided, subscriptions will default to all available sources. If these sources have already been set, nothing happens.

model->setSources(std::vector{OrderSource::NTV, OrderSource::DEX});
// or
model->setSources(std::unordered_set{OrderSource::NTV, OrderSource::DEX});
Template Parameters
EventSourceCollectionA type of the collection of sources (std::vector<EventSourceWrapper>, std::set<OrderSource>, etc.)
Parameters
sourcesThe specified sources.

◆ setSources() [2/3]

template<Derived< IndexedEvent > E>
template<typename EventSourceIt >
void IndexedTxModel< E >::setSources ( EventSourceIt begin,
EventSourceIt end ) const
inline

Sets the sources from which to subscribe for indexed events.

If an empty list is provided, subscriptions will default to all available sources. If these sources have already been set, nothing happens.

std::vector<EventSourceWrapper> sources{OrderSource::NTV, OrderSource::DEX};
model->setSources(sources.begin(), sources.end());
Template Parameters
EventSourceItThe source collection iterator type.
Parameters
beginThe beginning of the collection of sources.
endThe end of the collection of sources.

◆ setSources() [3/3]

template<Derived< IndexedEvent > E>
void IndexedTxModel< E >::setSources ( std::initializer_list< EventSourceWrapper > sources) const
inline

Sets the sources from which to subscribe for indexed events.

If an empty list is provided, subscriptions will default to all available sources. If these sources have already been set, nothing happens.

model->setSources({OrderSource::NTV, OrderSource::DEX});
model->setSources({OrderSource::NTV});
Parameters
sourcesThe specified sources.

◆ toString()

template<Derived< IndexedEvent > E>
std::string IndexedTxModel< E >::toString ( ) const
inlineoverridevirtual

Returns a string representation of the current object.

Returns
a string representation

Reimplemented from SharedEntity.