xrpld
Loading...
Searching...
No Matches
xrpl::InfoSub Class Referenceabstract

Manages a client's subscription to data feeds. More...

#include <InfoSub.h>

Inheritance diagram for xrpl::InfoSub:
Collaboration diagram for xrpl::InfoSub:

Classes

class  Source
 Abstracts the source of subscription data. More...

Public Types

using pointer = std::shared_ptr<InfoSub>
using wptr = std::weak_ptr<InfoSub>
using ref = std::shared_ptr<InfoSub> const&
using Consumer = Resource::Consumer

Public Member Functions

 InfoSub (Source &source)
 InfoSub (Source &source, Consumer consumer)
virtual ~InfoSub ()
ConsumergetConsumer ()
virtual void send (json::Value const &jvObj, bool broadcast)=0
std::uint64_t getSeq () const
void onSendEmpty ()
void insertSubAccountInfo (AccountID const &account, bool rt)
void deleteSubAccountInfo (AccountID const &account, bool rt)
void insertBookSubscription (Book const &book)
 Record that this subscriber is following book.
void deleteBookSubscription (Book const &book)
 Stop tracking book for this subscriber.
bool insertSubAccountHistory (AccountID const &account)
void deleteSubAccountHistory (AccountID const &account)
void clearRequest ()
void setRequest (std::shared_ptr< InfoSubRequest > const &req)
std::shared_ptr< InfoSubRequest > const & getRequest ()
void setApiVersion (unsigned int apiVersion)
unsigned int getApiVersion () const noexcept

Public Attributes

friend Object

Protected Attributes

std::mutex lock_

Static Private Member Functions

static int assignId ()
static auto & getCounter () noexcept

Private Attributes

Consumer consumer_
Sourcesource_
hash_set< AccountIDrealTimeSubscriptions_
hash_set< AccountIDnormalSubscriptions_
std::shared_ptr< InfoSubRequestrequest_
std::uint64_t seq_
hash_set< AccountIDaccountHistorySubscriptions_
hash_set< BookbookSubscriptions_
unsigned int apiVersion_ = 0

Detailed Description

Manages a client's subscription to data feeds.

An InfoSub holds a non-owning reference to its Source (typically the process-wide NetworkOPsImp). The destructor reaches back into the Source to remove this subscriber from every server-side subscription map.

Note
Lifetime contract: every InfoSub instance MUST be destroyed before the backing Source. NetworkOPsImp shutdown drops all subscriber strong refs before its own teardown to satisfy this.
Thread-safety: per-instance state is guarded by lock_. The destructor reads tracking sets without taking lock_ because the strong-pointer ref-count is zero at destruction time, so no other thread can be calling the public mutators.

Definition at line 44 of file InfoSub.h.

Member Typedef Documentation

◆ pointer

Definition at line 47 of file InfoSub.h.

◆ wptr

Definition at line 51 of file InfoSub.h.

◆ ref

Definition at line 53 of file InfoSub.h.

◆ Consumer

Definition at line 55 of file InfoSub.h.

Constructor & Destructor Documentation

◆ InfoSub() [1/2]

xrpl::InfoSub::InfoSub ( Source & source)

Definition at line 56 of file InfoSub.cpp.

◆ InfoSub() [2/2]

xrpl::InfoSub::InfoSub ( Source & source,
Consumer consumer )

Definition at line 60 of file InfoSub.cpp.

◆ ~InfoSub()

xrpl::InfoSub::~InfoSub ( )
virtual

Definition at line 65 of file InfoSub.cpp.

Member Function Documentation

◆ getConsumer()

Resource::Consumer & xrpl::InfoSub::getConsumer ( )

Definition at line 108 of file InfoSub.cpp.

◆ send()

virtual void xrpl::InfoSub::send ( json::Value const & jvObj,
bool broadcast )
pure virtual

Implemented in xrpl::RPCSubImp, and xrpl::WSInfoSub.

◆ getSeq()

std::uint64_t xrpl::InfoSub::getSeq ( ) const
nodiscard

Definition at line 114 of file InfoSub.cpp.

◆ onSendEmpty()

void xrpl::InfoSub::onSendEmpty ( )

Definition at line 120 of file InfoSub.cpp.

◆ insertSubAccountInfo()

void xrpl::InfoSub::insertSubAccountInfo ( AccountID const & account,
bool rt )

Definition at line 125 of file InfoSub.cpp.

◆ deleteSubAccountInfo()

void xrpl::InfoSub::deleteSubAccountInfo ( AccountID const & account,
bool rt )

Definition at line 140 of file InfoSub.cpp.

◆ insertBookSubscription()

void xrpl::InfoSub::insertBookSubscription ( Book const & book)

Record that this subscriber is following book.

Called by NetworkOPsImp::subBook so that ~InfoSub() can issue a matching unsubBook for every book this subscriber is tracking, keeping per-subscriber state symmetric with the server-side map.

Parameters
bookThe order book this subscriber has just subscribed to.
Note
Idempotent: re-inserting an already-tracked book is a no-op.
Thread-safe: takes InfoSub::lock_.

Definition at line 169 of file InfoSub.cpp.

◆ deleteBookSubscription()

void xrpl::InfoSub::deleteBookSubscription ( Book const & book)

Stop tracking book for this subscriber.

Called by the unsubscribe RPC handler so that the book is not re-unsubscribed by ~InfoSub(). Pairs with insertBookSubscription.

Parameters
bookThe order book to forget.
Note
No-op if book was not previously inserted.
Thread-safe: takes InfoSub::lock_.

Definition at line 176 of file InfoSub.cpp.

◆ insertSubAccountHistory()

bool xrpl::InfoSub::insertSubAccountHistory ( AccountID const & account)

Definition at line 155 of file InfoSub.cpp.

◆ deleteSubAccountHistory()

void xrpl::InfoSub::deleteSubAccountHistory ( AccountID const & account)

Definition at line 162 of file InfoSub.cpp.

◆ clearRequest()

void xrpl::InfoSub::clearRequest ( )

Definition at line 183 of file InfoSub.cpp.

◆ setRequest()

void xrpl::InfoSub::setRequest ( std::shared_ptr< InfoSubRequest > const & req)

Definition at line 189 of file InfoSub.cpp.

◆ getRequest()

std::shared_ptr< InfoSubRequest > const & xrpl::InfoSub::getRequest ( )

Definition at line 195 of file InfoSub.cpp.

◆ setApiVersion()

void xrpl::InfoSub::setApiVersion ( unsigned int apiVersion)

Definition at line 201 of file InfoSub.cpp.

◆ getApiVersion()

unsigned int xrpl::InfoSub::getApiVersion ( ) const
nodiscardnoexcept

Definition at line 207 of file InfoSub.cpp.

◆ assignId()

int xrpl::InfoSub::assignId ( )
staticprivate

Definition at line 305 of file InfoSub.h.

◆ getCounter()

auto & xrpl::CountedObject< InfoSub >::getCounter ( )
staticprivatenoexceptinherited

Definition at line 109 of file CountedObject.h.

Member Data Documentation

◆ lock_

std::mutex xrpl::InfoSub::lock_
protected

Definition at line 291 of file InfoSub.h.

◆ consumer_

Consumer xrpl::InfoSub::consumer_
private

Definition at line 294 of file InfoSub.h.

◆ source_

Source& xrpl::InfoSub::source_
private

Definition at line 295 of file InfoSub.h.

◆ realTimeSubscriptions_

hash_set<AccountID> xrpl::InfoSub::realTimeSubscriptions_
private

Definition at line 296 of file InfoSub.h.

◆ normalSubscriptions_

hash_set<AccountID> xrpl::InfoSub::normalSubscriptions_
private

Definition at line 297 of file InfoSub.h.

◆ request_

std::shared_ptr<InfoSubRequest> xrpl::InfoSub::request_
private

Definition at line 298 of file InfoSub.h.

◆ seq_

std::uint64_t xrpl::InfoSub::seq_
private

Definition at line 299 of file InfoSub.h.

◆ accountHistorySubscriptions_

hash_set<AccountID> xrpl::InfoSub::accountHistorySubscriptions_
private

Definition at line 300 of file InfoSub.h.

◆ bookSubscriptions_

hash_set<Book> xrpl::InfoSub::bookSubscriptions_
private

Definition at line 301 of file InfoSub.h.

◆ apiVersion_

unsigned int xrpl::InfoSub::apiVersion_ = 0
private

Definition at line 302 of file InfoSub.h.

◆ Object

Definition at line 134 of file CountedObject.h.