]> granicus.if.org Git - icinga2/commitdiff
Discard unnamed config items as early as possible
authorGunnar Beutner <gunnar.beutner@netways.de>
Sun, 9 Nov 2014 03:17:34 +0000 (04:17 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sun, 9 Nov 2014 03:17:34 +0000 (04:17 +0100)
lib/config/configitem.cpp
lib/config/configitem.hpp

index c39c828ce7d9ec853d2c2d7e617c2f709bc4ef5d..cf287933d362774f98eab222fc9702e076537e7a 100644 (file)
@@ -43,6 +43,7 @@ using namespace icinga;
 
 boost::mutex ConfigItem::m_Mutex;
 ConfigItem::ItemMap ConfigItem::m_Items;
+ConfigItem::ItemList ConfigItem::m_UnnamedItems;
 
 /**
  * Constructor for the ConfigItem class.
@@ -229,29 +230,19 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard)
  */
 void ConfigItem::Register(void)
 {
-       String name = m_Name;
-
-       /* If this is a non-abstract object we need to figure out
-        * its real name now - or assign it a temporary name. */
-       if (!m_Abstract) {
-               shared_ptr<NameComposer> nc = dynamic_pointer_cast<NameComposer>(Type::GetByName(m_Type));
-
-               if (nc) {
-                       name = nc->MakeName(m_Name, Dictionary::Ptr());
-
-                       ASSERT(name.IsEmpty() || name == m_Name);
-
-                       if (name.IsEmpty())
-                               name = Utility::NewUniqueID();
-               }
-       }
-
-       std::pair<String, String> key = std::make_pair(m_Type, name);
        ConfigItem::Ptr self = GetSelf();
 
-       boost::mutex::scoped_lock lock(m_Mutex);
+       /* If this is a non-abstract object with a composite name
+        * we register it in m_UnnamedItems instead of m_Items. */
+       if (!m_Abstract && dynamic_pointer_cast<NameComposer>(Type::GetByName(m_Type))) {
+               boost::mutex::scoped_lock lock(m_Mutex);
+               m_UnnamedItems.push_back(self);
+       } else {
+               std::pair<String, String> key = std::make_pair(m_Type, m_Name);
 
-       m_Items[key] = self;
+               boost::mutex::scoped_lock lock(m_Mutex);
+               m_Items[key] = self;
+       }
 }
 
 /**
@@ -291,6 +282,10 @@ bool ConfigItem::ValidateItems(void)
                upq.Enqueue(boost::bind(&ConfigItem::Commit, kv.second, false));
        }
 
+       BOOST_FOREACH(const ConfigItem::Ptr& item, m_UnnamedItems) {
+               upq.Enqueue(boost::bind(&ConfigItem::Commit, item, true));
+       }
+
        upq.Join();
 
        std::vector<DynamicObject::Ptr> objects;
@@ -301,6 +296,15 @@ bool ConfigItem::ValidateItems(void)
                        objects.push_back(object);
        }
 
+       BOOST_FOREACH(const ConfigItem::Ptr& item, m_UnnamedItems) {
+               DynamicObject::Ptr object = item->m_Object;
+
+               if (object)
+                       objects.push_back(object);
+       }
+
+       m_UnnamedItems.clear();
+
        Log(LogInformation, "ConfigItem", "Triggering OnConfigLoaded signal for config items");
 
        BOOST_FOREACH(const DynamicObject::Ptr& object, objects) {
index 2c5e5ab2752a027bfe514c8e9f296ab68cf694e5..ea6bd6d0632f2fa717ac7b619fc3dab14f382654 100644 (file)
@@ -84,6 +84,9 @@ private:
        typedef std::map<std::pair<String, String>, ConfigItem::Ptr> ItemMap;
        static ItemMap m_Items; /**< All registered configuration items. */
 
+       typedef std::vector<ConfigItem::Ptr> ItemList;
+       static ItemList m_UnnamedItems;
+
        static ConfigItem::Ptr GetObjectUnlocked(const String& type,
            const String& name);
 };