Changeset - cbf6db2a6125
[Not reviewed]
0 4 0
Jan Kaluza - 14 years ago 2011-08-03 13:58:55
hanzz.k@gmail.com
better AdminInterface
4 files changed with 17 insertions and 9 deletions:
0 comments (0 inline, 0 general)
include/transport/networkpluginserver.h
Show inline comments
 
@@ -66,13 +66,13 @@ class NetworkPluginServer {
 
		const std::list<Backend *> &getBackends() {
 
			return m_clients;
 
		}
 

	
 
		void collectBackend();
 

	
 
		void moveToLongRunBackend(User *user);
 
		bool moveToLongRunBackend(User *user);
 

	
 
		void handleMessageReceived(NetworkConversation *conv, boost::shared_ptr<Swift::Message> &message);
 

	
 
	private:
 
		void handleNewClientConnection(boost::shared_ptr<Swift::Connection> c);
 
		void handleSessionFinished(Backend *c);
spectrum/src/sample.cfg
Show inline comments
 
@@ -5,13 +5,13 @@ server = 127.0.0.1
 
port = 5222
 
server_mode = 1
 
backend_host=localhost # < this option doesn't work yet
 
backend_port=10001
 
admin_username=admin
 
admin_password=test
 
#idle_reconnect_time=10
 
idle_reconnect_time=10
 
#cert= #patch to PKCS#12 certificate
 
#cert_password= #password to that certificate if any
 
users_per_backend=10
 
backend=../../backends/libpurple/spectrum_libpurple_backend
 
#backend=../../backends/libircclient-qt/spectrum_libircclient-qt_backend
 
#protocol=prpl-msn
src/admininterface.cpp
Show inline comments
 
@@ -104,20 +104,26 @@ void AdminInterface::handleMessageReceived(Swift::Message::ref message) {
 
		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++) {
 
			NetworkPluginServer::Backend *backend = *b;
 
			lst += "Backend " + boost::lexical_cast<std::string>(id) + ":\n";
 
			lst += "Backend " + boost::lexical_cast<std::string>(id);
 
			lst += backend->acceptUsers ? "" : " - not-accepting";
 
			lst += backend->longRun ? " - long-running" : "";
 
			lst += ":\n";
 
			if (backend->users.size() == 0) {
 
				lst += "   waiting for users\n";
 
			}
 
			else {
 
				time_t now = time(NULL);
 
				for (std::list<User *>::const_iterator u = backend->users.begin(); u != backend->users.end(); u++) {
 
					User *user = *u;
 
					lst += "   " + user->getJID().toBare().toString() + "\n";
 
					lst += "   " + user->getJID().toBare().toString();
 
					lst += " - non-active for " + boost::lexical_cast<std::string>(now - user->getLastActivity()) + " seconds";
 
					lst += "\n";
 
				}
 
			}
 
			id++;
 
		}
 

	
 
		message->setBody(lst);
src/networkpluginserver.cpp
Show inline comments
 
@@ -609,13 +609,14 @@ void NetworkPluginServer::pingTimeout() {
 
			}
 
		}
 
	}
 

	
 
	BOOST_FOREACH(User *u, usersToMove) {
 
		LOG4CXX_INFO(logger, "Moving user " << u->getJID().toString() << " to long-running backend");
 
		moveToLongRunBackend(u);
 
		if (!moveToLongRunBackend(u))
 
			break;
 
	}
 
	
 

	
 
	// check ping responses
 
	for (std::list<Backend *>::const_iterator it = m_clients.begin(); it != m_clients.end(); it++) {
 
		if ((*it)->pongReceived || (*it)->pongReceived == -1) {
 
@@ -652,32 +653,32 @@ void NetworkPluginServer::collectBackend() {
 
		m_collectTimer->start();
 
		LOG4CXX_INFO(logger, "Backend " << backend << "is set to die");
 
		backend->acceptUsers = false;
 
	}
 
}
 

	
 
void NetworkPluginServer::moveToLongRunBackend(User *user) {
 
bool NetworkPluginServer::moveToLongRunBackend(User *user) {
 
	// Check if user has already some backend
 
	Backend *old = (Backend *) user->getData();
 
	if (!old) {
 
		LOG4CXX_INFO(logger, "User " << user->getJID().toString() << " does not have old backend. Not moving.");
 
		return;
 
		return true;
 
	}
 

	
 
	// if he's already on long run, do nothing
 
	if (old->longRun) {
 
		LOG4CXX_INFO(logger, "User " << user->getJID().toString() << " is already on long-running backend. Not moving.");
 
		return;
 
		return true;
 
	}
 

	
 
	// Get free longrun backend, if there's no longrun backend, create one and wait
 
	// for its connection
 
	Backend *backend = getFreeClient(false, true);
 
	if (!backend) {
 
		LOG4CXX_INFO(logger, "No free long-running backend for user " << user->getJID().toString() << ". Will try later");
 
		return;
 
		return false;
 
	}
 

	
 
	// old backend will trigger disconnection which has to be ignored to keep user online
 
	user->setIgnoreDisconnect(true);
 

	
 
	// remove user from the old backend
 
@@ -687,12 +688,13 @@ void NetworkPluginServer::moveToLongRunBackend(User *user) {
 
	// switch to new backend and connect
 
	user->setData(backend);
 
	backend->users.push_back(user);
 

	
 
	// connect him
 
	handleUserReadyToConnect(user);
 
	return true;
 
}
 

	
 
void NetworkPluginServer::handleUserCreated(User *user) {
 
	Backend *c = getFreeClient();
 

	
 
	if (!c) {
0 comments (0 inline, 0 general)