feisty meow concerns codebase  2.140
processes::heartbeat Class Reference

Monitors a periodic heartbeat to track a resource's health. More...

#include <heartbeat.h>

Inheritance diagram for processes::heartbeat:
Collaboration diagram for processes::heartbeat:

Public Member Functions

 heartbeat (int misses_allowed=500, int check_interval=10000)
 creates a heartbeat monitor with the specified interval and maximum skips permitted. More...
 
 heartbeat (const heartbeat &to_copy)
 
 ~heartbeat ()
 
 DEFINE_CLASS_NAME ("heartbeat")
 
heartbeatoperator= (const heartbeat &to_copy)
 
basis::astring text_form (bool detailed=false) const
 returns a readable form of the heartbeat's information. More...
 
void reset (int misses_allowed, int check_interval)
 retrains the heartbeat monitor for a new configuration. More...
 
bool due () const
 is the next heartbeat due yet? More...
 
bool dead () const
 is this object considered dead from missing too many heartbeats? More...
 
void made_request ()
 records that another heartbeat request was sent out. More...
 
void need_beat ()
 a synonym for the made_request() method. More...
 
void kabump ()
 registers a heartbeat response and sets the state to healthy. More...
 
void recycle ()
 a synonym for kabump(). More...
 
int missed_so_far () const
 returns the number of heartbeat responses that are pending. More...
 
int misses_left () const
 the number of misses that this object is still allowed. More...
 
int allowed_misses () const
 returns the number of misses allowed overall. More...
 
int checking_interval () const
 returns the period of the heartbeats. More...
 
timely::time_stamp heartbeat_time () const
 returns the time when the next heartbeat will be requested. More...
 
int time_left () const
 number of milliseconds left before the next beat will be requested. More...
 

Detailed Description

Monitors a periodic heartbeat to track a resource's health.

The heartbeat is defined as a "request-and-response" based check; when the next periodic heartbeat is due, a request is sent out. The heartbeat request is considered successfully dealt with only if a response comes back for the request. If the user-defined number of requests are sent without a single response coming back, then the 'patient' is considered dead.

Definition at line 33 of file heartbeat.h.

Constructor & Destructor Documentation

◆ heartbeat() [1/2]

processes::heartbeat::heartbeat ( int  misses_allowed = 500,
int  check_interval = 10000 
)

creates a heartbeat monitor with the specified interval and maximum skips permitted.

this allows the heartbeat request to be missed "misses_allowed" times. the heartbeats will become due every "check_interval" milliseconds. the defaults are a joke; you really need to set them.

Definition at line 29 of file heartbeat.cpp.

References reset().

◆ heartbeat() [2/2]

processes::heartbeat::heartbeat ( const heartbeat to_copy)

Definition at line 36 of file heartbeat.cpp.

◆ ~heartbeat()

processes::heartbeat::~heartbeat ( )

Definition at line 44 of file heartbeat.cpp.

References basis::WHACK().

Member Function Documentation

◆ allowed_misses()

int processes::heartbeat::allowed_misses ( ) const
inline

returns the number of misses allowed overall.

Definition at line 88 of file heartbeat.h.

◆ checking_interval()

int processes::heartbeat::checking_interval ( ) const
inline

returns the period of the heartbeats.

Definition at line 90 of file heartbeat.h.

Referenced by text_form().

◆ dead()

bool processes::heartbeat::dead ( ) const

is this object considered dead from missing too many heartbeats?

this is true if the heartbeat being monitored missed too many responses to heartbeat requests. if the maximum allowed requests have been made and there was not even a single response, then the object is considered dead.

Definition at line 60 of file heartbeat.cpp.

References due().

Referenced by text_form().

◆ DEFINE_CLASS_NAME()

processes::heartbeat::DEFINE_CLASS_NAME ( "heartbeat"  )

◆ due()

bool processes::heartbeat::due ( ) const

is the next heartbeat due yet?

Definition at line 48 of file heartbeat.cpp.

References time_left().

Referenced by dead(), and text_form().

◆ heartbeat_time()

time_stamp processes::heartbeat::heartbeat_time ( ) const

returns the time when the next heartbeat will be requested.

if no heartbeats had been missed yet, then this is the time when the due() method starts returning true.

Definition at line 46 of file heartbeat.cpp.

Referenced by text_form().

◆ kabump()

void processes::heartbeat::kabump ( )

registers a heartbeat response and sets the state to healthy.

this records that a heartbeat response came back from the monitored object. after this call, there are no heartbeats recorded as missed at all.

Definition at line 52 of file heartbeat.cpp.

Referenced by recycle().

◆ made_request()

void processes::heartbeat::made_request ( )

records that another heartbeat request was sent out.

the time for the next heartbeat request is reset to the time between beats. if there were already the maximum allowed number of missed responses, then the object is now dead.

Definition at line 50 of file heartbeat.cpp.

Referenced by need_beat().

◆ missed_so_far()

int processes::heartbeat::missed_so_far ( ) const
inline

returns the number of heartbeat responses that are pending.

Definition at line 83 of file heartbeat.h.

Referenced by text_form().

◆ misses_left()

int processes::heartbeat::misses_left ( ) const
inline

the number of misses that this object is still allowed.

Definition at line 85 of file heartbeat.h.

Referenced by text_form().

◆ need_beat()

void processes::heartbeat::need_beat ( )
inline

a synonym for the made_request() method.

Definition at line 70 of file heartbeat.h.

References made_request().

◆ operator=()

heartbeat & processes::heartbeat::operator= ( const heartbeat to_copy)

Definition at line 90 of file heartbeat.cpp.

◆ recycle()

void processes::heartbeat::recycle ( )
inline

a synonym for kabump().

Definition at line 78 of file heartbeat.h.

References kabump().

◆ reset()

void processes::heartbeat::reset ( int  misses_allowed,
int  check_interval 
)

retrains the heartbeat monitor for a new configuration.

Definition at line 68 of file heartbeat.cpp.

Referenced by heartbeat().

◆ text_form()

astring processes::heartbeat::text_form ( bool  detailed = false) const

returns a readable form of the heartbeat's information.

Definition at line 76 of file heartbeat.cpp.

References checking_interval(), dead(), due(), heartbeat_time(), missed_so_far(), misses_left(), and timely::time_stamp::text_form().

◆ time_left()

int processes::heartbeat::time_left ( ) const

number of milliseconds left before the next beat will be requested.

if the number is zero or negative, then a heartbeat is due.

Definition at line 57 of file heartbeat.cpp.

References timely::time_stamp::value().

Referenced by due().


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