MoldUDP64 session manager.
More...
MoldUDP64 session manager.
Manages a complete MoldUDP64 session lifecycle including:
- Dual redundant multicast feed reception (A/B feeds)
- Automatic failover between feeds
- Message sequencing and gap detection
- Automatic gap recovery via replay channel
- Heartbeat monitoring and link status management
- Message caching for local replay
State machine:
- InSync: Receiving messages in sequence, no gaps
- Recovering: Gap detected, requesting recovery
- OutOfSync: Recovery failed or massive gap, manual intervention needed
The session is abstract and requires derived classes to implement:
- Message processing (on_message)
- Recovery logic (play_snapshot, perform_recovery)
- Event handling (on_event)
- Note
- Thread-safety: Must be used with a single IOContext thread
-
Derived classes must implement pure virtual methods
- See also
- Settings
-
State
-
Event
#include <nasdaq/moldudp64/Session.h>
|
| enum class | State { InSync
, Recovering
, OutOfSync
} |
| | Session synchronization state. More...
|
| enum class | Source { Realtime
, Snapshot
, Cache
} |
| | Message source indicator. More...
|
| enum class | Event {
LinkUp
, LinkDown
, EndOfSession
, RecoveryStarted
,
RecoveryStopped
, RecoveryFailed
, SecdefsAvailable
} |
| | Session lifecycle and recovery events. More...
|
| using | error_code = std::error_code |
| | Error code type alias.
|
| using | Seqnum = decltype(std::declval<UDPPacket>().get_sn()) |
| | Sequence number type.
|
|
| | Session (std::shared_ptr< b2bits::IOContext > ctx, Settings s, const char *log_pfx=nullptr) |
| | Construct a MoldUDP64 session.
|
| | ~Session () |
| | Destructor.
|
| bool | is_started () const |
| | Check if session is started.
|
| State | get_state () const |
| | Get current session state.
|
| const std::string & | get_session () const |
| | Get active MoldUDP64 session name.
|
| std::int64_t | get_msg_recv_time () const |
| | Get timestamp of last received message.
|
| auto | get_packet_recv_time () |
| | Get timestamp of last received packet.
|
| void | start () |
| | Start the session.
|
| void | run () |
| | Run the session (blocking).
|
| void | stop () |
| | Stop the session (synchronous).
|
| template<typename Handler> |
| void | async_stop (Handler &&h) |
| | Stop the session asynchronously.
|
| void | pause_udp () |
| | Pause UDP multicast reception.
|
| void | resume_udp () |
| | Resume UDP multicast reception.
|
| void | operator() (Sequencer &, std::uint64_t sn, std::int64_t timestamp, const MessageBlock *h) |
| | Handle in-sequence message from sequencer.
|
| void | operator() (Sequencer &, Sequencer::ResetEvent) |
| | Handle sequencer reset event.
|
| void | operator() (Sequencer &, Sequencer::ReplayEvent) |
| | Handle sequencer replay event.
|
◆ error_code
◆ Seqnum
◆ Event
Session lifecycle and recovery events.
Events notified to derived classes for session state changes.
| Enumerator |
|---|
| LinkUp | Multicast feed is active (receiving heartbeats).
|
| LinkDown | Multicast feed timeout (no heartbeats).
|
| EndOfSession | End-of-session marker received.
|
| RecoveryStarted | Gap recovery initiated.
|
| RecoveryStopped | Gap recovery completed successfully.
|
| RecoveryFailed | Gap recovery failed, entering OutOfSync state.
|
| SecdefsAvailable | Security definitions are available.
|
◆ Source
Message source indicator.
Identifies where a message originated from during processing.
| Enumerator |
|---|
| Realtime | Message from live multicast feed (Feed A or B).
|
| Snapshot | Message from snapshot recovery.
|
| Cache | Message from local message cache.
|
◆ State
Session synchronization state.
Indicates the current state of message sequencing and recovery.
| Enumerator |
|---|
| InSync | Receiving messages in sequence, no gaps detected.
|
| Recovering | Gap detected, recovery in progress.
|
| OutOfSync | Recovery failed or gap too large, manual intervention needed.
|
◆ Session()
| b2bits::nasdaq::moldudp64::Session::Session |
( |
std::shared_ptr< b2bits::IOContext > | ctx, |
|
|
Settings | s, |
|
|
const char * | log_pfx = nullptr ) |
Construct a MoldUDP64 session.
Initializes the session with IO context, settings, and optional log prefix. The session is not started until start() is called.
- Parameters
-
| ctx | IO context for async operations |
| s | Session settings (feeds, timeouts, etc.) |
| log_pfx | Optional log prefix for identifying this session (default: nullptr) |
◆ ~Session()
| b2bits::nasdaq::moldudp64::Session::~Session |
( |
| ) |
|
Destructor.
Ensures proper cleanup and session termination. If the session is still running, it will be stopped.
◆ async_stop()
template<typename Handler>
| void b2bits::nasdaq::moldudp64::Session::async_stop |
( |
Handler && | h | ) |
|
|
inline |
Stop the session asynchronously.
Initiates asynchronous session termination. The provided handler is called when termination is complete.
- Template Parameters
-
| Handler | Handler type (function, lambda, etc.) |
- Parameters
-
| h | Handler to call on termination completion |
◆ get_msg_recv_time()
| std::int64_t b2bits::nasdaq::moldudp64::Session::get_msg_recv_time |
( |
| ) |
const |
|
inline |
Get timestamp of last received message.
- Returns
- Message receive timestamp (nanoseconds)
References msg_recv_time_.
◆ get_packet_recv_time()
| auto b2bits::nasdaq::moldudp64::Session::get_packet_recv_time |
( |
| ) |
|
|
inline |
Get timestamp of last received packet.
- Returns
- Packet receive time point
◆ get_sentry()
| std::shared_ptr< b2bits::AsyncSentry > b2bits::nasdaq::moldudp64::Session::get_sentry |
( |
| ) |
|
|
inlineprotected |
Get the async operation sentry.
- Returns
- Shared pointer to the sentry guard
◆ get_session()
| const std::string & b2bits::nasdaq::moldudp64::Session::get_session |
( |
| ) |
const |
|
inline |
Get active MoldUDP64 session name.
- Returns
- Session identifier string (10 characters)
References active_session_.
◆ get_state()
| State b2bits::nasdaq::moldudp64::Session::get_state |
( |
| ) |
const |
|
inline |
Get current session state.
- Returns
- Current State (InSync, Recovering, or OutOfSync)
◆ is_started()
| bool b2bits::nasdaq::moldudp64::Session::is_started |
( |
| ) |
const |
|
inline |
Check if session is started.
- Returns
- true if session is active
◆ on_eop()
| virtual void b2bits::nasdaq::moldudp64::Session::on_eop |
( |
| ) |
|
|
protectedpure virtual |
Called at end of packet processing.
Invoked after all messages in a packet have been processed. Useful for batching operations or flushing buffers.
◆ on_event()
| virtual void b2bits::nasdaq::moldudp64::Session::on_event |
( |
Event | e | ) |
|
|
protectedpure virtual |
Handle session lifecycle events.
Called when session state changes occur (link up/down, recovery started/stopped, end-of-session, etc.).
- Parameters
-
◆ on_message()
Process a received message.
Called for each in-sequence message that needs processing. The message payload follows the MessageBlock header.
- Parameters
-
| source | Where the message came from (Realtime/Snapshot/Cache) |
| sn | Message sequence number |
| msg | Pointer to MessageBlock header |
◆ on_recovery_finished()
| void b2bits::nasdaq::moldudp64::Session::on_recovery_finished |
( |
Seqnum | next_sn, |
|
|
const error_code & | ec ) |
|
protected |
Notify recovery completion.
Derived classes should call this when recovery is complete, providing the next expected sequence number.
- Parameters
-
| next_sn | Next expected sequence number after recovery |
| ec | Error code (success or failure reason) |
◆ on_start_termination()
| virtual void b2bits::nasdaq::moldudp64::Session::on_start_termination |
( |
| ) |
|
|
protectedpure virtual |
Called when session termination begins.
Derived classes should perform cleanup and prepare for shutdown. This is called before network connections are closed.
◆ on_terminated()
| virtual void b2bits::nasdaq::moldudp64::Session::on_terminated |
( |
| ) |
|
|
protectedvirtual |
Called when session is fully terminated.
Default implementation does nothing. Override to perform final cleanup after session shutdown.
◆ operator()() [1/3]
| void b2bits::nasdaq::moldudp64::Session::operator() |
( |
Sequencer & | , |
|
|
Sequencer::ReplayEvent | ) |
Handle sequencer replay event.
Called when the sequencer is replaying buffered messages.
- Parameters
-
◆ operator()() [2/3]
| void b2bits::nasdaq::moldudp64::Session::operator() |
( |
Sequencer & | , |
|
|
Sequencer::ResetEvent | ) |
Handle sequencer reset event.
Called when the sequencer resets (e.g., new session).
- Parameters
-
◆ operator()() [3/3]
| void b2bits::nasdaq::moldudp64::Session::operator() |
( |
Sequencer & | , |
|
|
std::uint64_t | sn, |
|
|
std::int64_t | timestamp, |
|
|
const MessageBlock * | h ) |
Handle in-sequence message from sequencer.
Called by the sequencer when a message is ready for processing.
- Parameters
-
| seq | Sequencer instance |
| sn | Sequence number |
| timestamp | Message timestamp |
| h | Message block pointer |
◆ pause_udp()
| void b2bits::nasdaq::moldudp64::Session::pause_udp |
( |
| ) |
|
Pause UDP multicast reception.
Temporarily stops receiving multicast packets. Useful for throttling or temporary suspension.
◆ perform_recovery()
| virtual void b2bits::nasdaq::moldudp64::Session::perform_recovery |
( |
| ) |
|
|
protectedpure virtual |
Perform message recovery.
Derived classes should implement the recovery logic to request and process missing messages from the replay channel.
◆ play_snapshot()
| virtual void b2bits::nasdaq::moldudp64::Session::play_snapshot |
( |
| ) |
|
|
protectedpure virtual |
Play snapshot data during recovery.
Derived classes should retrieve and process snapshot data to rebuild state during gap recovery.
◆ resume_udp()
| void b2bits::nasdaq::moldudp64::Session::resume_udp |
( |
| ) |
|
Resume UDP multicast reception.
Resumes receiving multicast packets after pause_udp().
◆ run()
| void b2bits::nasdaq::moldudp64::Session::run |
( |
| ) |
|
Run the session (blocking).
Blocks until the session is stopped. This runs the IO context event loop for processing network events.
◆ set_msg_recv_time()
| void b2bits::nasdaq::moldudp64::Session::set_msg_recv_time |
( |
std::int64_t | val | ) |
|
|
inlineprotected |
Set the message receive timestamp.
- Parameters
-
| val | Timestamp in nanoseconds |
References msg_recv_time_.
◆ set_session()
| void b2bits::nasdaq::moldudp64::Session::set_session |
( |
const std::string & | s | ) |
|
|
inlineprotected |
◆ start()
| void b2bits::nasdaq::moldudp64::Session::start |
( |
| ) |
|
Start the session.
Begins receiving multicast data and starts the heartbeat timer. The session enters recovery mode initially to establish sync.
◆ stop()
| void b2bits::nasdaq::moldudp64::Session::stop |
( |
| ) |
|
Stop the session (synchronous).
Stops receiving data and terminates the session synchronously. All resources are cleaned up before returning.
◆ active_session_
| std::string b2bits::nasdaq::moldudp64::Session::active_session_ |
|
protected |
◆ ctx_
| std::shared_ptr<b2bits::IOContext> b2bits::nasdaq::moldudp64::Session::ctx_ |
|
protected |
IO context for async operations.
◆ id_
| const std::int32_t b2bits::nasdaq::moldudp64::Session::id_ |
|
protected |
◆ link_is_up_
| bool b2bits::nasdaq::moldudp64::Session::link_is_up_ = true |
|
protected |
◆ log_prefix_
| const std::string b2bits::nasdaq::moldudp64::Session::log_prefix_ |
|
protected |
◆ msg_recv_time_
| std::int64_t b2bits::nasdaq::moldudp64::Session::msg_recv_time_ = 0 |
|
protected |
◆ settings_
| const Settings b2bits::nasdaq::moldudp64::Session::settings_ |
|
protected |
The documentation for this class was generated from the following file: