NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Analyzer.Process.Description.PeerStatJob Class Reference

Job which read statistics about peers and saves the result to a database. More...

Inheritance diagram for Ntp.Analyzer.Process.Description.PeerStatJob:
Collaboration diagram for Ntp.Analyzer.Process.Description.PeerStatJob:

Public Member Functions

 PeerStatJob (StatConfiguration config, LogBase log)
 
- Public Member Functions inherited from Ntp.Common.Process.JobDescription
override string ToString ()
 Returns a string that represents the current JobDescription. More...
 

Public Attributes

override string JobType => "Peer statistics"
 
override int Priority => 2
 
override ThreadType ThreadType => ThreadType.MultiThreaded
 
- Public Attributes inherited from Ntp.Common.Process.JobDescription
string Name => Configuration.ConfigName
 Gets the name. More...
 

Protected Member Functions

override void InternalExecute ()
 Implementing method for descendants. More...
 
- Protected Member Functions inherited from Ntp.Common.Process.JobDescription
 JobDescription (IJobConfiguration config, LogBase log)
 Initializes a new instance of the JobDescription class. More...
 

Private Member Functions

void Import ()
 Import statistics. More...
 
void Initialize ()
 Initialize database context. More...
 
void SaveResult ()
 Saves the result of the import to database. More...
 

Private Attributes

readonly List< PeerActivityactivities
 
readonly StatConfiguration config
 
readonly List< AssociationEntryentries
 
Host host
 
List< Peerpeers
 
readonly List< PeerReadingreadings
 

Additional Inherited Members

- Package Functions inherited from Ntp.Common.Process.JobDescription
void Execute ()
 Perform execution of this instance. More...
 
- Properties inherited from Ntp.Common.Process.JobDescription
IJobConfiguration Configuration [get]
 Gets the configuration for the job. More...
 
abstract string JobType [get]
 Gets the type of the job as text. More...
 
LogBase Log [get]
 Gets the log to use when registering events. More...
 
abstract int Priority [get]
 Gets the priority to use when scheduling jobs. More...
 
abstract ThreadType ThreadType [get]
 Gets a value indicating whether this JobDescription should run as a single thread. More...
 

Detailed Description

Job which read statistics about peers and saves the result to a database.

Definition at line 38 of file PeerStatJob.cs.

Constructor & Destructor Documentation

Ntp.Analyzer.Process.Description.PeerStatJob.PeerStatJob ( StatConfiguration  config,
LogBase  log 
)
inline

Definition at line 40 of file PeerStatJob.cs.

41  : base(config, log)
42  {
43  this.config = config;
44  readings = new List<PeerReading>();
45  activities = new List<PeerActivity>();
46  entries = new List<AssociationEntry>();
47  }
readonly List< PeerActivity > activities
Definition: PeerStatJob.cs:49
readonly List< PeerReading > readings
Definition: PeerStatJob.cs:53
readonly List< AssociationEntry > entries
Definition: PeerStatJob.cs:52

Member Function Documentation

void Ntp.Analyzer.Process.Description.PeerStatJob.Import ( )
inlineprivate

Import statistics.

Definition at line 80 of file PeerStatJob.cs.

References a, b, Ntp.Analyzer.Import.ImportFactory.CreatePeerImporter(), e, Ntp.Analyzer.Import.Importer< T >.Execute(), Ntp.Analyzer.Data.DataFace.Instance, Ntp.Analyzer.Objects.NamedObject.Name, Ntp.Analyzer.Data.DataFace.PeerActivities, and Ntp.Analyzer.Data.DataFace.ReadingBulks.

81  {
82  var bulk = config.Bulk == null
84  : DataFace.Instance.ReadingBulks.Single(b => b.Name == config.Bulk.Name);
85 
87  entries.AddRange(importer);
88 
89  // Read values
90  try
91  {
92  importer.Execute();
93  }
94  catch (Exception e)
95  {
96  Log.PeerImportError(e);
97  return;
98  }
99 
100  // Generate statistics
101  foreach (var entry in entries)
102  {
103  // Find peer in database.
104  var currentEntry = entry;
105  IEnumerable<Peer> peerList = peers.Where(p => p.Ip == currentEntry.Remote).ToList();
106  Peer peer;
107 
108  if (peerList.Count() == 1)
109  {
110  peer = peerList.Single();
111  }
112  else if (!peerList.Any())
113  {
114  Log.PeerIpNotFound(entry);
115  continue;
116  }
117  else
118  {
119  Log.PeerIpAmbiguous(entry);
120  continue;
121  }
122 
123  var reading = new PeerReading(host, peer, bulk, entry);
124  readings.Add(reading);
125 
126  // Update timestamp
127  var activity = DataFace.Instance.PeerActivities.
128  SingleOrDefault(a => Equals(a.Host, reading.Host) && Equals(a.Peer, reading.Peer));
129 
130  if (activity != null)
131  {
132  activity.LastActive = bulk.Time;
133  }
134  else
135  {
136  activity = new PeerActivity(reading.Peer, host, bulk.Time);
137  }
138 
139  activities.Add(activity);
140  }
141  }
string ServerName
Gets the name of the server in the HostSubConfiguration.
function a
Definition: bootstrap.min.js:6
LogBase Log
Gets the log to use when registering events.
static Importer< AssociationEntry > CreatePeerImporter(string address, ServerType type, Host host, LogBase log)
readonly List< PeerActivity > activities
Definition: PeerStatJob.cs:49
var e
Definition: bootstrap.min.js:6
Singleton facade class used to access memory persistent data.
Definition: DataFace.cs:30
readonly List< PeerReading > readings
Definition: PeerStatJob.cs:53
PeerActivityDatabaseMapper PeerActivities
Gets the peer activity mapper.
Definition: DataFace.cs:99
readonly List< AssociationEntry > entries
Definition: PeerStatJob.cs:52
static DataFace Instance
Gets the Singleton instance.
Definition: DataFace.cs:51
ServerType ServerType
Gets the type of the server in the HostSubConfiguration.
var b
Definition: bootstrap.min.js:6

Here is the call graph for this function:

void Ntp.Analyzer.Process.Description.PeerStatJob.Initialize ( )
inlineprivate

Initialize database context.

Definition at line 146 of file PeerStatJob.cs.

References Ntp.Analyzer.Data.DataFace.Hosts, Ntp.Analyzer.Data.DataFace.Instance, and Ntp.Analyzer.Data.DataFace.Peers.

147  {
148  // Clear any previous readings
149  entries.Clear();
150  readings.Clear();
151  activities.Clear();
152 
153  peers = DataFace.Instance.Peers.ToList();
154  host = DataFace.Instance.Hosts.SingleOrDefault(h => h.Id == config.HostId);
155 
156  if (host == null)
157  {
158  Log.HostNotFound(config.HostId);
159  }
160  }
HostDatabaseMapper Hosts
Gets the host mapper.
Definition: DataFace.cs:57
LogBase Log
Gets the log to use when registering events.
int HostId
Gets the host identifier in the HostSubConfiguration.
readonly List< PeerActivity > activities
Definition: PeerStatJob.cs:49
PeerDatabaseMapper Peers
Gets the peer mapper.
Definition: DataFace.cs:63
Singleton facade class used to access memory persistent data.
Definition: DataFace.cs:30
readonly List< PeerReading > readings
Definition: PeerStatJob.cs:53
readonly List< AssociationEntry > entries
Definition: PeerStatJob.cs:52
static DataFace Instance
Gets the Singleton instance.
Definition: DataFace.cs:51
override void Ntp.Analyzer.Process.Description.PeerStatJob.InternalExecute ( )
inlineprotectedvirtual

Implementing method for descendants.

Implements Ntp.Common.Process.JobDescription.

Definition at line 63 of file PeerStatJob.cs.

References e.

64  {
65  try
66  {
67  Initialize();
68  Import();
69  SaveResult();
70  }
71  catch (Exception e)
72  {
73  Log.PeerImportError(e);
74  }
75  }
LogBase Log
Gets the log to use when registering events.
var e
Definition: bootstrap.min.js:6
void Initialize()
Initialize database context.
Definition: PeerStatJob.cs:146
void SaveResult()
Saves the result of the import to database.
Definition: PeerStatJob.cs:165
void Ntp.Analyzer.Process.Description.PeerStatJob.SaveResult ( )
inlineprivate

Saves the result of the import to database.

Definition at line 165 of file PeerStatJob.cs.

References Ntp.Analyzer.Data.DataFace.AssociationEntries, Ntp.Analyzer.Data.DataFace.Instance, Ntp.Analyzer.Data.DataFace.PeerActivities, and Ntp.Analyzer.Data.DataFace.PeerReadings.

166  {
167  foreach (var reading in readings)
168  {
169  DataFace.Instance.PeerReadings.Save(reading);
170  }
171 
172  foreach (var activity in activities)
173  {
174  DataFace.Instance.PeerActivities.Save(activity);
175  }
176 
177  foreach (var entry in entries)
178  {
179  DataFace.Instance.AssociationEntries.Delete(entry.Remote, entry.HostId);
181  }
182  }
PeerReadingDatabaseMapper PeerReadings
Gets the peer reading mapper.
Definition: DataFace.cs:87
readonly List< PeerActivity > activities
Definition: PeerStatJob.cs:49
AssociationEntryMapper AssociationEntries
Gets the association entry mapper.
Definition: DataFace.cs:111
Singleton facade class used to access memory persistent data.
Definition: DataFace.cs:30
readonly List< PeerReading > readings
Definition: PeerStatJob.cs:53
PeerActivityDatabaseMapper PeerActivities
Gets the peer activity mapper.
Definition: DataFace.cs:99
readonly List< AssociationEntry > entries
Definition: PeerStatJob.cs:52
static DataFace Instance
Gets the Singleton instance.
Definition: DataFace.cs:51

Member Data Documentation

readonly List<PeerActivity> Ntp.Analyzer.Process.Description.PeerStatJob.activities
private

Definition at line 49 of file PeerStatJob.cs.

readonly StatConfiguration Ntp.Analyzer.Process.Description.PeerStatJob.config
private

Definition at line 51 of file PeerStatJob.cs.

readonly List<AssociationEntry> Ntp.Analyzer.Process.Description.PeerStatJob.entries
private

Definition at line 52 of file PeerStatJob.cs.

Host Ntp.Analyzer.Process.Description.PeerStatJob.host
private

Definition at line 54 of file PeerStatJob.cs.

override string Ntp.Analyzer.Process.Description.PeerStatJob.JobType => "Peer statistics"

Definition at line 59 of file PeerStatJob.cs.

List<Peer> Ntp.Analyzer.Process.Description.PeerStatJob.peers
private

Definition at line 55 of file PeerStatJob.cs.

override int Ntp.Analyzer.Process.Description.PeerStatJob.Priority => 2

Definition at line 61 of file PeerStatJob.cs.

readonly List<PeerReading> Ntp.Analyzer.Process.Description.PeerStatJob.readings
private

Definition at line 53 of file PeerStatJob.cs.

override ThreadType Ntp.Analyzer.Process.Description.PeerStatJob.ThreadType => ThreadType.MultiThreaded

Definition at line 57 of file PeerStatJob.cs.


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