custom login and multithreading

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Post Reply
User avatar
rewb0rn
Posts: 177
Joined: 26 Jan 2009, 12:54
Location: Berlin, Germany

custom login and multithreading

Post by rewb0rn »

Hi,

in my previous game with SFS 1.6 I used an executor service that handled additional threads to perform actions that connect to our database. This also includes the login process. In SFS2X however it seems that I can not invoke an additional thread to complete the login process, because the Login handler will trigger the login as soon as the event handler returns. So is there any other way to achieve a multithreaded login process or will I have to stay in the same thread?

Thanks in advance

edit: We are actually using a php backend that validates the users so the login process may take some time that is best spent in a second thread to not block the ingame actions.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Hi,
interesting question. This is a bit advanced and I am sorry if we haven't touched on this yet in our documentation. The next articles we will publish will include these topics too.

in SFS2X events are fired by one entity only called (predictably) EventManager. The EventManager is backed by a Thread pool that can be resized at runtime. This should be enough for almost all needs as regards adding threads for long running activities.

All you need to do is configure the manager's thread pool so that it uses enough threads for your needs. This means that any other slow operation executed by your code in any other event handler will also benefit from the new settings.

In the init() method of your Extenion's main class you just need this line:

Code: Select all

public void init()
{
   SmartFoxServer.getInstance().getEventManager().setThreadPoolSize(xy);
}
where xy is the number of threads you want.

NOTE: Just pay attention not to include this line in multiple extensions or each one will reconfigure the manager but only the last one will have effect.
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply