]> granicus.if.org Git - icinga2/commitdiff
Added placeholders for event persistance handling.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 19 Apr 2012 10:16:52 +0000 (12:16 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 19 Apr 2012 10:16:52 +0000 (12:16 +0200)
base/delegate.h
components/configrpc/configrpccomponent.cpp
icinga/endpoint.cpp
icinga/endpoint.h
icinga/jsonrpcendpoint.cpp
jsonrpc/netstring.cpp

index a5281555062cb938a794ad35b0b49032b4259913..beae350fe5e4846c996cf7b2c6b7fa0ceadb2e7f 100644 (file)
@@ -9,7 +9,7 @@ int delegate_fwd(int (TObject::*function)(TArgs), weak_ptr<TObject> wref, const
 {
        shared_ptr<TObject> ref = wref.lock();
 
-       if (ref.get() == NULL)
+       if (!ref)
                return -1;
 
        return (ref.get()->*function)(args);
index 0e0194d3a7fee5d4b7e5b67fa15cb83778305a6c..15d1cc035ceb45a22128ec6dec2c25ab2a2f2fa3 100644 (file)
@@ -201,7 +201,7 @@ int ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea
        ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
        ConfigObject::Ptr object = configHive->GetObject(type, name);
 
-       if (object.get() == NULL)
+       if (!object)
                return 0;
 
        configHive->RemoveObject(object);
index d95b808070ccc7aeca99bd716dae30f2f775aa4d..7fd8e791fcc3310d8bce056aa1bd7d2c80b07afc 100644 (file)
@@ -4,10 +4,10 @@ using namespace icinga;
 
 EndpointManager::Ptr Endpoint::GetEndpointManager(void) const
 {
-       return m_EndpointManager;
+       return m_EndpointManager.lock();
 }
 
-void Endpoint::SetEndpointManager(EndpointManager::Ptr manager)
+void Endpoint::SetEndpointManager(EndpointManager::WeakPtr manager)
 {
        m_EndpointManager = manager;
 }
@@ -61,3 +61,23 @@ void Endpoint::ForeachMethodSource(function<int (const NewMethodEventArgs&)> cal
                callback(nmea);
        }
 }
+
+void Endpoint::ClearMethodSinks(void)
+{
+       m_MethodSinks.clear();
+}
+
+void Endpoint::ClearMethodSources(void)
+{
+       m_MethodSources.clear();
+}
+
+int Endpoint::CountMethodSinks(void) const
+{
+       return m_MethodSinks.size();
+}
+
+int Endpoint::CountMethodSources(void) const
+{
+       return m_MethodSources.size();
+}
index 1a7f8258ea87323f53b3bdc51e525e36f0cf12b2..efe509934eb66d1bd6acc579ca3ed5cb7185c3bb 100644 (file)
@@ -17,14 +17,14 @@ private:
        set<string> m_MethodSinks;
        set<string> m_MethodSources;
 
-       shared_ptr<EndpointManager> m_EndpointManager;
+       weak_ptr<EndpointManager> m_EndpointManager;
 
 public:
        typedef shared_ptr<Endpoint> Ptr;
        typedef weak_ptr<Endpoint> WeakPtr;
 
        shared_ptr<EndpointManager> GetEndpointManager(void) const;
-       void SetEndpointManager(shared_ptr<EndpointManager> manager);
+       void SetEndpointManager(weak_ptr<EndpointManager> manager);
 
        void RegisterMethodSink(string method);
        void UnregisterMethodSink(string method);
@@ -44,6 +44,12 @@ public:
 
        void ForeachMethodSink(function<int (const NewMethodEventArgs&)> callback);
        void ForeachMethodSource(function<int (const NewMethodEventArgs&)> callback);
+
+       void ClearMethodSinks(void);
+       void ClearMethodSources(void);
+
+       int CountMethodSinks(void) const;
+       int CountMethodSources(void) const;
 };
 
 }
index 604686c3d45cae609b72ea65fa724ea02e9b3a97..cc48665ac0d059eb936422a568989d0c11102571 100644 (file)
@@ -32,7 +32,7 @@ bool JsonRpcEndpoint::IsLocal(void) const
 
 bool JsonRpcEndpoint::IsConnected(void) const
 {
-       return (m_Client.get() != NULL);
+       return m_Client;
 }
 
 void JsonRpcEndpoint::ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message)
@@ -44,6 +44,8 @@ void JsonRpcEndpoint::ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest&
                        m_PendingCalls[id] = sender;
 
                m_Client->SendMessage(message);
+       } else {
+               // TODO: persist the event
        }
 }
 
@@ -94,8 +96,6 @@ int JsonRpcEndpoint::ClientClosedHandler(const EventArgs& ea)
 {
        m_PendingCalls.clear();
 
-       // TODO: clear method sources/sinks
-
        if (m_Client->GetPeerHost() != string()) {
                Timer::Ptr timer = make_shared<Timer>();
                timer->SetInterval(30);
@@ -105,6 +105,14 @@ int JsonRpcEndpoint::ClientClosedHandler(const EventArgs& ea)
                m_ReconnectTimer = timer;
        }
 
+       // TODO: _only_ clear non-persistent method sources/sinks
+       // unregister ourselves if no persistent sources/sinks are left (use a timer for that, once we have a TTL property for the methods)
+       ClearMethodSinks();
+       ClearMethodSources();
+
+       if (CountMethodSinks() == 0)
+               GetEndpointManager()->UnregisterEndpoint(static_pointer_cast<Endpoint>(shared_from_this()));
+
        m_Client.reset();
 
        // TODO: persist events, etc., for now we just disable the endpoint
@@ -124,7 +132,7 @@ int JsonRpcEndpoint::ClientReconnectHandler(const TimerEventArgs& ea)
        JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(ea.UserArgs.Source);
        Timer::Ptr timer = static_pointer_cast<Timer>(ea.Source);
 
-       m_Client = client;
+       GetEndpointManager()->AddConnection(client->GetPeerHost(), client->GetPeerPort());
 
        timer->Stop();
        m_ReconnectTimer.reset();
index 48ca07419d82d38add76c4834f6b2a17cd985654..85347cc0ef82ccdc88eaae7d921f2970809cb980 100644 (file)
@@ -47,7 +47,7 @@ json_t *Netstring::GetJsonFromDictionary(const Dictionary::Ptr& dictionary)
                        case VariantObject:
                                valueDictionary = dynamic_pointer_cast<Dictionary>(i->second.GetObject());
 
-                               if (valueDictionary.get() != NULL)
+                               if (valueDictionary)
                                        cJSON_AddItemToObject(json, i->first.c_str(), GetJsonFromDictionary(valueDictionary));
                        default:
                                break;