Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
etl::impl::SubscriptionSource Class Reference

This class is used to subscribe to a source of ledger data and forward it to the subscription manager. More...

#include <SubscriptionSource.hpp>

Public Types

using OnConnectHook = SourceBase::OnConnectHook
 
using OnDisconnectHook = SourceBase::OnDisconnectHook
 
using OnLedgerClosedHook = SourceBase::OnLedgerClosedHook
 

Public Member Functions

 SubscriptionSource (boost::asio::io_context &ioContext, std::string const &ip, std::string const &wsPort, std::shared_ptr< NetworkValidatedLedgersInterface > validatedLedgers, std::shared_ptr< feed::SubscriptionManagerInterface > subscriptions, OnConnectHook onConnect, OnDisconnectHook onDisconnect, OnLedgerClosedHook onLedgerClosed, std::chrono::steady_clock::duration const wsTimeout=SubscriptionSource::kWS_TIMEOUT, std::chrono::steady_clock::duration const retryDelay=SubscriptionSource::kRETRY_DELAY)
 Construct a new Subscription Source object.
 
void run ()
 Run the source.
 
bool hasLedger (uint32_t sequence) const
 Check if the source has a ledger.
 
bool isConnected () const
 Check if the source is connected.
 
bool isForwarding () const
 Get whether the source is forwarding.
 
void setForwarding (bool isForwarding)
 Set source forwarding.
 
std::chrono::steady_clock::time_point lastMessageTime () const
 Get the last message time (even if the last message had an error)
 
std::string const & validatedRange () const
 Get the last received raw string of the validated ledgers.
 
void stop (boost::asio::yield_context yield)
 Stop the source. The source will complete already scheduled operations but will not schedule new ones.
 

Detailed Description

This class is used to subscribe to a source of ledger data and forward it to the subscription manager.

Note
This class is safe to delete only if io_context is stopped.

Constructor & Destructor Documentation

◆ SubscriptionSource()

etl::impl::SubscriptionSource::SubscriptionSource ( boost::asio::io_context & ioContext,
std::string const & ip,
std::string const & wsPort,
std::shared_ptr< NetworkValidatedLedgersInterface > validatedLedgers,
std::shared_ptr< feed::SubscriptionManagerInterface > subscriptions,
OnConnectHook onConnect,
OnDisconnectHook onDisconnect,
OnLedgerClosedHook onLedgerClosed,
std::chrono::steady_clock::duration const wsTimeout = SubscriptionSource::kWS_TIMEOUT,
std::chrono::steady_clock::duration const retryDelay = SubscriptionSource::kRETRY_DELAY )

Construct a new Subscription Source object.

Template Parameters
NetworkValidatedLedgersTypeThe type of the network validated ledgers object
Parameters
ioContextThe io_context to use
ipThe ip address of the source
wsPortThe port of the source
validatedLedgersThe network validated ledgers object
subscriptionsThe subscription manager object
onConnectThe onConnect hook. Called when the connection is established
onDisconnectThe onDisconnect hook. Called when the connection is lost
onLedgerClosedThe onLedgerClosed hook. Called when the ledger is closed if the source is forwarding
wsTimeoutA timeout for websocket operations. Defaults to 30 seconds
retryDelayThe retry delay. Defaults to 1 second

Member Function Documentation

◆ hasLedger()

bool etl::impl::SubscriptionSource::hasLedger ( uint32_t sequence) const

Check if the source has a ledger.

Parameters
sequenceThe sequence of the ledger
Returns
true if the source has the ledger, false otherwise

◆ isConnected()

bool etl::impl::SubscriptionSource::isConnected ( ) const

Check if the source is connected.

Returns
true if the source is connected, false otherwise

◆ isForwarding()

bool etl::impl::SubscriptionSource::isForwarding ( ) const

Get whether the source is forwarding.

Returns
true if the source is forwarding, false otherwise

◆ lastMessageTime()

std::chrono::steady_clock::time_point etl::impl::SubscriptionSource::lastMessageTime ( ) const

Get the last message time (even if the last message had an error)

Returns
The last message time

◆ setForwarding()

void etl::impl::SubscriptionSource::setForwarding ( bool isForwarding)

Set source forwarding.

Note
If forwarding is true the source will forward messages to the subscription manager. Forwarding is being reset on disconnect.
Parameters
isForwardingThe new forwarding state

◆ validatedRange()

std::string const & etl::impl::SubscriptionSource::validatedRange ( ) const

Get the last received raw string of the validated ledgers.

Returns
The validated ledgers string

The documentation for this class was generated from the following files: