feisty meow concerns codebase  2.140
heartbeat.h
Go to the documentation of this file.
1 #ifndef HEARTBEAT_CLASS
2 #define HEARTBEAT_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : heartbeat *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 1996-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include <basis/astring.h>
19 #include <basis/contracts.h>
20 #include <timely/time_stamp.h>
21 
22 namespace processes {
23 
25 
33 class heartbeat : public virtual basis::root_object
34 {
35 public:
36  heartbeat(int misses_allowed = 500, int check_interval = 10000);
38 
41  heartbeat(const heartbeat &to_copy);
42 
43  ~heartbeat();
44 
45  DEFINE_CLASS_NAME("heartbeat");
46 
47  heartbeat &operator =(const heartbeat &to_copy);
48 
49  basis::astring text_form(bool detailed = false) const;
51 
52  void reset(int misses_allowed, int check_interval);
54 
55  bool due() const;
57 
58  bool dead() const;
60 
65  void made_request();
67 
70  void need_beat() { made_request(); }
72 
73  void kabump();
75 
78  void recycle() { kabump(); }
80 
81  // reporting functions for internal state...
82 
83  int missed_so_far() const { return _misses; }
85  int misses_left() const { return _misses_allowed - _misses; }
87 
88  int allowed_misses() const { return _misses_allowed; }
90  int checking_interval() const { return _check_interval; }
92 
95 
98  int time_left() const;
100 
102 private:
103  timely::time_stamp *_next_heartbeat;
104  int _check_interval;
105  int _misses_allowed;
106  int _misses;
107 
108  void reset_next_beat();
109 };
110 
111 } //namespace.
112 
113 #endif
114 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
Monitors a periodic heartbeat to track a resource's health.
Definition: heartbeat.h:34
void made_request()
records that another heartbeat request was sent out.
Definition: heartbeat.cpp:50
void recycle()
a synonym for kabump().
Definition: heartbeat.h:78
int misses_left() const
the number of misses that this object is still allowed.
Definition: heartbeat.h:85
int checking_interval() const
returns the period of the heartbeats.
Definition: heartbeat.h:90
heartbeat & operator=(const heartbeat &to_copy)
Definition: heartbeat.cpp:90
int allowed_misses() const
returns the number of misses allowed overall.
Definition: heartbeat.h:88
timely::time_stamp heartbeat_time() const
returns the time when the next heartbeat will be requested.
Definition: heartbeat.cpp:46
void reset(int misses_allowed, int check_interval)
retrains the heartbeat monitor for a new configuration.
Definition: heartbeat.cpp:68
bool due() const
is the next heartbeat due yet?
Definition: heartbeat.cpp:48
int missed_so_far() const
returns the number of heartbeat responses that are pending.
Definition: heartbeat.h:83
int time_left() const
number of milliseconds left before the next beat will be requested.
Definition: heartbeat.cpp:57
heartbeat(int misses_allowed=500, int check_interval=10000)
creates a heartbeat monitor with the specified interval and maximum skips permitted.
Definition: heartbeat.cpp:29
bool dead() const
is this object considered dead from missing too many heartbeats?
Definition: heartbeat.cpp:60
basis::astring text_form(bool detailed=false) const
returns a readable form of the heartbeat's information.
Definition: heartbeat.cpp:76
DEFINE_CLASS_NAME("heartbeat")
void need_beat()
a synonym for the made_request() method.
Definition: heartbeat.h:70
void kabump()
registers a heartbeat response and sets the state to healthy.
Definition: heartbeat.cpp:52
Represents a point in time relative to the operating system startup time.
Definition: time_stamp.h:38