Quantum Resource Manager and Compiler Infrastructure (QRM&CI) 0.1.0
mqss::qrmci::CommunicationHandler Class Reference

CommunicationHandler abstracts the messaging operations that move pipeline messages between QRM&CI stages. More...

Public Member Functions

 CommunicationHandler (const RabbitMqConnectionConfig &config)
 Construct a CommunicationHandler with the given configuration.
 CommunicationHandler (const CommunicationHandler &)=delete
 Explicitly non-copyable and non-movable: a moved-from handler would leave its messenger's transport connection in an unusable state with no way to tell from the type alone, so that state is refused at compile time rather than left implicit.
CommunicationHandler & operator= (const CommunicationHandler &)=delete
 CommunicationHandler (CommunicationHandler &&)=delete
CommunicationHandler & operator= (CommunicationHandler &&)=delete
template<class Message>
std::expected< void, Error > send (const Message &message, const std::string &queueName)
 Send a message to the specified queue.
template<class Message>
std::expected< std::optional< Message >, Error > receive (const std::string &queueName, std::chrono::milliseconds timeout, const std::atomic< bool > &terminationFlag)
 Retrieve the next message of the given type from the specified queue.
template<class Message>
std::expected< std::optional< Message >, Error > receive (const std::string &queueName, std::chrono::milliseconds timeout=DefaultReceiveTimeout)
 Retrieve the next message of the given type, with no termination flag to interrupt the wait.

Detailed Description

CommunicationHandler abstracts the messaging operations that move pipeline messages between QRM&CI stages.

One send and one receive cover every message type: the type is a template parameter of the operation, not part of its name, so a new pipeline message costs a messageLabel overload rather than a new pair of methods. Neither operation throws; both report failure through std::expected, as the orchestration layer in Runners.h does, so a daemon loop can log a broker failure and keep its in-flight work instead of unwinding.

Definition at line 87 of file CommunicationHandler.h.

Constructor & Destructor Documentation

◆ CommunicationHandler() [1/2]

mqss::qrmci::CommunicationHandler::CommunicationHandler ( const RabbitMqConnectionConfig & config)
explicit

Construct a CommunicationHandler with the given configuration.

Parameters
configThe RabbitMQ configuration to use for the connection.

◆ CommunicationHandler() [2/2]

mqss::qrmci::CommunicationHandler::CommunicationHandler ( const CommunicationHandler & )
delete

Explicitly non-copyable and non-movable: a moved-from handler would leave its messenger's transport connection in an unusable state with no way to tell from the type alone, so that state is refused at compile time rather than left implicit.

Construct one in place instead.

Member Function Documentation

◆ receive() [1/2]

template<class Message>
std::expected< std::optional< Message >, Error > mqss::qrmci::CommunicationHandler::receive ( const std::string & queueName,
std::chrono::milliseconds timeout,
const std::atomic< bool > & terminationFlag )
inlinenodiscard

Retrieve the next message of the given type from the specified queue.

Template Parameters
MessageThe message type to receive (e.g. mqss::QuantumTask, mqss::QuantumResult, mqss::Backend).
Parameters
queueNameThe name of the queue to consume from.
timeoutThe maximum time to wait for a message. 0ms polls once and returns immediately if nothing is available; pass WaitForever to poll until a message arrives or terminationFlag is set.
terminationFlagConsulted before every receive attempt: once set, this returns an empty optional without touching the transport, whatever the timeout.
Returns
The next message, an empty optional if the timeout elapsed or termination was requested, or a MessagingFailed error describing the failure.
Note
The message is received under manual ack and explicitly acknowledged once successfully decoded.

Definition at line 143 of file CommunicationHandler.h.

◆ receive() [2/2]

template<class Message>
std::expected< std::optional< Message >, Error > mqss::qrmci::CommunicationHandler::receive ( const std::string & queueName,
std::chrono::milliseconds timeout = DefaultReceiveTimeout )
inlinenodiscard

Retrieve the next message of the given type, with no termination flag to interrupt the wait.

A separate overload rather than a defaulted parameter, so that a caller with no flag to offer has to say so rather than silently binding one that can never be set. Tests and short-lived tools are the intended users; a daemon should pass its own flag.

Template Parameters
MessageThe message type to receive.
Parameters
queueNameThe name of the queue to consume from.
timeoutThe maximum time to wait for a message. 0ms polls once and returns immediately if nothing is available; WaitForever is uninterruptible on this overload since there is no flag to consult, so pass one from any process that has to shut down.
Returns
The next message, an empty optional if the timeout elapsed, or a MessagingFailed error describing the failure.

Definition at line 198 of file CommunicationHandler.h.

◆ send()

template<class Message>
std::expected< void, Error > mqss::qrmci::CommunicationHandler::send ( const Message & message,
const std::string & queueName )
inlinenodiscard

Send a message to the specified queue.

Template Parameters
MessageThe message type to send (e.g. mqss::QuantumTask, mqss::QuantumResult, mqss::Backend).
Parameters
messageThe message to be sent.
queueNameThe name of the queue that receives the message.
Returns
Nothing on success, or a MessagingFailed error describing the failure. The message is not queued for retry, so a caller that must not lose it has to resend it itself.

Definition at line 112 of file CommunicationHandler.h.


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