From 543c2d4044922719aac3e1e5ce3a9d335ae7db21 Mon Sep 17 00:00:00 2001 From: Arpad Boda Date: Fri, 31 Jan 2020 09:46:48 +0100 Subject: [PATCH] Review comments #2 --- libminifi/include/SchedulingAgent.h | 22 ++++++---------------- libminifi/src/SchedulingAgent.cpp | 2 +- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/libminifi/include/SchedulingAgent.h b/libminifi/include/SchedulingAgent.h index dabd2336013..46667b4bb8e 100644 --- a/libminifi/include/SchedulingAgent.h +++ b/libminifi/include/SchedulingAgent.h @@ -141,10 +141,6 @@ class SchedulingAgent { watchDogTimer_.reset(new utils::CallBackTimer(std::chrono::milliseconds(SCHEDULING_WATCHDOG_CHECK_PERIOD), f)); watchDogTimer_->start(); } - // Destructor - virtual ~SchedulingAgent() { - watchDogTimer_->stop(); - } // onTrigger, return whether the yield is need bool onTrigger(const std::shared_ptr &processor, const std::shared_ptr &processContext, const std::shared_ptr &sessionFactory); @@ -202,15 +198,13 @@ class SchedulingAgent { private: struct SchedulingInfo { - std::chrono::time_point start_time_; + std::chrono::time_point start_time_ = std::chrono::steady_clock::now(); std::string name_; std::string uuid_; - SchedulingInfo(const std::shared_ptr &processor) { - start_time_ = std::chrono::steady_clock::now(); - name_ = processor->getName(); - uuid_ = processor->getUUIDStr(); - } + explicit SchedulingInfo(const std::shared_ptr &processor) : + name_(processor->getName()), + uuid_(processor->getUUIDStr()) {} bool operator <(const SchedulingInfo& o) const { return std::tie(start_time_, name_, uuid_) < std::tie(o.start_time_, o.name_, o.uuid_); @@ -219,13 +213,9 @@ class SchedulingAgent { // Logger std::shared_ptr logger_; - std::mutex watchdog_mtx_; // used to protect the vector below - std::set scheduled_processors_; + std::mutex watchdog_mtx_; // used to protect the set below + std::set scheduled_processors_; // set was chosen to avoid iterator invalidation std::unique_ptr watchDogTimer_; - - // Prevent default copy constructor and assignment operation - // Only support pass by reference or pointer - }; } /* namespace minifi */ diff --git a/libminifi/src/SchedulingAgent.cpp b/libminifi/src/SchedulingAgent.cpp index be36f713447..4bd6db2d32c 100644 --- a/libminifi/src/SchedulingAgent.cpp +++ b/libminifi/src/SchedulingAgent.cpp @@ -144,7 +144,7 @@ void SchedulingAgent::watchDogFunc() { for (const auto& info : scheduled_processors_) { int64_t elapsed = std::chrono::duration_cast(now - info.start_time_).count(); if (elapsed > SCHEDULING_WATCHDOG_ALERT_PERIOD) { - logger_->log_warn("%s::onTrigger is running for %lld ms in %s", info.name_, elapsed, info.uuid_); + logger_->log_warn("%s::onTrigger has been running for %lld ms in %s", info.name_, elapsed, info.uuid_); } } }