MXS-1775 Add MonitorInstanceSimple class

MonitorInstanceSimple is intended for simple monitors that
probe servers in a straightforward fashion. More complex monitors
can be derived directly from MonitorInstance.
This commit is contained in:
Johan Wikman
2018-06-07 11:25:44 +03:00
parent 880db1353a
commit 8afa8c2c5a
14 changed files with 82 additions and 51 deletions

View File

@ -168,14 +168,6 @@ protected:
*/
virtual bool has_sufficient_permissions() const;
/**
* @brief Update server information
*
* The implementation should probe the server in question and update
* the server status bits.
*/
virtual void update_server_status(MXS_MONITORED_SERVER* pMonitored_server) = 0;
/**
* @brief Flush pending server status to each server.
*
@ -189,23 +181,9 @@ protected:
* @brief Monitor the servers
*
* This function is called once per monitor round, and the concrete
* implementation should probe all servers, i.e. call @c update_server_status
* on each server.
*
* The default implementation will for each server:
* - Do nothing, if the server is in maintenance.
* - Before calling, store the previous status of the server.
* - Before calling, set the pending status of the monitored server object
* to the status of the corresponding server object.
* - Ensure that there is a connection to the server.
* If there is, @c update_server_status is called.
* If there is not, the pending status will be updated accordingly and
* @c update_server_status will *not* be called.
* - After the call, update the error count of the server if it is down.
*
* Finally, it will call @c flush_server_status.
* implementation should probe all servers and set server status bits.
*/
virtual void tick();
virtual void tick() = 0;
/**
* @brief Called before the monitor loop is started
@ -244,6 +222,59 @@ private:
static void main(void* pArg);
};
class MonitorInstanceSimple : public MonitorInstance
{
public:
MonitorInstanceSimple(const MonitorInstanceSimple&) = delete;
MonitorInstanceSimple& operator = (const MonitorInstanceSimple&) = delete;
protected:
MonitorInstanceSimple(MXS_MONITOR* pMonitor)
: MonitorInstance(pMonitor)
{
}
/**
* @brief Update server information
*
* The implementation should probe the server in question and update
* the server status bits.
*/
virtual void update_server_status(MXS_MONITORED_SERVER* pMonitored_server) = 0;
/**
* @brief Called right at the beginning of @c tick().
*
* The default implementation does nothing.
*/
virtual void pre_tick();
/**
* @brief Called right before the end of @c tick().
*
* The default implementation does nothing.
*/
virtual void post_tick();
private:
/**
* @brief Monitor the servers
*
* This function is called once per monitor round and will for each server:
*
* - Do nothing, if the server is in maintenance.
* - Store the previous status of the server.
* - Set the pending status of the monitored server object
* to the status of the corresponding server object.
* - Ensure that there is a connection to the server.
* If there is, @c update_server_status() is called.
* If there is not, the pending status will be updated accordingly and
* @c update_server_status() will *not* be called.
* - After the call, update the error count of the server if it is down.
*/
void tick(); // final
};
/**
* The purpose of the template MonitorApi is to provide an implementation
* of the monitor C-API. The template is instantiated with a class that