From e9e2991f8e189ffc3e6e07cace185593b44e48f3 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Fri, 29 Jul 2011 00:50:43 +0200 Subject: [PATCH] collectBackend called every hour --- include/transport/networkpluginserver.h | 2 ++ src/config.cpp | 1 + src/networkpluginserver.cpp | 27 +++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/transport/networkpluginserver.h b/include/transport/networkpluginserver.h index 239bff24..8533f152 100644 --- a/include/transport/networkpluginserver.h +++ b/include/transport/networkpluginserver.h @@ -104,6 +104,7 @@ class NetworkPluginServer { void send(boost::shared_ptr &, const std::string &data); void pingTimeout(); + void collectBackend(); void sendPing(Backend *c); Backend *getFreeClient(); @@ -115,6 +116,7 @@ class NetworkPluginServer { boost::shared_ptr m_server; std::list m_clients; Swift::Timer::ref m_pingTimer; + Swift::Timer::ref m_collectTimer; Component *m_component; std::list m_waitingUsers; }; diff --git a/src/config.cpp b/src/config.cpp index c9a398e9..36e7f05f 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -46,6 +46,7 @@ bool Config::load(const std::string &configfile, boost::program_options::options ("service.cert_password", value()->default_value(""), "PKCS#12 Certificate password.") ("service.admin_username", value()->default_value(""), "Administrator username.") ("service.admin_password", value()->default_value(""), "Administrator password.") + ("service.reuse_old_backends", value()->default_value(true), "True if Spectrum should use old backends which were full in the past.") ("identity.name", value()->default_value("Spectrum 2 Transport"), "Name showed in service discovery.") ("identity.category", value()->default_value("gateway"), "Disco#info identity category. 'gateway' by default.") ("identity.type", value()->default_value(""), "Type of transport ('icq','msn','gg','irc', ...)") diff --git a/src/networkpluginserver.cpp b/src/networkpluginserver.cpp index 0c032f18..8fd4d41c 100644 --- a/src/networkpluginserver.cpp +++ b/src/networkpluginserver.cpp @@ -146,6 +146,10 @@ NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, U m_pingTimer->onTick.connect(boost::bind(&NetworkPluginServer::pingTimeout, this)); m_pingTimer->start(); + m_collectTimer = component->getNetworkFactories()->getTimerFactory()->createTimer(3600000); + m_collectTimer->onTick.connect(boost::bind(&NetworkPluginServer::collectBackend, this)); + m_collectTimer->start(); + m_vcardResponder = new VCardResponder(component->getIQRouter(), userManager); m_vcardResponder->onVCardRequired.connect(boost::bind(&NetworkPluginServer::handleVCardRequired, this, _1, _2, _3)); m_vcardResponder->onVCardUpdated.connect(boost::bind(&NetworkPluginServer::handleVCardUpdated, this, _1, _2)); @@ -585,6 +589,23 @@ void NetworkPluginServer::pingTimeout() { m_pingTimer->start(); } +void NetworkPluginServer::collectBackend() { + LOG4CXX_INFO(logger, "Collect backend called, finding backend which will be set to die"); + unsigned long max = 0; + Backend *backend = NULL; + for (std::list::const_iterator it = m_clients.begin(); it != m_clients.end(); it++) { + if ((*it)->res > max) { + max = (*it)->res; + backend = (*it); + } + } + + if (backend) { + LOG4CXX_INFO(logger, "Backend " << backend << "is set to die"); + backend->acceptUsers = false; + } +} + void NetworkPluginServer::handleUserCreated(User *user) { Backend *c = getFreeClient(); @@ -946,8 +967,10 @@ NetworkPluginServer::Backend *NetworkPluginServer::getFreeClient() { // This backend is free. if ((*it)->acceptUsers && (*it)->users.size() < CONFIG_INT(m_config, "service.users_per_backend") && (*it)->connection) { c = *it; - if (c->users.size() + 1 >= CONFIG_INT(m_config, "service.users_per_backend")) { - c->acceptUsers = false; + if (!CONFIG_BOOL(m_config, "service.reuse_old_backends")) { + if (c->users.size() + 1 >= CONFIG_INT(m_config, "service.users_per_backend")) { + c->acceptUsers = false; + } } break; }