ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | List of all members
subscription_manager Class Referencefinal

Manages client subscriptions to event notifications. More...

#include <subscription_manager.hpp>

Collaboration diagram for subscription_manager:
Collaboration graph

Public Member Functions

 subscription_manager (const subscription_manager &)=delete
 
subscription_manageroperator= (const subscription_manager &)=delete
 
 subscription_manager (subscription_manager &&)=delete
 
subscription_manageroperator= (subscription_manager &&)=delete
 
void register_session (const session_id &id, notification_callback callback)
 Register a new session with the subscription manager.
 
void unregister_session (const session_id &id)
 Unregister a session from the subscription manager.
 
bool subscribe (const session_id &id, const std::string &event_type)
 Subscribe a session to an event type.
 
bool unsubscribe (const session_id &id, const std::string &event_type)
 Unsubscribe a session from an event type.
 
std::size_t notify (const std::string &event_type, std::chrono::system_clock::time_point timestamp)
 Notify all subscribers of an event.
 
std::size_t subscriber_count (const std::string &event_type) const
 Get the number of subscribers for an event type.
 
std::size_t session_count () const
 Get the total number of registered sessions.
 
std::vector< std::string > get_subscriptions (const session_id &id) const
 Get the event types a session is subscribed to.
 

Detailed Description

Manages client subscriptions to event notifications.

This class tracks which clients are subscribed to which event types and provides the mechanism to broadcast notifications when events occur.

Thread Safety:

Usage:

// Register a session when it connects
mgr.register_session("192.168.1.1:45678",
[&conn](const std::string& event_type, auto ts) {
return push_notification(conn, event_type, ts);
});
// Subscribe to events
mgr.subscribe("192.168.1.1:45678", "ores.risk.currency_changed");
// Notify all subscribers of an event
mgr.notify("ores.risk.currency_changed", std::chrono::system_clock::now());
// Unregister when session ends
mgr.unregister_session("192.168.1.1:45678");
Manages client subscriptions to event notifications.
Definition subscription_manager.hpp:83
void unregister_session(const session_id &id)
Unregister a session from the subscription manager.
Definition subscription_manager.cpp:45
bool subscribe(const session_id &id, const std::string &event_type)
Subscribe a session to an event type.
Definition subscription_manager.cpp:78
void register_session(const session_id &id, notification_callback callback)
Register a new session with the subscription manager.
Definition subscription_manager.cpp:26
std::size_t notify(const std::string &event_type, std::chrono::system_clock::time_point timestamp)
Notify all subscribers of an event.
Definition subscription_manager.cpp:148

Member Function Documentation

◆ register_session()

void register_session ( const session_id &  id,
notification_callback  callback 
)

Register a new session with the subscription manager.

Must be called when a session successfully completes handshake.

Parameters
idThe unique session identifier (typically remote address).
callbackThe callback to invoke for pushing notifications.

◆ unregister_session()

void unregister_session ( const session_id &  id)

Unregister a session from the subscription manager.

Removes all subscriptions for this session. Should be called when a session disconnects.

Parameters
idThe session identifier to unregister.

◆ subscribe()

bool subscribe ( const session_id &  id,
const std::string &  event_type 
)

Subscribe a session to an event type.

Parameters
idThe session identifier.
event_typeThe event type to subscribe to.
Returns
true if subscription succeeded, false if session not found.

◆ unsubscribe()

bool unsubscribe ( const session_id &  id,
const std::string &  event_type 
)

Unsubscribe a session from an event type.

Parameters
idThe session identifier.
event_typeThe event type to unsubscribe from.
Returns
true if unsubscription succeeded, false if session not found or was not subscribed.

◆ notify()

std::size_t notify ( const std::string &  event_type,
std::chrono::system_clock::time_point  timestamp 
)

Notify all subscribers of an event.

Invokes the notification callback for each session subscribed to the given event type. Failed notifications (callback returns false) are logged but do not affect other subscribers.

Parameters
event_typeThe event type that occurred.
timestampThe timestamp of the event.
Returns
The number of successful notifications sent.

◆ subscriber_count()

std::size_t subscriber_count ( const std::string &  event_type) const

Get the number of subscribers for an event type.

Parameters
event_typeThe event type to query.
Returns
The number of sessions subscribed to this event type.

◆ session_count()

std::size_t session_count ( ) const

Get the total number of registered sessions.

Returns
The number of active sessions.

◆ get_subscriptions()

std::vector< std::string > get_subscriptions ( const session_id &  id) const

Get the event types a session is subscribed to.

Parameters
idThe session identifier.
Returns
Vector of event type names, empty if session not found.