From 5a7aeb1f19262be266bd3afc5236b6e178b0360a Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 18 Jan 2013 09:36:28 +0100 Subject: [PATCH] Fix: Endpoints were not properly marked as local. --- components/checker/checkercomponent.cpp | 2 +- components/demo/democomponent.cpp | 2 +- components/replication/replicationcomponent.cpp | 2 +- lib/remoting/endpoint.cpp | 5 +++-- lib/remoting/endpoint.h | 2 +- lib/remoting/endpointmanager.cpp | 12 +++++++----- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 8e16d87ad..928289a47 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -23,7 +23,7 @@ using namespace icinga; void CheckerComponent::Start(void) { - m_Endpoint = Endpoint::MakeEndpoint("checker", true); + m_Endpoint = Endpoint::MakeEndpoint("checker", false); /* dummy registration so the delegation module knows this is a checker TODO: figure out a better way for this */ diff --git a/components/demo/democomponent.cpp b/components/demo/democomponent.cpp index 17c3d4dbf..b72b02f1e 100644 --- a/components/demo/democomponent.cpp +++ b/components/demo/democomponent.cpp @@ -26,7 +26,7 @@ using namespace icinga; */ void DemoComponent::Start(void) { - m_Endpoint = Endpoint::MakeEndpoint("demo", true); + m_Endpoint = Endpoint::MakeEndpoint("demo", false); m_Endpoint->RegisterTopicHandler("demo::HelloWorld", boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _2, _3)); diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp index f8ee5c68c..ec717566a 100644 --- a/components/replication/replicationcomponent.cpp +++ b/components/replication/replicationcomponent.cpp @@ -26,7 +26,7 @@ using namespace icinga; */ void ReplicationComponent::Start(void) { - m_Endpoint = Endpoint::MakeEndpoint("replication", true); + m_Endpoint = Endpoint::MakeEndpoint("replication", false); DynamicObject::OnRegistered.connect(boost::bind(&ReplicationComponent::LocalObjectRegisteredHandler, this, _1)); DynamicObject::OnUnregistered.connect(boost::bind(&ReplicationComponent::LocalObjectUnregisteredHandler, this, _1)); diff --git a/lib/remoting/endpoint.cpp b/lib/remoting/endpoint.cpp index 99d26848e..b6e89f1f3 100644 --- a/lib/remoting/endpoint.cpp +++ b/lib/remoting/endpoint.cpp @@ -76,15 +76,16 @@ Endpoint::Ptr Endpoint::GetByName(const String& name) * Helper function for creating new endpoint objects. * * @param name The name of the new endpoint. + * @param replicated Whether replication is enabled for the endpoint object. * @param local Whether the new endpoint should be local. * @returns The new endpoint. */ -Endpoint::Ptr Endpoint::MakeEndpoint(const String& name, bool local) +Endpoint::Ptr Endpoint::MakeEndpoint(const String& name, bool replicated, bool local) { ConfigItemBuilder::Ptr endpointConfig = boost::make_shared(); endpointConfig->SetType("Endpoint"); endpointConfig->SetName(local ? "local:" + name : name); - endpointConfig->SetLocal(local ? 1 : 0); + endpointConfig->SetLocal(!replicated); endpointConfig->AddExpression("local", OperatorSet, local); DynamicObject::Ptr object = endpointConfig->Compile()->Commit(); diff --git a/lib/remoting/endpoint.h b/lib/remoting/endpoint.h index 744469723..9b8e22eb8 100644 --- a/lib/remoting/endpoint.h +++ b/lib/remoting/endpoint.h @@ -69,7 +69,7 @@ public: String GetNode(void) const; String GetService(void) const; - static Endpoint::Ptr MakeEndpoint(const String& name, bool local); + static Endpoint::Ptr MakeEndpoint(const String& name, bool replicated, bool local = true); static boost::signal OnConnected; static boost::signal OnDisconnected; diff --git a/lib/remoting/endpointmanager.cpp b/lib/remoting/endpointmanager.cpp index 299e24ab5..799f3c2f8 100644 --- a/lib/remoting/endpointmanager.cpp +++ b/lib/remoting/endpointmanager.cpp @@ -81,7 +81,7 @@ void EndpointManager::SetIdentity(const String& identity) if (object) m_Endpoint = dynamic_pointer_cast(object); else - m_Endpoint = Endpoint::MakeEndpoint(identity, false); + m_Endpoint = Endpoint::MakeEndpoint(identity, true, true); } /** @@ -173,7 +173,7 @@ void EndpointManager::ClientConnectedHandler(const Stream::Ptr& client, const St if (Endpoint::Exists(identity)) endpoint = Endpoint::GetByName(identity); else - endpoint = Endpoint::MakeEndpoint(identity, false); + endpoint = Endpoint::MakeEndpoint(identity, true); endpoint->SetClient(jclient); } @@ -310,9 +310,11 @@ void EndpointManager::SubscriptionTimerHandler(void) if (!endpoint->IsLocalEndpoint()) continue; - String topic; - BOOST_FOREACH(tie(tuples::ignore, topic), endpoint->GetSubscriptions()) { - subscriptions->Set(topic, topic); + if (endpoint->GetSubscriptions()) { + String topic; + BOOST_FOREACH(tie(tuples::ignore, topic), endpoint->GetSubscriptions()) { + subscriptions->Set(topic, topic); + } } }