]> granicus.if.org Git - icinga2/commitdiff
Use boost::multi_index instead of a priority queue.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sat, 4 Aug 2012 11:49:25 +0000 (13:49 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sat, 4 Aug 2012 11:49:25 +0000 (13:49 +0200)
components/checker/checkercomponent.cpp
components/checker/checkercomponent.h
components/checker/i2-checker.h

index 4adbda657e414ce6ee0e8e8f30a3a45fa7596f47..6b4ab546eec5379299b9854352b2e4498f25a9ec 100644 (file)
@@ -59,14 +59,17 @@ void CheckerComponent::CheckTimerHandler(void)
        double now = Utility::GetTime();
        long tasks = 0;
 
-       while (!m_Services.empty()) {
-               CheckerComponent::ServiceMultiSet::iterator it = m_Services.begin();
+       while (!m_IdleServices.empty()) {
+               typedef nth_index<ServiceSet, 1>::type CheckTimeView;
+               CheckTimeView& idx = boost::get<1>(m_IdleServices);
+
+               CheckTimeView::iterator it = idx.begin();
                Service::Ptr service = *it;
 
                if (service->GetNextCheck() > now)
                        break;
 
-               m_Services.erase(it);
+               idx.erase(it);
 
                Logger::Write(LogDebug, "checker", "Executing service check for '" + service->GetName() + "'");
 
@@ -130,11 +133,11 @@ void CheckerComponent::CheckCompletedHandler(const Service::Ptr& service, const
        /* remove the service from the list of pending services; if it's not in the
         * list this was a manual (i.e. forced) check and we must not re-add the
         * service to the services list because it's already there. */
-       CheckerComponent::ServiceMultiSet::iterator it;
+       CheckerComponent::ServiceSet::iterator it;
        it = m_PendingServices.find(service);
        if (it != m_PendingServices.end()) {
                m_PendingServices.erase(it);
-               m_Services.insert(service);
+               m_IdleServices.insert(service);
        }
 
        Logger::Write(LogDebug, "checker", "Check finished for service '" + service->GetName() + "'");
@@ -145,7 +148,7 @@ void CheckerComponent::ResultTimerHandler(void)
        Logger::Write(LogDebug, "checker", "ResultTimerHandler entered.");
 
        stringstream msgbuf;
-       msgbuf << "Pending services: " << m_PendingServices.size() << "; Idle services: " << m_Services.size();
+       msgbuf << "Pending services: " << m_PendingServices.size() << "; Idle services: " << m_IdleServices.size();
        Logger::Write(LogInformation, "checker", msgbuf.str());
 }
 
@@ -159,9 +162,9 @@ void CheckerComponent::CheckerChangedHandler(const Service::Ptr& service)
 
                service->UpdateNextCheck();
 
-               m_Services.insert(service);
+               m_IdleServices.insert(service);
        } else {
-               m_Services.erase(service);
+               m_IdleServices.erase(service);
                m_PendingServices.erase(service);
        }
 }
@@ -174,7 +177,7 @@ void CheckerComponent::ServiceRemovedHandler(const DynamicObject::Ptr& object)
        if (!service)
                return;
 
-       m_Services.erase(service);
+       m_IdleServices.erase(service);
        m_PendingServices.erase(service);
 }
 
index d5b18c464ee1560968d0820541744840613de0fa..8e59f61317c6f4a603c7e9f1f576997c871368bc 100644 (file)
 namespace icinga
 {
 
-struct ServiceNextCheckLessComparer
+struct ServiceNextCheckExtractor
 {
-public:
-       bool operator()(const Service::Ptr& a, const Service::Ptr& b)
+       typedef double result_type;
+
+       double operator()(const Service::Ptr& service)
        {
-               return a->GetNextCheck() > b->GetNextCheck();
+               return service->GetNextCheck();
        }
 };
 
@@ -41,7 +42,13 @@ public:
        typedef shared_ptr<CheckerComponent> Ptr;
        typedef weak_ptr<CheckerComponent> WeakPtr;
 
-       typedef multiset<Service::Ptr, ServiceNextCheckLessComparer> ServiceMultiSet;
+       typedef multi_index_container<
+               Service::Ptr,
+               indexed_by<
+                       ordered_unique<identity<Service::Ptr> >,
+                       ordered_non_unique<ServiceNextCheckExtractor>
+               >
+       > ServiceSet;
 
        virtual void Start(void);
        virtual void Stop(void);
@@ -49,8 +56,8 @@ public:
 private:
        VirtualEndpoint::Ptr m_Endpoint;
 
-       ServiceMultiSet m_Services;
-       ServiceMultiSet m_PendingServices;
+       ServiceSet m_IdleServices;
+       ServiceSet m_PendingServices;
 
        Timer::Ptr m_CheckTimer;
 
index b142c84d6a303dc4dac4fbb6073558c324df4ffa..4cb465d99ebf918b11b0139465f99727c92d715e 100644 (file)
 #include <i2-icinga.h>
 #include <i2-cib.h>
 
-#include <queue>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+#include <boost/multi_index/key_extractors.hpp>
 
-using std::priority_queue;
+using boost::multi_index_container;
+using boost::multi_index::indexed_by;
+using boost::multi_index::identity;
+using boost::multi_index::ordered_unique;
+using boost::multi_index::ordered_non_unique;
+using boost::multi_index::nth_index;
 
 #include "checkercomponent.h"