dxFeed Graal CXX API v9.0.0
Loading...
Searching...
No Matches
InstrumentProfileCollector Class Referencefinal

Collects instrument profile updates and provides the live list of instrument profiles. More...

#include <InstrumentProfileCollector.hpp>

Inheritance diagram for InstrumentProfileCollector:

Public Types

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

Public Member Functions

std::int64_t getLastUpdateTime () const
 Returns last modification time (in milliseconds) of instrument profiles or zero if it is unknown.
std::chrono::milliseconds getLastUpdateTimeAsDuration () const
 Returns last modification time (as std::chrono::milliseconds) of instrument profiles or zero if it is unknown.
void updateInstrumentProfile (std::shared_ptr< InstrumentProfile > ip) const
 Convenience method to update one instrument profile in this collector.
std::shared_ptr< IterableInstrumentProfile > view () const
 Returns a concurrent view of the set of instrument profiles.
template<typename InstrumentProfileUpdateListener>
std::size_t addUpdateListener (InstrumentProfileUpdateListener listener)
 Adds listener that is notified about any updates in the set of instrument profiles.
void removeUpdateListener (std::size_t listenerId)
 Removes listener for instrument profile updates.
Public Member Functions inherited from SharedEntity
template<typename T>
bool is () const noexcept
 Checks that the object is of type T: its dynamic type is T or derived from T.
template<typename T>
std::shared_ptr< T > sharedAs () noexcept
 Returns a pointer to the current object wrapped in a smart pointer to type T or std::shared_ptr<T>{nullptr} if the object is not managed by std::shared_ptr.
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 or std::shared_ptr<T>{nullptr} if the object is not managed by std::shared_ptr.
virtual std::string toString () const
 Returns a string representation of the current object.
Public Member Functions inherited from Entity
virtual ~Entity () noexcept
 The default virtual d-tor.

Static Public Member Functions

static Ptr create ()
 Creates the new InstrumentProfileCollector.

Detailed Description

Collects instrument profile updates and provides the live list of instrument profiles.

This class contains a map that keeps a unique instrument profile per symbol. This class is intended to be used with InstrumentProfileConnection as a repository that keeps profiles of all known instruments. See InstrumentProfileConnection for a usage example.

As set of instrument profiles stored in this collector can be accessed with view method. A snapshot plus a live stream of updates can be accessed with addUpdateListener method.

Removal of instrument profile is represented by an InstrumentProfile instance with a type equal to InstrumentProfileType::REMOVED.getName().

This class is thread-safe.

Member Function Documentation

◆ addUpdateListener()

template<typename InstrumentProfileUpdateListener>
std::size_t InstrumentProfileCollector::addUpdateListener ( InstrumentProfileUpdateListener listener)
inline

Adds listener that is notified about any updates in the set of instrument profiles.

If a set of instrument profiles is not empty, then this listener will be immediately notified.

Warning
The API will be changed in the future. Instead of a vector, a wrapped Java-like iterator will be passed.

Example:

collector->addUpdateListener([](const std::vector<std::shared_ptr<dxfcpp::InstrumentProfile>> &profiles) {
for (const auto &p : profiles) {
if (InstrumentProfileType::REMOVED.getName() == p->getType()) {
std::cout << p->getSymbol() + ": " + p->getType() + "\n";
} else {
std::cout << p->getSymbol() + " (" + p->getDescription() + ")\n";
}
}
});

Example:

collector->addUpdateListener([](auto &&profiles) -> void {
for (const auto &p : profiles) {
if (InstrumentProfileType::REMOVED.getName() == p->getType()) {
std::cout << p->getSymbol() + ": " + p->getType() + "\n";
} else {
std::cout << p->getSymbol() + " (" + p->getDescription() + ")\n";
}
}
});
Template Parameters
InstrumentProfileUpdateListenerThe listener type. Listener can be callable with signature: void(const std::vector<std::shared_ptr<InstrumentProfile>&)
Parameters
listenerThe profile update listener. The listener can be callable with signature: void(const std::vector<std::shared_ptr<InstrumentProfile>&)
Returns
The listener id
Exceptions
InvalidArgumentExceptionif the listener ids of this collector are exhausted (about 2^32 listeners were added on a 64-bit platform)

References addUpdateListener().

Referenced by addUpdateListener().

◆ create()

InstrumentProfileCollector::Ptr InstrumentProfileCollector::create ( )
static

Creates the new InstrumentProfileCollector.

Returns
The new InstrumentProfileCollector

◆ getLastUpdateTime()

std::int64_t InstrumentProfileCollector::getLastUpdateTime ( ) const

Returns last modification time (in milliseconds) of instrument profiles or zero if it is unknown.

Note, that while the time is represented in milliseconds, the actual granularity of time here is a second.

Returns
The last modification time (in milliseconds) of instrument profiles or zero if it is unknown.

Referenced by getLastUpdateTimeAsDuration().

◆ getLastUpdateTimeAsDuration()

std::chrono::milliseconds InstrumentProfileCollector::getLastUpdateTimeAsDuration ( ) const

Returns last modification time (as std::chrono::milliseconds) of instrument profiles or zero if it is unknown.

Note, that while the time is represented in milliseconds, the actual granularity of time here is a second.

Returns
The last modification time (as std::chrono::milliseconds) of instrument profiles or zero if it is unknown.

References getLastUpdateTime().

◆ removeUpdateListener()

void InstrumentProfileCollector::removeUpdateListener ( std::size_t listenerId)

Removes listener for instrument profile updates.

Example:

auto id = collector->addUpdateListener([](auto){});
collector->removeUpdateListener(id);
Parameters
listenerIdThe listener id

◆ updateInstrumentProfile()

void InstrumentProfileCollector::updateInstrumentProfile ( std::shared_ptr< InstrumentProfile > ip) const

Convenience method to update one instrument profile in this collector.

Parameters
ipThe instrument profile.

◆ view()

std::shared_ptr< IterableInstrumentProfile > InstrumentProfileCollector::view ( ) const

Returns a concurrent view of the set of instrument profiles.

Note, that removal of instrument profile is represented by an InstrumentProfile instance with a type equal to InstrumentProfileType::REMOVED.getName(). Normally, this view exposes only non-removed profiles. However, if iteration is concurrent with removal, then a removed instrument profile (with a removed type) can be exposed by this view.

Returns
A concurrent view of the set of instrument profiles.