]> granicus.if.org Git - icinga2/commitdiff
Funnel messages through the generic SendUnicastRequest method to take advantage of...
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 23 Apr 2012 14:48:40 +0000 (16:48 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 23 Apr 2012 14:48:40 +0000 (16:48 +0200)
icinga/endpointmanager.cpp
icinga/endpointmanager.h
icinga/subscriptioncomponent.cpp

index 1f6172eb2603a582b6a26e31b602754e7fe1e8af..6e499fed826129d29fd53389567f4891912d2cbe 100644 (file)
@@ -73,6 +73,23 @@ void EndpointManager::UnregisterEndpoint(Endpoint::Ptr endpoint)
        m_Endpoints.remove(endpoint);
 }
 
+void EndpointManager::SendUnicastRequest(Endpoint::Ptr sender, Endpoint::Ptr recipient, const JsonRpcRequest& request, bool fromLocal)
+{
+       if (sender == recipient)
+               return;
+
+       /* don't forward messages between non-local endpoints */
+       if (!fromLocal && !recipient->IsLocal())
+               return;
+
+       string method;
+       if (!request.GetMethod(&method))
+               throw InvalidArgumentException("Missing 'method' parameter.");
+
+       if (recipient->IsMethodSink(method) && recipient->IsAllowedMethodSink(method))
+               recipient->ProcessRequest(sender, request);
+}
+
 void EndpointManager::SendAnycastRequest(Endpoint::Ptr sender, const JsonRpcRequest& request, bool fromLocal)
 {
        throw NotImplementedException();
@@ -92,17 +109,7 @@ void EndpointManager::SendMulticastRequest(Endpoint::Ptr sender, const JsonRpcRe
 
        for (list<Endpoint::Ptr>::iterator i = m_Endpoints.begin(); i != m_Endpoints.end(); i++)
        {
-               Endpoint::Ptr endpoint = *i;
-
-               if (endpoint == sender)
-                       continue;
-
-               /* send non-local messages to just the local endpoints */
-               if (!fromLocal && !endpoint->IsLocal())
-                       continue;
-
-               if (endpoint->IsMethodSink(method) && endpoint->IsAllowedMethodSink(method))
-                       endpoint->ProcessRequest(sender, request);
+               SendUnicastRequest(sender, *i, request, fromLocal);
        }
 }
 
index e125dc94d94465557bf0b8839d46855d3b018c79..34815d7353979e6f4842c310382960b061e0fdba 100644 (file)
@@ -36,6 +36,7 @@ public:
        void RegisterEndpoint(Endpoint::Ptr endpoint);
        void UnregisterEndpoint(Endpoint::Ptr endpoint);
 
+       void SendUnicastRequest(Endpoint::Ptr sender, Endpoint::Ptr recipient, const JsonRpcRequest& request, bool fromLocal = true);
        void SendAnycastRequest(Endpoint::Ptr sender, const JsonRpcRequest& request, bool fromLocal = true);
        void SendMulticastRequest(Endpoint::Ptr sender, const JsonRpcRequest& request, bool fromLocal = true);
 
index 6af4bffbdbdc7a68cf1e3593823deaacf2fd0de9..60fc677487fd3a99090cdce9125d9c69ebc08692 100644 (file)
@@ -46,7 +46,8 @@ int SubscriptionComponent::SyncSubscription(Endpoint::Ptr target, string type, c
        subscriptionMessage.SetMethod(nmea.Method);
        request.SetParams(subscriptionMessage);
 
-       target->ProcessRequest(m_SubscriptionEndpoint, request);
+       EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
+       endpointManager->SendUnicastRequest(m_SubscriptionEndpoint, target, request);
 
        return 0;
 }