#ifndef __PushAlerts_h_ #define __PushAlerts_h_ #include "../../shared/ThreadClass.h" #include "../../shared/DatabaseWithRetry.h" #include "AlertMatricies.h" /* This class is reponsible for sending alerts to the database. * * This class is designed to listen to to the alert matrix directly. The * Delphi version had a GUI sitting between these two pieces, which slowed * things down more than it should have. I mean that literally. There was * a timer that would go off every 100ms to keep the GUI from using too much * CPU. The push to the database was also limited by that timer! * * There are many possible arrangements. Presumably another unit will create * one of these, and multiple alert matrix objects. All of the alert matrix * objects will send alerts to the same PushAlerts object. * * This is implemented as a thread with a standard event queue. When an * alert is given to this unit, all it does is creates a simple wrapper * around the object and puts it in the queue. Submitting an alert is a quick * process, even if the database is slow or broken. * * At this time the implementation is very simple. In particular, it never * throws away alerts. It works just like all of our queues, where it will * report a backlog to the log file, but nothing will be ignored. The Delphi * version had a fized sized queue, and would throw out old alerts if required. * I think that's overkill. If the database goes down for an extended period * then we have bigger problems on our hands. * * We also send status messages to the monitor_alive table. The Delphi version * had a different source for these messages. But, in any case, the message * tests multiple threads, and the connection to the database. In an * improvement to the Delphi version, this code works even when multiple copies * of this program are all running on the same server. * * This thread is smart enough to send alerts, top list entries, or both. * However, when under enough stress, it might not give fair time to one or the * other. So you can more than one of these threads. */ class PushAlertsThread : private ThreadClass, public AlertMatrixListener { private: enum { mtAlert, mtDeadManTimer, mtTest, mtQuit }; RequestQueue _incoming; volatile bool _fake; void onAlert(AlertEvent *event); protected: void threadFunction(); public: void updateDeadManTimer(); PushAlertsThread(std::string name = "PushAlertsThread", std::string debugPrefix = ""); ~PushAlertsThread(); void setFake(bool fake) { _fake = fake; } }; #endif