NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Common.App.Heartbeat Class Reference
Collaboration diagram for Ntp.Common.App.Heartbeat:

Public Member Functions

 Heartbeat (LogBase log, int interval)
 
void Start ()
 
void Stop ()
 

Private Member Functions

void Pulse ()
 

Private Attributes

bool alive
 
int beats
 
readonly int interval
 
readonly LogBase log
 
DateTime start
 

Detailed Description

Definition at line 29 of file Heartbeat.cs.

Constructor & Destructor Documentation

Ntp.Common.App.Heartbeat.Heartbeat ( LogBase  log,
int  interval 
)
inline

Definition at line 31 of file Heartbeat.cs.

32  {
33  this.log = log;
34  this.interval = interval;
35  }
readonly int interval
Definition: Heartbeat.cs:37
readonly LogBase log
Definition: Heartbeat.cs:38

Member Function Documentation

void Ntp.Common.App.Heartbeat.Pulse ( )
inlineprivate

Definition at line 65 of file Heartbeat.cs.

66  {
67  while (alive)
68  {
69  int next = (beats + 1)*interval;
70  var sleep = start.AddMinutes(next).Subtract(DateTime.Now).TotalMilliseconds;
71  Thread.Sleep(Convert.ToInt32(sleep));
72  beats++;
73 
74  var span = TimeSpan.FromMinutes(beats*interval);
75  var builder = new StringBuilder();
76 
77  if (span.Days != 0)
78  {
79  builder.Append(span.Days);
80  builder.Append(" day");
81  }
82 
83  if (span.Days > 1)
84  {
85  builder.Append("s");
86  }
87 
88  if (span.Days >= 1)
89  {
90  if (span.Hours != 0 && span.Minutes == 0)
91  {
92  builder.Append(" and ");
93  }
94  else if (span.Hours == 0 && span.Minutes != 0)
95  {
96  builder.Append(" and ");
97  }
98  else if (span.Hours != 0 && span.Minutes != 0)
99  {
100  builder.Append(", ");
101  }
102  }
103 
104  if (span.Hours != 0)
105  {
106  builder.Append(span.Hours);
107  builder.Append(" hour");
108  }
109 
110  if (span.Hours > 1)
111  {
112  builder.Append("s");
113  }
114 
115  if (span.Hours >= 1 && span.Minutes != 0)
116  {
117  builder.Append(" ");
118  }
119 
120  if (span.Hours != 0 && span.Minutes != 0)
121  {
122  builder.Append("and ");
123  }
124 
125  if (span.Minutes != 0)
126  {
127  builder.Append(span.Minutes);
128  builder.Append(" minute");
129  }
130 
131  if (span.Minutes > 1)
132  {
133  builder.Append("s");
134  }
135 
136  log.HeartbeatUptime(builder.ToString());
137  }
138  }
readonly int interval
Definition: Heartbeat.cs:37
readonly LogBase log
Definition: Heartbeat.cs:38
void Ntp.Common.App.Heartbeat.Start ( )
inline

Definition at line 43 of file Heartbeat.cs.

44  {
45  start = DateTime.Now;
46  alive = true;
47  beats = 0;
48 
49  var thread = new Thread(Pulse)
50  {
51  Name = "Heartbeat",
52  IsBackground = true,
53  Priority = ThreadPriority.AboveNormal
54  };
55 
56  thread.Start();
57  log.HeartbeatStarted(interval);
58  }
readonly int interval
Definition: Heartbeat.cs:37
readonly LogBase log
Definition: Heartbeat.cs:38
void Ntp.Common.App.Heartbeat.Stop ( )
inline

Definition at line 60 of file Heartbeat.cs.

61  {
62  alive = false;
63  }

Member Data Documentation

bool Ntp.Common.App.Heartbeat.alive
private

Definition at line 39 of file Heartbeat.cs.

int Ntp.Common.App.Heartbeat.beats
private

Definition at line 40 of file Heartbeat.cs.

readonly int Ntp.Common.App.Heartbeat.interval
private

Definition at line 37 of file Heartbeat.cs.

readonly LogBase Ntp.Common.App.Heartbeat.log
private

Definition at line 38 of file Heartbeat.cs.

DateTime Ntp.Common.App.Heartbeat.start
private

Definition at line 41 of file Heartbeat.cs.


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