NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Common.Process.Cluster Class Reference
Inheritance diagram for Ntp.Common.Process.Cluster:
Collaboration diagram for Ntp.Common.Process.Cluster:

Public Member Functions

 Cluster (Scheduler scheduler, IApplicationController controller, IEnumerable< IRequest > peers, LogBase log)
 
void Activate ()
 
void Dispose ()
 

Private Member Functions

 ~Cluster ()
 
void Dispose (bool disposing)
 

Private Attributes

bool disposedValue
 
readonly LogBase log
 
readonly IEnumerable< IRequestpeers
 
bool run
 
readonly Scheduler scheduler
 
readonly EventWaitHandle waitHandle
 

Detailed Description

Definition at line 31 of file Cluster.cs.

Constructor & Destructor Documentation

Ntp.Common.Process.Cluster.Cluster ( Scheduler  scheduler,
IApplicationController  controller,
IEnumerable< IRequest peers,
LogBase  log 
)
inline

Definition at line 33 of file Cluster.cs.

References e, Ntp.Common.App.IApplicationController.ExitApplication, and Ntp.Common.Process.Scheduler.WaitHandle.

38  {
39  this.scheduler = scheduler;
40  this.peers = peers;
41  this.log = log;
42 
43  waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
44  controller.ExitApplication += (sender, e) =>
45  {
46  run = false;
47  waitHandle.Set();
48  scheduler.WaitHandle.Set();
49  };
50  }
readonly LogBase log
Definition: Cluster.cs:52
var e
Definition: bootstrap.min.js:6
EventWaitHandle WaitHandle
Gets the wait handle of this Scheduler.
Definition: Scheduler.cs:70
readonly EventWaitHandle waitHandle
Definition: Cluster.cs:55
readonly Scheduler scheduler
Definition: Cluster.cs:54
readonly IEnumerable< IRequest > peers
Definition: Cluster.cs:53
Ntp.Common.Process.Cluster.~Cluster ( )
inlineprivate

Definition at line 141 of file Cluster.cs.

142  {
143  Dispose(false);
144  }

Member Function Documentation

void Ntp.Common.Process.Cluster.Activate ( )
inline

Definition at line 58 of file Cluster.cs.

References e.

59  {
60  bool activated = true;
61  if (peers.Count() != 0)
62  {
63  log.ClusterStart();
64  }
65 
66  run = true;
67  while (run)
68  {
69  bool otherActive = false;
70  foreach (var request in peers)
71  {
72  try
73  {
74  string answer = request.Send("ping");
75 
76  if (answer != null && answer == "*" && activated)
77  {
78  log.ClusterNodeAlive(request);
79  }
80  else if (answer != null && answer == "active" && activated)
81  {
82  log.ClusterNodeActive(request);
83  }
84  else if (activated)
85  {
86  log.ClusterNodeDead(request);
87  }
88 
89  if (answer != null && answer == "active")
90  {
91  otherActive = true;
92  }
93  }
94  catch (Exception e)
95  {
96  log.ClusterNodeError(request, e);
97  }
98  }
99 
100  if (!otherActive)
101  {
102  try
103  {
105  }
106  catch (Exception e)
107  {
108  log.ClusterError(e);
109  return;
110  }
111  }
112  else
113  {
114  waitHandle.WaitOne(10000);
115  }
116 
117  // This node is now active and no longer "activated"
118  activated = false;
119  }
120 
121  scheduler.Stop();
122  }
readonly LogBase log
Definition: Cluster.cs:52
var e
Definition: bootstrap.min.js:6
void RunOneCycle()
Run the scheduler "queue pump" method.
Definition: Scheduler.cs:151
readonly EventWaitHandle waitHandle
Definition: Cluster.cs:55
readonly Scheduler scheduler
Definition: Cluster.cs:54
readonly IEnumerable< IRequest > peers
Definition: Cluster.cs:53
void Ntp.Common.Process.Cluster.Dispose ( bool  disposing)
inlineprivate

Definition at line 128 of file Cluster.cs.

129  {
130  if (disposedValue)
131  return;
132 
133  if (disposing)
134  {
135  waitHandle.Dispose();
136  }
137 
138  disposedValue = true;
139  }
readonly EventWaitHandle waitHandle
Definition: Cluster.cs:55
void Ntp.Common.Process.Cluster.Dispose ( )
inline

Definition at line 146 of file Cluster.cs.

147  {
148  Dispose(true);
149  GC.SuppressFinalize(this);
150  }

Member Data Documentation

bool Ntp.Common.Process.Cluster.disposedValue
private

Definition at line 126 of file Cluster.cs.

readonly LogBase Ntp.Common.Process.Cluster.log
private

Definition at line 52 of file Cluster.cs.

readonly IEnumerable<IRequest> Ntp.Common.Process.Cluster.peers
private

Definition at line 53 of file Cluster.cs.

bool Ntp.Common.Process.Cluster.run
private

Definition at line 56 of file Cluster.cs.

readonly Scheduler Ntp.Common.Process.Cluster.scheduler
private

Definition at line 54 of file Cluster.cs.

readonly EventWaitHandle Ntp.Common.Process.Cluster.waitHandle
private

Definition at line 55 of file Cluster.cs.


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