Changeset - 4d106deddda6
[Not reviewed]
0 4 0
HanzZ - 14 years ago 2011-07-09 17:07:44
hanzz.k@gmail.com
Added way to reload config ifle
4 files changed with 26 insertions and 2 deletions:
0 comments (0 inline, 0 general)
include/transport/config.h
Show inline comments
 
@@ -66,12 +66,14 @@ class Config {
 
		
 
		/// This function loads only config variables needed by libtransport.
 
		/// \see load(const std::string &, boost::program_options::options_description &)
 
		/// \param configfile path to config file
 
		bool load(const std::string &configfile);
 

	
 
		bool reload();
 

	
 
		/// Returns value of variable defined by key.
 
		
 
		/// For variables in sections you can use "section.variable" key format.
 
		/// \param key config variable name
 
		const boost::program_options::variable_value &operator[] (const std::string &key) {
 
			return m_variables[key];
src/admininterface.cpp
Show inline comments
 
@@ -86,12 +86,21 @@ void AdminInterface::handleMessageReceived(Swift::Message::ref message) {
 
		message->setBody(lst);
 
	}
 
	else if (message->getBody() == "online_users_count") {
 
		int users = m_userManager->getUserCount();
 
		message->setBody(boost::lexical_cast<std::string>(users));
 
	}
 
	else if (message->getBody() == "reload") {
 
		bool done = m_component->getConfig()->reload();
 
		if (done) {
 
			message->setBody("Config reloaded");
 
		}
 
		else {
 
			message->setBody("Error during config reload");
 
		}
 
	}
 
	else if (message->getBody() == "online_users_per_backend") {
 
		std::string lst;
 
		int id = 1;
 

	
 
		const std::list <NetworkPluginServer::Backend *> &backends = m_server->getBackends();
 
		for (std::list <NetworkPluginServer::Backend *>::const_iterator b = backends.begin(); b != backends.end(); b++) {
 
@@ -122,14 +131,16 @@ void AdminInterface::handleMessageReceived(Swift::Message::ref message) {
 
	}
 
	else if (message->getBody().find("help") == 0) {
 
		std::string help;
 
		help += "status - shows instance status\n";
 
		help += "online_users - returns list of all online users\n";
 
		help += "online_users_count - number of online users\n";
 
		help += "online_users_per_backend - shows online users per backends\n";
 
		help += "has_online_user <bare_JID> - returns 1 if user is online\n";
 
		help += "backends_count - number of active backends\n";
 
		help += "reload - Reloads config file\n";
 
		message->setBody(help);
 
	}
 
	else {
 
		message->setBody("Unknown command. Try \"help\"");
 
	}
 

	
src/config.cpp
Show inline comments
 
@@ -71,7 +71,15 @@ bool Config::load(const std::string &configfile, boost::program_options::options
 

	
 
bool Config::load(const std::string &configfile) {
 
	options_description opts("Transport options");
 
	return load(configfile, opts);
 
}
 

	
 
bool Config::reload() {
 
	if (m_file.empty()) {
 
		return false;
 
	}
 

	
 
	return load(m_file);
 
}
 

	
 
}
src/networkpluginserver.cpp
Show inline comments
 
@@ -516,13 +516,13 @@ void NetworkPluginServer::pingTimeout() {
 
}
 

	
 
void NetworkPluginServer::handleUserCreated(User *user) {
 
	Backend *c = getFreeClient();
 
	if (!c) {
 
		LOG4CXX_ERROR(logger, "There is no backend to handle user " << user->getJID().toString());
 
		user->handleDisconnected("Internal Server Error, please reconnect.");
 
		user->handleDisconnected("Internal Server Error (no free backend to handle your session), please reconnect.");
 
		return;
 
	}
 
	user->setData(c);
 
	c->users.push_back(user);
 

	
 
// 	UserInfo userInfo = user->getUserInfo();
 
@@ -801,16 +801,19 @@ void NetworkPluginServer::sendPing(Backend *c) {
 
}
 

	
 
NetworkPluginServer::Backend *NetworkPluginServer::getFreeClient() {
 
	NetworkPluginServer::Backend *c = NULL;
 
	bool spawnNew = false;
 
	for (std::list<Backend *>::const_iterator it = m_clients.begin(); it != m_clients.end(); it++) {
 
		// This backend is free.
 
		if ((*it)->users.size() < CONFIG_INT(m_config, "service.users_per_backend")) {
 
			if ((*it)->users.size() + 1 == CONFIG_INT(m_config, "service.users_per_backend")) {
 
			// After this user, this backend could be full, so we have to spawn new one...
 
			if ((*it)->users.size() + 1 >= CONFIG_INT(m_config, "service.users_per_backend")) {
 
				spawnNew = true;
 
			}
 

	
 
			if (c == NULL) {
 
				c = *it;
 
			}
 
			else {
 
				if ((*it)->users.size() + 1 != CONFIG_INT(m_config, "service.users_per_backend")) {
 
					spawnNew = false;
0 comments (0 inline, 0 general)