Dripline-Cpp  v2.4.2
Dripline Implementation in C++
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
relayer Class Reference

Asynchronous message sending. More...

#include <relayer.hh>

Inheritance diagram for relayer:
Inheritance graph

Classes

struct  message_and_reply
 
struct  wait_for_send_pkg
 Extended sent-message package that adds thread synchronization objects. More...
 

Public Types

typedef std::shared_ptr< wait_for_send_pkgwait_for_send_pkg_ptr
 

Public Member Functions

 relayer (const scarab::param_node &a_config=scarab::param_node(), const std::string &a_broker_address="", unsigned a_port=0, const std::string &a_auth_file="")
 
virtual ~relayer ()
 
void execute_relayer ()
 Thread execution function: sends any messages that are submitted via the send functions. More...
 
wait_for_send_pkg_ptr send_async (request_ptr_t a_request) const
 
wait_for_send_pkg_ptr send_async (alert_ptr_t a_alert) const
 
reply_ptr_t wait_for_reply (const wait_for_send_pkg_ptr a_receive_reply, int a_timeout_ms=0)
 
reply_ptr_t wait_for_reply (const wait_for_send_pkg_ptr a_receive_reply, bool &a_chan_valid, int a_timeout_ms=0)
 
- Public Member Functions inherited from core
 core (const scarab::param_node &a_config=scarab::param_node(), const std::string &a_broker_address="", unsigned a_port=0, const std::string &a_auth_file="", const bool a_make_connection=true)
 
 core (const bool a_make_connection, const scarab::param_node &a_config=scarab::param_node())
 
 core (const core &a_orig)
 
 core (core &&a_orig)
 
virtual ~core ()
 
coreoperator= (const core &a_orig)
 
coreoperator= (core &&a_orig)
 
virtual sent_msg_pkg_ptr send (request_ptr_t a_request) const
 
virtual sent_msg_pkg_ptr send (reply_ptr_t a_reply) const
 
virtual sent_msg_pkg_ptr send (alert_ptr_t a_alert) const
 
 snake_case_mv_referrable (std::string, address)
 
 snake_case_mv_accessible (unsigned, port)
 
 snake_case_mv_referrable (std::string, username)
 
 snake_case_mv_referrable (std::string, password)
 
 snake_case_mv_referrable (std::string, requests_exchange)
 
 snake_case_mv_referrable (std::string, alerts_exchange)
 
 snake_case_mv_referrable (std::string, heartbeat_routing_key)
 
 snake_case_mv_accessible (unsigned, max_payload_size)
 
 snake_case_mv_accessible (bool, make_connection)
 

Private Types

typedef std::shared_ptr< message_and_replymar_ptr
 

Private Member Functions

void do_cancellation (int a_code)
 
 snake_case_mv_referrable (receiver, msg_receiver)
 

Private Attributes

scarab::concurrent_queue< mar_ptrf_queue
 

Additional Inherited Members

- Static Public Member Functions inherited from core
static bool listen_for_message (amqp_envelope_ptr &a_envelope, amqp_channel_ptr a_channel, const std::string &a_consumer_tag, int a_timeout_ms=0, bool a_do_ack=true)
 return: if false, channel is no longer useable; if true, may be reused More...
 
- Static Public Attributes inherited from core
static bool s_offline = false
 
- Protected Member Functions inherited from core
sent_msg_pkg_ptr do_send (message_ptr_t a_message, const std::string &a_exchange, bool a_expect_reply) const
 
amqp_channel_ptr send_withreply (message_ptr_t a_message, std::string &a_reply_consumer_tag, const std::string &a_exchange) const
 
bool send_noreply (message_ptr_t a_message, const std::string &a_exchange) const
 
amqp_channel_ptr open_channel () const
 
- Static Protected Member Functions inherited from core
static bool setup_exchange (amqp_channel_ptr a_channel, const std::string &a_exchange)
 
static bool setup_queue (amqp_channel_ptr a_channel, const std::string &a_queue_name)
 
static bool bind_key (amqp_channel_ptr a_channel, const std::string &a_exchange, const std::string &a_queue_name, const std::string &a_routing_key)
 
static std::string start_consuming (amqp_channel_ptr a_channel, const std::string &a_queue_name)
 
static bool stop_consuming (amqp_channel_ptr a_channel, std::string &a_consumer_tag)
 
static bool remove_queue (amqp_channel_ptr a_channel, const std::string &a_queue_name)
 

Detailed Description

Asynchronous message sending.

Author
N.S. Oblath

This class allows a user to send message asynchronously. Messages are sent in a dedicated thread that runs the function execute_relayer(). Asynchronous operation is achieved using a concurrent queue to store messages that are submitted.

The primary user interface consists of send_async() and wait_for_reply(). The former immediately returns a special sent-message package that includes thread-synchonization objects. That package is then passed to the latter, which blocks while waiting for a reply.

Definition at line 37 of file relayer.hh.

Member Typedef Documentation

◆ mar_ptr

typedef std::shared_ptr< message_and_reply > mar_ptr
private

Definition at line 102 of file relayer.hh.

◆ wait_for_send_pkg_ptr

typedef std::shared_ptr< wait_for_send_pkg > wait_for_send_pkg_ptr

Definition at line 67 of file relayer.hh.

Constructor & Destructor Documentation

◆ relayer()

relayer ( const scarab::param_node &  a_config = scarab::param_node(),
const std::string &  a_broker_address = "",
unsigned  a_port = 0,
const std::string &  a_auth_file = "" 
)

Definition at line 16 of file relayer.cc.

◆ ~relayer()

~relayer ( )
virtual

Definition at line 24 of file relayer.cc.

Member Function Documentation

◆ do_cancellation()

void do_cancellation ( int  a_code)
private

Definition at line 80 of file relayer.cc.

◆ execute_relayer()

void execute_relayer ( )

Thread execution function: sends any messages that are submitted via the send functions.

Definition at line 28 of file relayer.cc.

◆ send_async() [1/2]

relayer::wait_for_send_pkg_ptr send_async ( request_ptr_t  a_request) const

Asynchronously send a request message Returns immediately, without blocking for send

Definition at line 87 of file relayer.cc.

◆ send_async() [2/2]

relayer::wait_for_send_pkg_ptr send_async ( alert_ptr_t  a_alert) const

Asynchronously send an alert message Returns immediately, without blocking for send

Definition at line 106 of file relayer.cc.

◆ snake_case_mv_referrable()

snake_case_mv_referrable ( receiver  ,
msg_receiver   
)
private

◆ wait_for_reply() [1/2]

reply_ptr_t wait_for_reply ( const wait_for_send_pkg_ptr  a_receive_reply,
int  a_timeout_ms = 0 
)

User interface for waiting for a reply message. This can be called multiple times to receive multiple replies.

Parameters
a_receive_replyThe sent-message package from the request.
a_timeout_msTimeout for waiting for a reply; if it's 0, there will be no timeout.
Returns
Reply message

Definition at line 125 of file relayer.cc.

◆ wait_for_reply() [2/2]

reply_ptr_t wait_for_reply ( const wait_for_send_pkg_ptr  a_receive_reply,
bool &  a_chan_valid,
int  a_timeout_ms = 0 
)

User interface for waiting for a reply message. This can be called multiple times to receive multiple replies.

Parameters
[in]a_receive_replyThe sent-message package from the request.
[in]a_timeout_msTimeout for waiting for a reply; if it's 0, there will be no timeout.
[out]a_chan_validReturns whether or not the channel is still valid for use after receiving a message.
Returns
Reply message

Definition at line 131 of file relayer.cc.

Member Data Documentation

◆ f_queue

scarab::concurrent_queue< mar_ptr > f_queue
mutableprivate

Definition at line 104 of file relayer.hh.


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