Changeset - e9e2991f8e18
[Not reviewed]
0 3 0
HanzZ - 14 years ago 2011-07-29 00:50:43
hanzz.k@gmail.com
collectBackend called every hour
3 files changed with 28 insertions and 2 deletions:
0 comments (0 inline, 0 general)
include/transport/networkpluginserver.h
Show inline comments
 
@@ -104,6 +104,7 @@ class NetworkPluginServer {
 
		void send(boost::shared_ptr<Swift::Connection> &, const std::string &data);
 

	
 
		void pingTimeout();
 
		void collectBackend();
 
		void sendPing(Backend *c);
 
		Backend *getFreeClient();
 

	
 
@@ -115,6 +116,7 @@ class NetworkPluginServer {
 
		boost::shared_ptr<Swift::BoostConnectionServer> m_server;
 
		std::list<Backend *>  m_clients;
 
		Swift::Timer::ref m_pingTimer;
 
		Swift::Timer::ref m_collectTimer;
 
		Component *m_component;
 
		std::list<User *> m_waitingUsers;
 
};
src/config.cpp
Show inline comments
 
@@ -46,6 +46,7 @@ bool Config::load(const std::string &configfile, boost::program_options::options
 
		("service.cert_password", value<std::string>()->default_value(""), "PKCS#12 Certificate password.")
 
		("service.admin_username", value<std::string>()->default_value(""), "Administrator username.")
 
		("service.admin_password", value<std::string>()->default_value(""), "Administrator password.")
 
		("service.reuse_old_backends", value<bool>()->default_value(true), "True if Spectrum should use old backends which were full in the past.")
 
		("identity.name", value<std::string>()->default_value("Spectrum 2 Transport"), "Name showed in service discovery.")
 
		("identity.category", value<std::string>()->default_value("gateway"), "Disco#info identity category. 'gateway' by default.")
 
		("identity.type", value<std::string>()->default_value(""), "Type of transport ('icq','msn','gg','irc', ...)")
src/networkpluginserver.cpp
Show inline comments
 
@@ -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<Backend *>::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;
 
		}
0 comments (0 inline, 0 general)