mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-22 21:24:41 +02:00
parent
cffe3cf57c
commit
7310a254e8
@ -29,6 +29,7 @@
|
|||||||
#include "base/scriptfunction.h"
|
#include "base/scriptfunction.h"
|
||||||
#include "base/initialize.h"
|
#include "base/initialize.h"
|
||||||
#include "base/scriptvariable.h"
|
#include "base/scriptvariable.h"
|
||||||
|
#include "base/workqueue.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/exception/errinfo_api_function.hpp>
|
#include <boost/exception/errinfo_api_function.hpp>
|
||||||
@ -277,6 +278,33 @@ void DynamicObject::DumpObjects(const String& filename, int attributeTypes)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DynamicObject::RestoreObject(const String& message, int attributeTypes)
|
||||||
|
{
|
||||||
|
Dictionary::Ptr persistentObject = JsonDeserialize(message);
|
||||||
|
|
||||||
|
String type = persistentObject->Get("type");
|
||||||
|
|
||||||
|
DynamicType::Ptr dt = DynamicType::GetByName(type);
|
||||||
|
|
||||||
|
if (!dt)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String name = persistentObject->Get("name");
|
||||||
|
|
||||||
|
DynamicObject::Ptr object = dt->GetObject(name);
|
||||||
|
|
||||||
|
if (!object)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ASSERT(!object->IsActive());
|
||||||
|
#ifdef _DEBUG
|
||||||
|
Log(LogDebug, "base", "Restoring object '" + name + "' of type '" + type + "'.");
|
||||||
|
#endif /* _DEBUG */
|
||||||
|
Dictionary::Ptr update = persistentObject->Get("update");
|
||||||
|
Deserialize(object, update, false, attributeTypes);
|
||||||
|
object->OnStateLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
void DynamicObject::RestoreObjects(const String& filename, int attributeTypes)
|
void DynamicObject::RestoreObjects(const String& filename, int attributeTypes)
|
||||||
{
|
{
|
||||||
Log(LogInformation, "base", "Restoring program state from file '" + filename + "'");
|
Log(LogInformation, "base", "Restoring program state from file '" + filename + "'");
|
||||||
@ -288,35 +316,18 @@ void DynamicObject::RestoreObjects(const String& filename, int attributeTypes)
|
|||||||
|
|
||||||
unsigned long restored = 0;
|
unsigned long restored = 0;
|
||||||
|
|
||||||
|
ParallelWorkQueue upq;
|
||||||
|
|
||||||
String message;
|
String message;
|
||||||
while (NetString::ReadStringFromStream(sfp, &message)) {
|
while (NetString::ReadStringFromStream(sfp, &message)) {
|
||||||
Dictionary::Ptr persistentObject = JsonDeserialize(message);
|
upq.Enqueue(boost::bind(&DynamicObject::RestoreObject, message, attributeTypes));
|
||||||
|
|
||||||
String type = persistentObject->Get("type");
|
|
||||||
String name = persistentObject->Get("name");
|
|
||||||
Dictionary::Ptr update = persistentObject->Get("update");
|
|
||||||
|
|
||||||
DynamicType::Ptr dt = DynamicType::GetByName(type);
|
|
||||||
|
|
||||||
if (!dt)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
DynamicObject::Ptr object = dt->GetObject(name);
|
|
||||||
|
|
||||||
if (object) {
|
|
||||||
ASSERT(!object->IsActive());
|
|
||||||
#ifdef _DEBUG
|
|
||||||
Log(LogDebug, "base", "Restoring object '" + name + "' of type '" + type + "'.");
|
|
||||||
#endif /* _DEBUG */
|
|
||||||
Deserialize(object, update, false, attributeTypes);
|
|
||||||
object->OnStateLoaded();
|
|
||||||
}
|
|
||||||
|
|
||||||
restored++;
|
restored++;
|
||||||
}
|
}
|
||||||
|
|
||||||
sfp->Close();
|
sfp->Close();
|
||||||
|
|
||||||
|
upq.Join();
|
||||||
|
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
msgbuf << "Restored " << restored << " objects";
|
msgbuf << "Restored " << restored << " objects";
|
||||||
Log(LogInformation, "base", msgbuf.str());
|
Log(LogInformation, "base", msgbuf.str());
|
||||||
|
@ -125,6 +125,7 @@ private:
|
|||||||
std::map<String, int> m_Privileges;
|
std::map<String, int> m_Privileges;
|
||||||
|
|
||||||
static DynamicObject::Ptr GetObject(const String& type, const String& name);
|
static DynamicObject::Ptr GetObject(const String& type, const String& name);
|
||||||
|
static void RestoreObject(const String& message, int attributeTypes);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DECLARE_TYPENAME(klass) \
|
#define DECLARE_TYPENAME(klass) \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user