mirror of https://github.com/Icinga/icinga2.git
Added placeholders for event persistance handling.
This commit is contained in:
parent
2cd43ed8c6
commit
c11231f4e7
|
@ -9,7 +9,7 @@ int delegate_fwd(int (TObject::*function)(TArgs), weak_ptr<TObject> wref, const
|
||||||
{
|
{
|
||||||
shared_ptr<TObject> ref = wref.lock();
|
shared_ptr<TObject> ref = wref.lock();
|
||||||
|
|
||||||
if (ref.get() == NULL)
|
if (!ref)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return (ref.get()->*function)(args);
|
return (ref.get()->*function)(args);
|
||||||
|
|
|
@ -201,7 +201,7 @@ int ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea
|
||||||
ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
|
ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
|
||||||
ConfigObject::Ptr object = configHive->GetObject(type, name);
|
ConfigObject::Ptr object = configHive->GetObject(type, name);
|
||||||
|
|
||||||
if (object.get() == NULL)
|
if (!object)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
configHive->RemoveObject(object);
|
configHive->RemoveObject(object);
|
||||||
|
|
|
@ -4,10 +4,10 @@ using namespace icinga;
|
||||||
|
|
||||||
EndpointManager::Ptr Endpoint::GetEndpointManager(void) const
|
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;
|
m_EndpointManager = manager;
|
||||||
}
|
}
|
||||||
|
@ -61,3 +61,23 @@ void Endpoint::ForeachMethodSource(function<int (const NewMethodEventArgs&)> cal
|
||||||
callback(nmea);
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -17,14 +17,14 @@ private:
|
||||||
set<string> m_MethodSinks;
|
set<string> m_MethodSinks;
|
||||||
set<string> m_MethodSources;
|
set<string> m_MethodSources;
|
||||||
|
|
||||||
shared_ptr<EndpointManager> m_EndpointManager;
|
weak_ptr<EndpointManager> m_EndpointManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef shared_ptr<Endpoint> Ptr;
|
typedef shared_ptr<Endpoint> Ptr;
|
||||||
typedef weak_ptr<Endpoint> WeakPtr;
|
typedef weak_ptr<Endpoint> WeakPtr;
|
||||||
|
|
||||||
shared_ptr<EndpointManager> GetEndpointManager(void) const;
|
shared_ptr<EndpointManager> GetEndpointManager(void) const;
|
||||||
void SetEndpointManager(shared_ptr<EndpointManager> manager);
|
void SetEndpointManager(weak_ptr<EndpointManager> manager);
|
||||||
|
|
||||||
void RegisterMethodSink(string method);
|
void RegisterMethodSink(string method);
|
||||||
void UnregisterMethodSink(string method);
|
void UnregisterMethodSink(string method);
|
||||||
|
@ -44,6 +44,12 @@ public:
|
||||||
|
|
||||||
void ForeachMethodSink(function<int (const NewMethodEventArgs&)> callback);
|
void ForeachMethodSink(function<int (const NewMethodEventArgs&)> callback);
|
||||||
void ForeachMethodSource(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;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ bool JsonRpcEndpoint::IsLocal(void) const
|
||||||
|
|
||||||
bool JsonRpcEndpoint::IsConnected(void) const
|
bool JsonRpcEndpoint::IsConnected(void) const
|
||||||
{
|
{
|
||||||
return (m_Client.get() != NULL);
|
return m_Client;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonRpcEndpoint::ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message)
|
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_PendingCalls[id] = sender;
|
||||||
|
|
||||||
m_Client->SendMessage(message);
|
m_Client->SendMessage(message);
|
||||||
|
} else {
|
||||||
|
// TODO: persist the event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,8 +96,6 @@ int JsonRpcEndpoint::ClientClosedHandler(const EventArgs& ea)
|
||||||
{
|
{
|
||||||
m_PendingCalls.clear();
|
m_PendingCalls.clear();
|
||||||
|
|
||||||
// TODO: clear method sources/sinks
|
|
||||||
|
|
||||||
if (m_Client->GetPeerHost() != string()) {
|
if (m_Client->GetPeerHost() != string()) {
|
||||||
Timer::Ptr timer = make_shared<Timer>();
|
Timer::Ptr timer = make_shared<Timer>();
|
||||||
timer->SetInterval(30);
|
timer->SetInterval(30);
|
||||||
|
@ -105,6 +105,14 @@ int JsonRpcEndpoint::ClientClosedHandler(const EventArgs& ea)
|
||||||
m_ReconnectTimer = timer;
|
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();
|
m_Client.reset();
|
||||||
|
|
||||||
// TODO: persist events, etc., for now we just disable the endpoint
|
// 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);
|
JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(ea.UserArgs.Source);
|
||||||
Timer::Ptr timer = static_pointer_cast<Timer>(ea.Source);
|
Timer::Ptr timer = static_pointer_cast<Timer>(ea.Source);
|
||||||
|
|
||||||
m_Client = client;
|
GetEndpointManager()->AddConnection(client->GetPeerHost(), client->GetPeerPort());
|
||||||
|
|
||||||
timer->Stop();
|
timer->Stop();
|
||||||
m_ReconnectTimer.reset();
|
m_ReconnectTimer.reset();
|
||||||
|
|
|
@ -47,7 +47,7 @@ json_t *Netstring::GetJsonFromDictionary(const Dictionary::Ptr& dictionary)
|
||||||
case VariantObject:
|
case VariantObject:
|
||||||
valueDictionary = dynamic_pointer_cast<Dictionary>(i->second.GetObject());
|
valueDictionary = dynamic_pointer_cast<Dictionary>(i->second.GetObject());
|
||||||
|
|
||||||
if (valueDictionary.get() != NULL)
|
if (valueDictionary)
|
||||||
cJSON_AddItemToObject(json, i->first.c_str(), GetJsonFromDictionary(valueDictionary));
|
cJSON_AddItemToObject(json, i->first.c_str(), GetJsonFromDictionary(valueDictionary));
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue