REGISTER_APIFUNCTION(Hello, icinga, &ApiListener::HelloAPIHandler);
ApiListener::ApiListener(void)
- : m_LogMessageCount(0)
+ : m_SyncQueue(0, 4), m_LogMessageCount(0)
{ }
void ApiListener::OnConfigLoaded(void)
if (endpoint) {
endpoint->AddClient(aclient);
- if (need_sync) {
- {
- ObjectLock olock(endpoint);
-
- endpoint->SetSyncing(true);
- }
-
- Log(LogInformation, "ApiListener")
- << "Sending updates for endpoint '" << endpoint->GetName() << "'.";
-
- /* sync zone file config */
- SendConfigUpdate(aclient);
- /* sync runtime config */
- SendRuntimeConfigObjects(aclient);
-
- Log(LogInformation, "ApiListener")
- << "Finished sending updates for endpoint '" << endpoint->GetName() << "'.";
-
- ReplayLog(aclient);
- }
+ if (need_sync)
+ m_SyncQueue.Enqueue(boost::bind(&ApiListener::SyncClient, this, aclient, endpoint));
} else
AddAnonymousClient(aclient);
} else {
}
}
+void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoint::Ptr& endpoint)
+{
+ try {
+ {
+ ObjectLock olock(endpoint);
+
+ endpoint->SetSyncing(true);
+ }
+
+ Log(LogInformation, "ApiListener")
+ << "Sending updates for endpoint '" << endpoint->GetName() << "'.";
+
+ /* sync zone file config */
+ SendConfigUpdate(aclient);
+ /* sync runtime config */
+ SendRuntimeConfigObjects(aclient);
+
+ Log(LogInformation, "ApiListener")
+ << "Finished sending updates for endpoint '" << endpoint->GetName() << "'.";
+
+ ReplayLog(aclient);
+ } catch (const std::exception& ex) {
+ Log(LogCritical, "ApiListener")
+ << "Error while syncing endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex);
+ }
+}
+
void ApiListener::ApiTimerHandler(void)
{
double now = Utility::GetTime();
void ListenerThreadProc(const Socket::Ptr& server);
WorkQueue m_RelayQueue;
+ WorkQueue m_SyncQueue;
boost::mutex m_LogLock;
Stream::Ptr m_LogFile;
void DeleteConfigObject(const ConfigObject::Ptr& object, const MessageOrigin::Ptr& origin,
const JsonRpcConnection::Ptr& client = JsonRpcConnection::Ptr());
void SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient);
+
+ void SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoint::Ptr& endpoint);
};
}
{
BOOST_FOREACH(const Endpoint::Ptr& endpoint, ConfigType::GetObjectsByType<Endpoint>()) {
BOOST_FOREACH(const JsonRpcConnection::Ptr& client, endpoint->GetClients()) {
- if (endpoint->GetSyncing()) {
- Log(LogInformation, "JsonRpcConnection")
- << "Not sending heartbeat for endpoint '" << endpoint->GetName() << "' because we're replaying the log for it.";
- continue;
- }
-
if (client->m_NextHeartbeat != 0 && client->m_NextHeartbeat < Utility::GetTime()) {
Log(LogWarning, "JsonRpcConnection")
<< "Client for endpoint '" << endpoint->GetName() << "' has requested "