reload packages

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

corwin
Posts: 77
Joined: 17 Jul 2009, 08:19

reload packages

Postby corwin » 15 Dec 2009, 09:52

Hi, I have the the following problem.
I have java packages which I want to reuse in my sfs projects (Rating, Achievments, Board, etc.). I don't want to restart the server each time I update these packages. So I put them in my javaExtensions directory and after reloading projects which use them, everything is updated without the need to restart.
The problem comes with room specific objects - e.g. Board. Earlier I put it in the room properties and when needed just cast. Now I get "Blah blah, cannot cast, class Board is different from class Board". I thought I could put them as global HashMap<RoomId, Board>, but of course on reload they are cleared. Any ideas or advices how can I keep those objects after reload?
User avatar
Lapo
Site Admin
Posts: 21216
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 15 Dec 2009, 10:17

The problem is related with the class reloading.
When you reload classes in a new Class Loader the previous instances of those classes that are still in memory won't work with the new ones.

Technically they are not the same thing although to developer's eye they are instances of the "same" class.

This is a well know limit in the Java Virtual Machine architecture and there is not much you can do about it.

One pretty advanced way of handling this problem is decoupling your often-to-be-reloaded classes with interfaces that are loaded in the System Class Loader and then you will be able to reload their implementations many times in the custom Class Loader.

Example:
you need to reload four classes at runtime very often: Apple, Orange, Lemon, Pear

You create four interfaces: IApple, IOrange, ILemon and IPear and load them in the System Class Loader (add them to the server classpath)
Then you create your implementations and let SFS load them in a custom ClassLoader (i.e. put them in the javaExtensions/ folder)

This way you can hot-swap / hot-reload your implementations as many times as you wish as long as you always refer to these objects via their interfaces.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
corwin
Posts: 77
Joined: 17 Jul 2009, 08:19

Postby corwin » 15 Dec 2009, 11:22

Thanks for the advice.
corwin
Posts: 77
Joined: 17 Jul 2009, 08:19

Postby corwin » 17 Dec 2009, 12:04

I made some tests and I guess everything will be ok. But here comes the next problem - when the interfaces are in the System Class Loader, when I need to update an interface will have to restart the server. That will break not only the games played at the moment in the zone, but all zones' games.
I guess that will be pretty rare case, but still we have currently 8-10 games and I would want to avoid that. The obvious solution is to start separate sfs server instances for each of our "important" games, and when needed, to restart only the corresponding sfs.

So my questions is is it possible to have more than one sfs server instance on one machine with one license?
User avatar
Lapo
Site Admin
Posts: 21216
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 17 Dec 2009, 13:39

But here comes the next problem - when the interfaces are in the System Class Loader, when I need to update an interface will have to restart the server. That will break not only the games played at the moment in the zone, but all zones' games.

Yes absolutely. Ideally interfaces should never need to be changed, or at least they should very rarely.

So my questions is is it possible to have more than one sfs server instance on one machine with one license?

Sure, you can do that.

hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
corwin
Posts: 77
Joined: 17 Jul 2009, 08:19

Postby corwin » 17 Dec 2009, 13:44

Thanks. :)
corwin
Posts: 77
Joined: 17 Jul 2009, 08:19

Postby corwin » 18 Dec 2009, 12:05

... continue harassment ...

Couldn't start second instance on one server - the problem is h2. The two servers start fighting for poor 9009 and the second cries that fails at ".checkIfTableExists(AdvancedBuddyListPersister.java:270)".

At the docs I find just "localhost:9009 ---> this is the address of the H2 server and its TCP port. (should never change)".

Any hints how I can work round this problem?
User avatar
Lapo
Site Admin
Posts: 21216
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 18 Dec 2009, 13:32

SFS runs an internal database server which binds port 9009 by default. You will need to set a different TCP port for each instance using the <H2EnginePort>xxx</H2EnginePort> setting under <ServerSetup>
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 11 guests