Dripline-Cpp  v2.4.2
Dripline Implementation in C++
Public Member Functions | Protected Attributes | List of all members
heartbeater Class Reference

A heartbeater repeatedly sends an alert on a particular time interval. More...

#include <heartbeater.hh>

Inheritance diagram for heartbeater:
Inheritance graph

Public Member Functions

 heartbeater (service_ptr_t a_service=service_ptr_t())
 Primary constructor. A service pointer is required to be able to send messages. More...
 
 heartbeater (const heartbeater &)=delete
 
 heartbeater (heartbeater &&a_orig)
 
virtual ~heartbeater ()
 
heartbeateroperator= (const heartbeater &)=delete
 
heartbeateroperator= (heartbeater &&a_orig)
 
void execute (const std::string &a_name, uuid_t a_id, const std::string &a_routing_key)
 
 snake_case_mv_accessible (unsigned, heartbeat_interval_s)
 Interval between heartbeat alerts (default: 60 s) More...
 
 snake_case_mv_accessible (unsigned, check_timeout_ms)
 Timing interval for the internal loop (default: 1000 ms) More...
 
 snake_case_mv_referrable (service_ptr_t, service)
 
 snake_case_mv_atomic (bool, stop)
 

Protected Attributes

std::thread f_heartbeat_thread
 

Detailed Description

A heartbeater repeatedly sends an alert on a particular time interval.

Author
N.S. Oblath

This class is intended to be used as a mix-in to add heartbeat capabilities to another class by inheriting from it. See service as an example of its use.

The heartbeat is an alert sent to a pre-determined routing key, which is given as a parameter to the execute() function. The interval for sending the heartbeats is f_heartbeat_interval_s, which is in seconds. The default interval is 60 s.

If the heartbeat interval is 0, the sending of heartbeats is disabled.

The parameters provided upon execution are the name (a_name, e.g. the service name), a UUID (a_id), and the routing key (a_routing_key).

The payload of each heartbeat message will be:

{
name: [a_name]
id: [a_id]
}

The routing key to which the message will be sent is a_routing_key.a_name.

Definition at line 52 of file heartbeater.hh.

Constructor & Destructor Documentation

◆ heartbeater() [1/3]

Primary constructor. A service pointer is required to be able to send messages.

Definition at line 25 of file heartbeater.cc.

◆ heartbeater() [2/3]

heartbeater ( const heartbeater )
delete

◆ heartbeater() [3/3]

heartbeater ( heartbeater &&  a_orig)

Definition at line 33 of file heartbeater.cc.

◆ ~heartbeater()

~heartbeater ( )
virtual

Definition at line 41 of file heartbeater.cc.

Member Function Documentation

◆ execute()

void execute ( const std::string &  a_name,
uuid_t  a_id,
const std::string &  a_routing_key 
)

Starts the heartbeat process. Heartbeat alerts are emitted every heartbeat_interval_s seconds. If the interval is 0, then heartbeats are disabled.

Parameters
a_nameThe name for the heartbeater (e.g. the service)
a_idUUID for the heartbeater
a_routing_keyThe base of the routing key for heartbeat alerts; will be postpended with a_name

Definition at line 53 of file heartbeater.cc.

◆ operator=() [1/2]

heartbeater& operator= ( const heartbeater )
delete

◆ operator=() [2/2]

heartbeater & operator= ( heartbeater &&  a_orig)

Definition at line 44 of file heartbeater.cc.

◆ snake_case_mv_accessible() [1/2]

snake_case_mv_accessible ( unsigned  ,
heartbeat_interval_s   
)

Interval between heartbeat alerts (default: 60 s)

◆ snake_case_mv_accessible() [2/2]

snake_case_mv_accessible ( unsigned  ,
check_timeout_ms   
)

Timing interval for the internal loop (default: 1000 ms)

◆ snake_case_mv_atomic()

snake_case_mv_atomic ( bool  ,
stop   
)

◆ snake_case_mv_referrable()

snake_case_mv_referrable ( service_ptr_t  ,
service   
)

Member Data Documentation

◆ f_heartbeat_thread

std::thread f_heartbeat_thread
protected

Definition at line 83 of file heartbeater.hh.


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