ITCH 5.0 Market Data Handler 1.0.0
NASDAQ ITCH 5.0 Market Data Feed Handler
Loading...
Searching...
No Matches
b2bits::nasdaq::moldudp64::Session Class Referenceabstract

MoldUDP64 session manager. More...

Detailed Description

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>

Inheritance diagram for b2bits::nasdaq::moldudp64::Session:

Public Types

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.

Public Member Functions

 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.

Protected Member Functions

std::shared_ptr< b2bits::AsyncSentry > get_sentry ()
 Get the async operation sentry.
void set_session (const std::string &s)
 Set the active session name.
void set_msg_recv_time (std::int64_t val)
 Set the message receive timestamp.
virtual void on_start_termination ()=0
 Called when session termination begins.
virtual void on_event (Event e)=0
 Handle session lifecycle events.
virtual void on_message (Source source, Seqnum sn, const MessageBlock *)=0
 Process a received message.
virtual void on_eop ()=0
 Called at end of packet processing.
virtual void on_terminated ()
 Called when session is fully terminated.
virtual void play_snapshot ()=0
 Play snapshot data during recovery.
virtual void perform_recovery ()=0
 Perform message recovery.
void on_recovery_finished (Seqnum next_sn, const error_code &ec)
 Notify recovery completion.

Protected Attributes

const std::string log_prefix_
 Prefix for log messages.
const Settings settings_
 Session configuration.
const std::int32_t id_
 Session identifier.
std::string active_session_
 Current MoldUDP64 session name.
bool link_is_up_ = true
 Multicast link status.
std::int64_t msg_recv_time_ = 0
 Timestamp of last received message.
std::shared_ptr< b2bits::IOContext > ctx_
 IO context for async operations.

Member Typedef Documentation

◆ error_code

Error code type alias.

◆ Seqnum

using b2bits::nasdaq::moldudp64::Session::Seqnum = decltype(std::declval<UDPPacket>().get_sn())

Sequence number type.

Member Enumeration Documentation

◆ 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.

Constructor & Destructor Documentation

◆ 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
ctxIO context for async operations
sSession settings (feeds, timeouts, etc.)
log_pfxOptional 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.

Member Function Documentation

◆ 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
HandlerHandler type (function, lambda, etc.)
Parameters
hHandler 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
eEvent type

◆ on_message()

virtual void b2bits::nasdaq::moldudp64::Session::on_message ( Source source,
Seqnum sn,
const MessageBlock *  )
protectedpure virtual

Process a received message.

Called for each in-sequence message that needs processing. The message payload follows the MessageBlock header.

Parameters
sourceWhere the message came from (Realtime/Snapshot/Cache)
snMessage sequence number
msgPointer 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_snNext expected sequence number after recovery
ecError 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
seqSequencer instance
evtReplay event

◆ 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
seqSequencer instance
evtReset event

◆ 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
seqSequencer instance
snSequence number
timestampMessage timestamp
hMessage 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
valTimestamp in nanoseconds

References msg_recv_time_.

◆ set_session()

void b2bits::nasdaq::moldudp64::Session::set_session ( const std::string & s)
inlineprotected

Set the active session name.

Parameters
sSession identifier (10 characters)

References active_session_.

◆ 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.

Member Data Documentation

◆ active_session_

std::string b2bits::nasdaq::moldudp64::Session::active_session_
protected

Current MoldUDP64 session name.

Referenced by get_session(), and set_session().

◆ 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

Session identifier.

◆ link_is_up_

bool b2bits::nasdaq::moldudp64::Session::link_is_up_ = true
protected

Multicast link status.

◆ log_prefix_

const std::string b2bits::nasdaq::moldudp64::Session::log_prefix_
protected

Prefix for log messages.

◆ msg_recv_time_

std::int64_t b2bits::nasdaq::moldudp64::Session::msg_recv_time_ = 0
protected

Timestamp of last received message.

Referenced by get_msg_recv_time(), and set_msg_recv_time().

◆ settings_

const Settings b2bits::nasdaq::moldudp64::Session::settings_
protected

Session configuration.


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