-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExceptionMonitor.cpp
87 lines (72 loc) · 2.42 KB
/
ExceptionMonitor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include"SystemManager/ExceptionMonitor.h"
namespace SystemManagerSpace
{
// -------------------------------------------------------
// constructor/destructor ExceptionMonitor
// - Constructor: Initializes the ExceptionMonitor
// -------------------------------------------------------
ExceptionMonitor::ExceptionMonitor(string name)
: Thread(name)
, exceptionSubscriber(NULL)
, stopExceptionMonitor(false)
{
exceptionSubscriber = new ExceptionMulticastSubscriber(ExceptionMulticast::GetMulticastHandle(), this, true);
}
ExceptionMonitor::~ExceptionMonitor()
{
stopExceptionMonitor = true;
// -> Is selfdestructing!
//if(exceptionSubscriber != NULL)
//{
// exceptionSubscriber->Shutdown();
// delete exceptionSubscriber;
// exceptionSubscriber = NULL;
//}
}
// NB! Thread is never started
// TODO: Anything to do in this thread?
void ExceptionMonitor::run()
{
while(!stopExceptionMonitor)
{
msleep(1000);
if(stopExceptionMonitor) break;
}
}
void ExceptionMonitor::PrintAll(std::ostream &ostr)
{
MutexLocker lock(&updateLock);
ostr << "---------------------------- Exceptions Received ----------------------------" << endl;
for(size_t i = 0; i < vectorTimeStampExceptionMessage.size(); i++)
{
ostr << vectorTimeStampExceptionMessage[i] << endl;
}
}
void ExceptionMonitor::ClearAll()
{
MutexLocker lock(&updateLock);
vectorTimeStampExceptionMessage.clear();
}
void ExceptionMonitor::PostException(ExceptionMessage &exceptionMessage)
{
MutexLocker lock(&updateLock);
vectorTimeStampExceptionMessage.push_back(exceptionMessage);
}
map<long long, ExceptionMessage> ExceptionMonitor::GetMiddlewareExceptions(long long &lastTimestamp)
{
MutexLocker lock(&updateLock);
if(lastTimestamp < 0) lastTimestamp = 0;
if(lastTimestamp > vectorTimeStampExceptionMessage.size()) // fix silently
{
lastTimestamp = vectorTimeStampExceptionMessage.size();
//cout << "ExceptionMonitor::GetMiddlewareExceptions(" << lastTimestamp << "): WARNING! timestamp is too large! Current timestamp: " << vectorTimeStampExceptionMessage.size() << endl;
}
MapTimeStampExceptionMessage mapTimestampExceptionMessage;
for( ; lastTimestamp < vectorTimeStampExceptionMessage.size(); lastTimestamp++)
{
ExceptionMessage &ex = vectorTimeStampExceptionMessage[(unsigned int)lastTimestamp];
mapTimestampExceptionMessage.insert(pair<long long, ExceptionMessage>(lastTimestamp, ex));
}
return mapTimestampExceptionMessage;
}
} // namespace SystemManagerSpace