int Application::m_ArgC;
char **Application::m_ArgV;
double Application::m_StartTime;
+double Application::m_MainTime;
bool Application::m_ScriptDebuggerEnabled = false;
/**
return EXIT_FAILURE;
}
+ SetMainTime(Utility::GetTime());
+
return Main();
}
m_StartTime = ts;
}
+double Application::GetMainTime(void)
+{
+ return m_MainTime;
+}
+
+void Application::SetMainTime(double ts)
+{
+ m_MainTime = ts;
+}
+
bool Application::GetScriptDebuggerEnabled(void)
{
return m_ScriptDebuggerEnabled;
static double GetStartTime(void);
static void SetStartTime(double ts);
+ static double GetMainTime(void);
+ static void SetMainTime(double ts);
+
static bool GetScriptDebuggerEnabled(void);
static void SetScriptDebuggerEnabled(bool enabled);
static bool m_Debugging; /**< Whether debugging is enabled. */
static LogSeverity m_DebuggingSeverity; /**< Whether debugging severity is set. */
static double m_StartTime;
+ static double m_MainTime;
static bool m_ScriptDebuggerEnabled;
#ifndef _WIN32
#include "cli/daemoncommand.hpp"
#include "cli/daemonutility.hpp"
+#include "remote/apilistener.hpp"
#include "config/configcompiler.hpp"
#include "config/configcompilercontext.hpp"
#include "config/configitembuilder.hpp"
sigaction(SIGHUP, &sa, NULL);
#endif /* _WIN32 */
+ /* update object authority */
+ ApiListener::UpdateObjectAuthorityAsync();
+
return Application::GetInstance()->Run();
}
static void AuthorityTimerHandler(void)
{
- ApiListener::Ptr listener = ApiListener::GetInstance();
+ Zone::Ptr my_zone = Zone::GetLocalZone();
- if (!listener || !listener->IsActive())
- return;
+ std::vector<Endpoint::Ptr> endpoints;
+ Endpoint::Ptr my_endpoint;
- Zone::Ptr my_zone = Zone::GetLocalZone();
- if (!my_zone)
- return;
+ if (my_zone) {
+ my_endpoint = Endpoint::GetLocalEndpoint();
- Endpoint::Ptr my_endpoint = Endpoint::GetLocalEndpoint();
+ int num_total = 0;
- std::vector<Endpoint::Ptr> endpoints;
- BOOST_FOREACH(const Endpoint::Ptr& endpoint, my_zone->GetEndpoints()) {
- if (!endpoint->GetConnected() && endpoint != my_endpoint)
- continue;
+ BOOST_FOREACH(const Endpoint::Ptr& endpoint, my_zone->GetEndpoints()) {
+ num_total++;
- endpoints.push_back(endpoint);
- }
+ if (endpoint != my_endpoint && !endpoint->GetConnected())
+ continue;
+
+ endpoints.push_back(endpoint);
+ }
+
+ double mainTime = Application::GetMainTime();
- std::sort(endpoints.begin(), endpoints.end(), ObjectNameLessComparer);
+ if (num_total > 1 && endpoints.size() <= 1 && (mainTime == 0 || Utility::GetTime() - mainTime < 60))
+ return;
+
+ std::sort(endpoints.begin(), endpoints.end(), ObjectNameLessComparer);
+ }
BOOST_FOREACH(const ConfigType::Ptr& type, ConfigType::GetTypes()) {
BOOST_FOREACH(const ConfigObject::Ptr& object, type->GetObjects()) {
- Endpoint::Ptr endpoint = endpoints[Utility::SDBM(object->GetName()) % endpoints.size()];
+ if (object->GetHAMode() != HARunOnce)
+ continue;
+
+ bool authority;
+
+ if (!my_zone)
+ authority = true;
+ else
+ authority = endpoints[Utility::SDBM(object->GetName()) % endpoints.size()] == my_endpoint;
- if (object->GetHAMode() == HARunOnce)
- object->SetAuthority(endpoint == my_endpoint);
+ object->SetAuthority(authority);
}
}
}
+void ApiListener::UpdateObjectAuthorityAsync(void)
+{
+ l_AuthorityTimer->Reschedule(0);
+}
+
static void StaticInitialize(void)
{
l_AuthorityTimer = new Timer();
l_AuthorityTimer->OnTimerExpired.connect(boost::bind(&AuthorityTimerHandler));
- l_AuthorityTimer->SetInterval(30);
+ l_AuthorityTimer->SetInterval(15);
l_AuthorityTimer->Start();
}