Added way to reload config ifle

This commit is contained in:
HanzZ 2011-07-09 17:07:44 +02:00
parent 9d23a3ba8b
commit 4d106deddd
4 changed files with 26 additions and 2 deletions

View file

@ -69,6 +69,8 @@ class Config {
/// \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.

View file

@ -89,6 +89,15 @@ void AdminInterface::handleMessageReceived(Swift::Message::ref message) {
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;
@ -125,8 +134,10 @@ void AdminInterface::handleMessageReceived(Swift::Message::ref message) {
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 {

View file

@ -74,4 +74,12 @@ bool Config::load(const std::string &configfile) {
return load(configfile, opts);
}
bool Config::reload() {
if (m_file.empty()) {
return false;
}
return load(m_file);
}
}

View file

@ -519,7 +519,7 @@ 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);
@ -804,10 +804,13 @@ 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;
}