2019-02-25 08:48:22 -05:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2012-06-14 05:23:25 -04:00
|
|
|
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "checker/checkercomponent.hpp"
|
2018-01-18 07:50:38 -05:00
|
|
|
#include "checker/checkercomponent-ti.cpp"
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "icinga/icingaapplication.hpp"
|
|
|
|
|
#include "icinga/cib.hpp"
|
|
|
|
|
#include "remote/apilistener.hpp"
|
2019-04-15 10:56:30 -04:00
|
|
|
#include "base/configuration.hpp"
|
2015-08-15 14:28:05 -04:00
|
|
|
#include "base/configtype.hpp"
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "base/objectlock.hpp"
|
|
|
|
|
#include "base/utility.hpp"
|
2017-05-15 09:51:39 -04:00
|
|
|
#include "base/perfdatavalue.hpp"
|
2014-10-19 08:21:12 -04:00
|
|
|
#include "base/logger.hpp"
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "base/exception.hpp"
|
|
|
|
|
#include "base/convert.hpp"
|
|
|
|
|
#include "base/statsfunction.hpp"
|
2021-02-02 04:16:04 -05:00
|
|
|
#include <chrono>
|
2012-06-14 05:23:25 -04:00
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
2013-03-12 08:45:54 -04:00
|
|
|
REGISTER_TYPE(CheckerComponent);
|
2014-02-18 04:53:44 -05:00
|
|
|
|
2015-09-21 05:44:58 -04:00
|
|
|
REGISTER_STATSFUNCTION(CheckerComponent, &CheckerComponent::StatsFunc);
|
2014-02-17 10:34:18 -05:00
|
|
|
|
2015-02-07 16:36:17 -05:00
|
|
|
void CheckerComponent::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
|
2014-02-17 10:34:18 -05:00
|
|
|
{
|
2018-01-11 05:17:38 -05:00
|
|
|
DictionaryData nodes;
|
2014-02-18 04:53:44 -05:00
|
|
|
|
2016-08-25 00:19:44 -04:00
|
|
|
for (const CheckerComponent::Ptr& checker : ConfigType::GetObjectsByType<CheckerComponent>()) {
|
2014-04-03 09:36:13 -04:00
|
|
|
unsigned long idle = checker->GetIdleCheckables();
|
|
|
|
|
unsigned long pending = checker->GetPendingCheckables();
|
2014-02-18 04:53:44 -05:00
|
|
|
|
2018-01-11 05:17:38 -05:00
|
|
|
nodes.emplace_back(checker->GetName(), new Dictionary({
|
|
|
|
|
{ "idle", idle },
|
|
|
|
|
{ "pending", pending }
|
|
|
|
|
}));
|
2014-02-18 04:53:44 -05:00
|
|
|
|
|
|
|
|
String perfdata_prefix = "checkercomponent_" + checker->GetName() + "_";
|
2014-11-08 15:17:16 -05:00
|
|
|
perfdata->Add(new PerfdataValue(perfdata_prefix + "idle", Convert::ToDouble(idle)));
|
|
|
|
|
perfdata->Add(new PerfdataValue(perfdata_prefix + "pending", Convert::ToDouble(pending)));
|
2014-02-18 04:53:44 -05:00
|
|
|
}
|
|
|
|
|
|
2018-01-11 05:17:38 -05:00
|
|
|
status->Set("checkercomponent", new Dictionary(std::move(nodes)));
|
2014-02-17 10:34:18 -05:00
|
|
|
}
|
2013-03-12 08:45:54 -04:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
void CheckerComponent::OnConfigLoaded()
|
2012-06-14 05:23:25 -04:00
|
|
|
{
|
2021-01-18 08:29:05 -05:00
|
|
|
ConfigObject::OnActiveChanged.connect([this](const ConfigObject::Ptr& object, const Value&) {
|
|
|
|
|
ObjectHandler(object);
|
|
|
|
|
});
|
|
|
|
|
ConfigObject::OnPausedChanged.connect([this](const ConfigObject::Ptr& object, const Value&) {
|
|
|
|
|
ObjectHandler(object);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Checkable::OnNextCheckChanged.connect([this](const Checkable::Ptr& checkable, const Value&) {
|
|
|
|
|
NextCheckChangedHandler(checkable);
|
|
|
|
|
});
|
2013-11-28 14:56:21 -05:00
|
|
|
}
|
|
|
|
|
|
2015-08-20 11:18:48 -04:00
|
|
|
void CheckerComponent::Start(bool runtimeCreated)
|
2013-11-28 14:56:21 -05:00
|
|
|
{
|
2015-08-20 11:18:48 -04:00
|
|
|
ObjectImpl<CheckerComponent>::Start(runtimeCreated);
|
2012-08-03 17:03:58 -04:00
|
|
|
|
2017-02-08 08:53:52 -05:00
|
|
|
Log(LogInformation, "CheckerComponent")
|
2017-12-19 09:50:05 -05:00
|
|
|
<< "'" << GetName() << "' started.";
|
2017-02-08 08:53:52 -05:00
|
|
|
|
|
|
|
|
|
2021-01-18 08:29:05 -05:00
|
|
|
m_Thread = std::thread([this]() { CheckThreadProc(); });
|
2012-06-14 05:23:25 -04:00
|
|
|
|
2023-03-21 05:30:15 -04:00
|
|
|
m_ResultTimer = Timer::Create();
|
2012-06-17 17:10:03 -04:00
|
|
|
m_ResultTimer->SetInterval(5);
|
2021-01-18 08:29:05 -05:00
|
|
|
m_ResultTimer->OnTimerExpired.connect([this](const Timer * const&) { ResultTimerHandler(); });
|
2012-06-17 14:35:56 -04:00
|
|
|
m_ResultTimer->Start();
|
2012-06-14 05:23:25 -04:00
|
|
|
}
|
|
|
|
|
|
2015-08-20 11:18:48 -04:00
|
|
|
void CheckerComponent::Stop(bool runtimeRemoved)
|
2012-06-14 05:23:25 -04:00
|
|
|
{
|
2013-02-19 17:02:08 -05:00
|
|
|
{
|
2021-02-02 04:16:04 -05:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2013-02-19 17:02:08 -05:00
|
|
|
m_Stopped = true;
|
|
|
|
|
m_CV.notify_all();
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-22 11:34:37 -04:00
|
|
|
m_WaitGroup->Join();
|
2023-04-13 10:19:58 -04:00
|
|
|
m_ResultTimer->Stop(true);
|
2013-02-19 17:02:08 -05:00
|
|
|
m_Thread.join();
|
2014-04-16 09:01:31 -04:00
|
|
|
|
2019-01-24 07:55:17 -05:00
|
|
|
Log(LogInformation, "CheckerComponent")
|
|
|
|
|
<< "'" << GetName() << "' stopped.";
|
|
|
|
|
|
2015-08-20 11:18:48 -04:00
|
|
|
ObjectImpl<CheckerComponent>::Stop(runtimeRemoved);
|
2012-06-14 05:23:25 -04:00
|
|
|
}
|
|
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
void CheckerComponent::CheckThreadProc()
|
2012-06-14 05:23:25 -04:00
|
|
|
{
|
2013-08-30 04:19:32 -04:00
|
|
|
Utility::SetThreadName("Check Scheduler");
|
2019-04-15 10:56:30 -04:00
|
|
|
IcingaApplication::Ptr icingaApp = IcingaApplication::GetInstance();
|
2013-08-30 04:19:32 -04:00
|
|
|
|
2021-02-02 04:16:04 -05:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2013-02-17 13:14:34 -05:00
|
|
|
|
2013-02-23 19:10:34 -05:00
|
|
|
for (;;) {
|
2014-04-03 09:36:13 -04:00
|
|
|
typedef boost::multi_index::nth_index<CheckableSet, 1>::type CheckTimeView;
|
|
|
|
|
CheckTimeView& idx = boost::get<1>(m_IdleCheckables);
|
2013-02-17 13:14:34 -05:00
|
|
|
|
2013-02-21 10:12:50 -05:00
|
|
|
while (idx.begin() == idx.end() && !m_Stopped)
|
|
|
|
|
m_CV.wait(lock);
|
2012-08-04 07:49:25 -04:00
|
|
|
|
2013-02-21 10:12:50 -05:00
|
|
|
if (m_Stopped)
|
|
|
|
|
break;
|
2013-02-19 17:02:08 -05:00
|
|
|
|
2016-08-27 13:56:12 -04:00
|
|
|
auto it = idx.begin();
|
2016-07-28 06:50:48 -04:00
|
|
|
CheckableScheduleInfo csi = *it;
|
2013-02-17 13:14:34 -05:00
|
|
|
|
2016-07-28 06:50:48 -04:00
|
|
|
double wait = csi.NextCheck - Utility::GetTime();
|
2013-02-11 07:05:08 -05:00
|
|
|
|
2019-04-15 10:56:30 -04:00
|
|
|
//#ifdef I2_DEBUG
|
|
|
|
|
// Log(LogDebug, "CheckerComponent")
|
|
|
|
|
// << "Pending checks " << Checkable::GetPendingChecks()
|
|
|
|
|
// << " vs. max concurrent checks " << icingaApp->GetMaxConcurrentChecks() << ".";
|
|
|
|
|
//#endif /* I2_DEBUG */
|
|
|
|
|
|
|
|
|
|
if (Checkable::GetPendingChecks() >= icingaApp->GetMaxConcurrentChecks())
|
2016-05-18 08:30:36 -04:00
|
|
|
wait = 0.5;
|
|
|
|
|
|
|
|
|
|
if (wait > 0) {
|
2013-02-18 08:40:24 -05:00
|
|
|
/* Wait for the next check. */
|
2021-02-02 04:16:04 -05:00
|
|
|
m_CV.wait_for(lock, std::chrono::duration<double>(wait));
|
2013-02-18 08:40:24 -05:00
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-28 06:50:48 -04:00
|
|
|
Checkable::Ptr checkable = csi.Object;
|
|
|
|
|
|
2014-04-05 13:02:45 -04:00
|
|
|
m_IdleCheckables.erase(checkable);
|
2012-06-17 16:46:40 -04:00
|
|
|
|
2014-04-05 13:02:45 -04:00
|
|
|
bool forced = checkable->GetForceNextCheck();
|
2013-03-13 11:04:53 -04:00
|
|
|
bool check = true;
|
2023-02-01 10:25:56 -05:00
|
|
|
bool notifyNextCheck = false;
|
2025-05-14 06:44:48 -04:00
|
|
|
double nextCheck = -1;
|
2013-09-12 04:03:48 -04:00
|
|
|
|
2013-09-10 03:26:46 -04:00
|
|
|
if (!forced) {
|
2014-04-05 13:02:45 -04:00
|
|
|
if (!checkable->IsReachable(DependencyCheckExecution)) {
|
2014-10-20 04:09:57 -04:00
|
|
|
Log(LogNotice, "CheckerComponent")
|
2017-12-19 09:50:05 -05:00
|
|
|
<< "Skipping check for object '" << checkable->GetName() << "': Dependency failed.";
|
2023-02-01 10:25:56 -05:00
|
|
|
|
2014-02-27 05:05:55 -05:00
|
|
|
check = false;
|
2023-02-01 10:25:56 -05:00
|
|
|
notifyNextCheck = true;
|
2014-02-27 05:05:55 -05:00
|
|
|
}
|
|
|
|
|
|
2014-04-17 05:29:47 -04:00
|
|
|
Host::Ptr host;
|
|
|
|
|
Service::Ptr service;
|
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
|
2019-04-15 10:56:30 -04:00
|
|
|
if (host && !service && (!checkable->GetEnableActiveChecks() || !icingaApp->GetEnableHostChecks())) {
|
2014-10-20 04:09:57 -04:00
|
|
|
Log(LogNotice, "CheckerComponent")
|
2017-12-19 09:50:05 -05:00
|
|
|
<< "Skipping check for host '" << host->GetName() << "': active host checks are disabled";
|
2014-04-17 05:29:47 -04:00
|
|
|
check = false;
|
|
|
|
|
}
|
2019-04-15 10:56:30 -04:00
|
|
|
if (host && service && (!checkable->GetEnableActiveChecks() || !icingaApp->GetEnableServiceChecks())) {
|
2014-10-20 04:09:57 -04:00
|
|
|
Log(LogNotice, "CheckerComponent")
|
2017-12-19 09:50:05 -05:00
|
|
|
<< "Skipping check for service '" << service->GetName() << "': active service checks are disabled";
|
2013-03-13 11:04:53 -04:00
|
|
|
check = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-05 13:02:45 -04:00
|
|
|
TimePeriod::Ptr tp = checkable->GetCheckPeriod();
|
2013-03-13 11:04:53 -04:00
|
|
|
|
2025-05-14 06:44:48 -04:00
|
|
|
if (tp) {
|
|
|
|
|
auto ts (Utility::GetTime());
|
|
|
|
|
ObjectLock oLock (tp);
|
2023-02-01 10:25:56 -05:00
|
|
|
|
2025-05-14 06:44:48 -04:00
|
|
|
if (!tp->IsInside(ts)) {
|
|
|
|
|
nextCheck = tp->FindNextTransition(ts);
|
|
|
|
|
|
|
|
|
|
if (nextCheck <= 0) {
|
|
|
|
|
nextCheck = tp->GetValidEnd();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log(LogNotice, "CheckerComponent")
|
|
|
|
|
<< "Skipping check for object '" << checkable->GetName()
|
|
|
|
|
<< "', as not in check period '" << tp->GetName() << "', until "
|
|
|
|
|
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", nextCheck);
|
|
|
|
|
|
|
|
|
|
check = false;
|
|
|
|
|
notifyNextCheck = true;
|
|
|
|
|
}
|
2013-03-13 11:04:53 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-05 13:02:45 -04:00
|
|
|
/* reschedule the checkable if checks are disabled */
|
2013-03-13 11:04:53 -04:00
|
|
|
if (!check) {
|
2016-07-28 06:50:48 -04:00
|
|
|
m_IdleCheckables.insert(GetCheckableScheduleInfo(checkable));
|
2013-11-28 14:55:10 -05:00
|
|
|
lock.unlock();
|
|
|
|
|
|
2025-05-14 06:44:48 -04:00
|
|
|
if (nextCheck > 0) {
|
|
|
|
|
checkable->SetNextCheck(nextCheck);
|
|
|
|
|
} else {
|
|
|
|
|
Log(LogDebug, "CheckerComponent")
|
|
|
|
|
<< "Checks for checkable '" << checkable->GetName() << "' are disabled. Rescheduling check.";
|
2018-07-02 10:17:33 -04:00
|
|
|
|
2025-05-14 06:44:48 -04:00
|
|
|
checkable->UpdateNextCheck();
|
|
|
|
|
}
|
2013-01-22 10:01:08 -05:00
|
|
|
|
2023-02-01 10:25:56 -05:00
|
|
|
if (notifyNextCheck) {
|
|
|
|
|
// Trigger update event for Icinga DB
|
|
|
|
|
Checkable::OnNextCheckUpdated(checkable);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-28 14:55:10 -05:00
|
|
|
lock.lock();
|
2013-01-22 10:01:08 -05:00
|
|
|
|
2013-03-02 03:07:47 -05:00
|
|
|
continue;
|
2013-01-22 10:01:08 -05:00
|
|
|
}
|
|
|
|
|
|
2018-07-02 10:17:33 -04:00
|
|
|
|
|
|
|
|
csi = GetCheckableScheduleInfo(checkable);
|
|
|
|
|
|
|
|
|
|
Log(LogDebug, "CheckerComponent")
|
|
|
|
|
<< "Scheduling info for checkable '" << checkable->GetName() << "' ("
|
|
|
|
|
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", checkable->GetNextCheck()) << "): Object '"
|
|
|
|
|
<< csi.Object->GetName() << "', Next Check: "
|
2025-02-26 10:36:57 -05:00
|
|
|
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", csi.NextCheck)
|
|
|
|
|
<< " (" << std::fixed << std::setprecision(0) << csi.NextCheck << ").";
|
2018-07-02 10:17:33 -04:00
|
|
|
|
|
|
|
|
m_PendingCheckables.insert(csi);
|
2013-03-06 07:01:51 -05:00
|
|
|
|
|
|
|
|
lock.unlock();
|
|
|
|
|
|
2013-09-10 03:26:46 -04:00
|
|
|
if (forced) {
|
2014-04-05 13:02:45 -04:00
|
|
|
ObjectLock olock(checkable);
|
|
|
|
|
checkable->SetForceNextCheck(false);
|
2013-03-04 09:52:42 -05:00
|
|
|
}
|
2013-01-23 09:25:00 -05:00
|
|
|
|
2014-10-20 04:09:57 -04:00
|
|
|
Log(LogDebug, "CheckerComponent")
|
2017-12-19 09:50:05 -05:00
|
|
|
<< "Executing check for '" << checkable->GetName() << "'";
|
2012-06-17 14:35:56 -04:00
|
|
|
|
2016-08-29 08:12:29 -04:00
|
|
|
Checkable::IncreasePendingChecks();
|
|
|
|
|
|
2021-01-18 08:29:05 -05:00
|
|
|
/*
|
|
|
|
|
* Explicitly use CheckerComponent::Ptr to keep the reference counted while the
|
|
|
|
|
* callback is active and making it crash safe
|
|
|
|
|
*/
|
|
|
|
|
CheckerComponent::Ptr checkComponent(this);
|
|
|
|
|
|
|
|
|
|
Utility::QueueAsyncCallback([this, checkComponent, checkable]() { ExecuteCheckHelper(checkable); });
|
2013-03-06 07:01:51 -05:00
|
|
|
|
|
|
|
|
lock.lock();
|
2012-10-15 02:52:31 -04:00
|
|
|
}
|
2012-06-14 05:23:25 -04:00
|
|
|
}
|
|
|
|
|
|
2014-04-05 13:02:45 -04:00
|
|
|
void CheckerComponent::ExecuteCheckHelper(const Checkable::Ptr& checkable)
|
2012-06-17 14:35:56 -04:00
|
|
|
{
|
2013-03-25 13:36:15 -04:00
|
|
|
try {
|
2025-05-22 11:56:16 -04:00
|
|
|
checkable->ExecuteCheck(m_WaitGroup);
|
2013-03-25 13:36:15 -04:00
|
|
|
} catch (const std::exception& ex) {
|
2014-11-08 15:17:16 -05:00
|
|
|
CheckResult::Ptr cr = new CheckResult();
|
2014-04-22 13:02:45 -04:00
|
|
|
cr->SetState(ServiceUnknown);
|
|
|
|
|
|
2018-07-21 04:38:09 -04:00
|
|
|
String output = "Exception occurred while checking '" + checkable->GetName() + "': " + DiagnosticInformation(ex);
|
2014-04-22 13:02:45 -04:00
|
|
|
cr->SetOutput(output);
|
|
|
|
|
|
|
|
|
|
double now = Utility::GetTime();
|
|
|
|
|
cr->SetScheduleStart(now);
|
|
|
|
|
cr->SetScheduleEnd(now);
|
|
|
|
|
cr->SetExecutionStart(now);
|
|
|
|
|
cr->SetExecutionEnd(now);
|
|
|
|
|
|
2025-05-22 11:56:16 -04:00
|
|
|
checkable->ProcessCheckResult(cr, m_WaitGroup);
|
2014-04-22 13:02:45 -04:00
|
|
|
|
|
|
|
|
Log(LogCritical, "checker", output);
|
2013-03-25 13:36:15 -04:00
|
|
|
}
|
2016-05-12 07:46:22 -04:00
|
|
|
|
2016-08-29 08:12:29 -04:00
|
|
|
Checkable::DecreasePendingChecks();
|
|
|
|
|
|
2016-05-12 07:46:22 -04:00
|
|
|
{
|
2021-02-02 04:16:04 -05:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2016-05-12 07:46:22 -04:00
|
|
|
|
|
|
|
|
/* remove the object from the list of pending objects; if it's not in the
|
|
|
|
|
* list this was a manual (i.e. forced) check and we must not re-add the
|
|
|
|
|
* object to the list because it's already there. */
|
2016-08-27 13:56:12 -04:00
|
|
|
auto it = m_PendingCheckables.find(checkable);
|
|
|
|
|
|
2016-05-12 07:46:22 -04:00
|
|
|
if (it != m_PendingCheckables.end()) {
|
|
|
|
|
m_PendingCheckables.erase(it);
|
|
|
|
|
|
|
|
|
|
if (checkable->IsActive())
|
2016-07-28 06:50:48 -04:00
|
|
|
m_IdleCheckables.insert(GetCheckableScheduleInfo(checkable));
|
2016-05-12 07:46:22 -04:00
|
|
|
|
|
|
|
|
m_CV.notify_all();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log(LogDebug, "CheckerComponent")
|
2017-12-19 09:50:05 -05:00
|
|
|
<< "Check finished for object '" << checkable->GetName() << "'";
|
2012-07-13 15:00:54 -04:00
|
|
|
}
|
2012-06-20 09:23:31 -04:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
void CheckerComponent::ResultTimerHandler()
|
2012-07-13 15:00:54 -04:00
|
|
|
{
|
2013-03-16 16:18:53 -04:00
|
|
|
std::ostringstream msgbuf;
|
2013-02-17 13:14:34 -05:00
|
|
|
|
|
|
|
|
{
|
2021-02-02 04:16:04 -05:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2013-02-17 13:14:34 -05:00
|
|
|
|
2014-05-26 14:56:34 -04:00
|
|
|
msgbuf << "Pending checkables: " << m_PendingCheckables.size() << "; Idle checkables: " << m_IdleCheckables.size() << "; Checks/s: "
|
2017-12-19 09:50:05 -05:00
|
|
|
<< (CIB::GetActiveHostChecksStatistics(60) + CIB::GetActiveServiceChecksStatistics(60)) / 60.0;
|
2013-02-17 13:14:34 -05:00
|
|
|
}
|
|
|
|
|
|
2014-05-28 07:03:44 -04:00
|
|
|
Log(LogNotice, "CheckerComponent", msgbuf.str());
|
2012-06-17 14:35:56 -04:00
|
|
|
}
|
|
|
|
|
|
2015-08-15 14:28:05 -04:00
|
|
|
void CheckerComponent::ObjectHandler(const ConfigObject::Ptr& object)
|
2012-06-14 05:23:25 -04:00
|
|
|
{
|
2015-03-20 03:15:07 -04:00
|
|
|
Checkable::Ptr checkable = dynamic_pointer_cast<Checkable>(object);
|
2013-02-21 10:12:50 -05:00
|
|
|
|
2015-03-20 03:15:07 -04:00
|
|
|
if (!checkable)
|
|
|
|
|
return;
|
2013-08-20 05:06:04 -04:00
|
|
|
|
2015-02-09 02:50:17 -05:00
|
|
|
Zone::Ptr zone = Zone::GetByName(checkable->GetZoneName());
|
2014-05-03 14:02:22 -04:00
|
|
|
bool same_zone = (!zone || Zone::GetLocalZone() == zone);
|
|
|
|
|
|
2013-08-20 05:06:04 -04:00
|
|
|
{
|
2021-02-02 04:16:04 -05:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2012-06-14 10:09:04 -04:00
|
|
|
|
2014-05-09 05:32:24 -04:00
|
|
|
if (object->IsActive() && !object->IsPaused() && same_zone) {
|
2014-04-05 13:02:45 -04:00
|
|
|
if (m_PendingCheckables.find(checkable) != m_PendingCheckables.end())
|
2013-09-13 01:49:12 -04:00
|
|
|
return;
|
2012-06-14 10:09:04 -04:00
|
|
|
|
2016-07-28 06:50:48 -04:00
|
|
|
m_IdleCheckables.insert(GetCheckableScheduleInfo(checkable));
|
2013-09-13 01:49:12 -04:00
|
|
|
} else {
|
2014-04-05 13:02:45 -04:00
|
|
|
m_IdleCheckables.erase(checkable);
|
|
|
|
|
m_PendingCheckables.erase(checkable);
|
2013-09-13 01:49:12 -04:00
|
|
|
}
|
2013-08-20 05:06:04 -04:00
|
|
|
|
2013-02-18 08:40:24 -05:00
|
|
|
m_CV.notify_all();
|
2012-07-17 06:57:21 -04:00
|
|
|
}
|
2012-06-14 05:23:25 -04:00
|
|
|
}
|
|
|
|
|
|
2016-07-28 06:50:48 -04:00
|
|
|
CheckableScheduleInfo CheckerComponent::GetCheckableScheduleInfo(const Checkable::Ptr& checkable)
|
|
|
|
|
{
|
|
|
|
|
CheckableScheduleInfo csi;
|
|
|
|
|
csi.Object = checkable;
|
|
|
|
|
csi.NextCheck = checkable->GetNextCheck();
|
|
|
|
|
return csi;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-05 13:02:45 -04:00
|
|
|
void CheckerComponent::NextCheckChangedHandler(const Checkable::Ptr& checkable)
|
2013-01-22 06:44:23 -05:00
|
|
|
{
|
2021-02-02 04:16:04 -05:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2013-02-21 10:12:50 -05:00
|
|
|
|
2014-04-05 13:02:45 -04:00
|
|
|
/* remove and re-insert the object from the set in order to force an index update */
|
2014-04-03 09:36:13 -04:00
|
|
|
typedef boost::multi_index::nth_index<CheckableSet, 0>::type CheckableView;
|
|
|
|
|
CheckableView& idx = boost::get<0>(m_IdleCheckables);
|
2013-02-17 13:14:34 -05:00
|
|
|
|
2016-08-27 13:56:12 -04:00
|
|
|
auto it = idx.find(checkable);
|
|
|
|
|
|
2013-02-21 10:12:50 -05:00
|
|
|
if (it == idx.end())
|
|
|
|
|
return;
|
2013-01-22 06:44:23 -05:00
|
|
|
|
2014-04-05 13:02:45 -04:00
|
|
|
idx.erase(checkable);
|
2016-07-28 06:50:48 -04:00
|
|
|
|
|
|
|
|
CheckableScheduleInfo csi = GetCheckableScheduleInfo(checkable);
|
|
|
|
|
idx.insert(csi);
|
|
|
|
|
|
2013-02-21 10:12:50 -05:00
|
|
|
m_CV.notify_all();
|
2013-01-22 06:44:23 -05:00
|
|
|
}
|
2014-02-18 04:53:44 -05:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
unsigned long CheckerComponent::GetIdleCheckables()
|
2014-02-18 04:53:44 -05:00
|
|
|
{
|
2021-02-02 04:16:04 -05:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2014-02-18 04:53:44 -05:00
|
|
|
|
2014-04-03 09:36:13 -04:00
|
|
|
return m_IdleCheckables.size();
|
2014-02-18 04:53:44 -05:00
|
|
|
}
|
|
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
unsigned long CheckerComponent::GetPendingCheckables()
|
2014-02-18 04:53:44 -05:00
|
|
|
{
|
2021-02-02 04:16:04 -05:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2014-02-18 04:53:44 -05:00
|
|
|
|
2014-04-03 09:36:13 -04:00
|
|
|
return m_PendingCheckables.size();
|
2014-02-18 04:53:44 -05:00
|
|
|
}
|