Reputation: 5818
I am developing a server application in java (SE) + some open source libraries. This is a game, so I think it will have to be updated sometimes. As long as the app is tracking the state of the clients, using it, and also supports client sessions (in a form of dedicated threads), and singletons, which store references to these player instances, I would like to reload the JVM process (installing a new version of jar file for example), so that some of the classes and instances are not erased by GC, but hooked into the new process started.
Probable Situation:
I have a game version 1.0 running on the server. I need to add some new features in 1.2. But 100 players are fighting each other. I need to install version-1.2, players might feel some lag, but they should be able to continue with their fight even though the version of the jar has changed.
How can that be done?
Upvotes: 1
Views: 63
Reputation: 4223
First thing to note is that your current game state might be inconsistent with new version. So not all modifications could be installed like this. You can use remote caching system with master/slave configuration. So that all session is stored on remote machine and while one server is stopped, second server can continue working with the same state. First you put down slave, update it and start. Then switch roles and put down second server for update.
Upvotes: 1
Reputation: 22128
You could look at things like OSGI and class-loading tricks and see if you can achieve what you need, however maybe there is a simpler approach which is a bit safer too.
You could have 2 servers running behind a simple load balancer and when you need to do such maintenance you start routing all new games to Server A only. When all the games on server B finish (and no new games have started because all are going to server A) you stop server B and do whatever maintenance you need to do together with any tests to verify everything is OK before you introduce it back into the 'cluster'.
You then do the same thing and route new games to server B, so that when all games on server A finish you cans switch that off too and do the maintenance.
You will need to develop this simple load balancer which just acts as a connection router but is aware of your game sessions. Maybe you also need to have some information synchronisation between each server instance (if there is any need of communicating lists of players online, chat messages etc., depends what features you have).
Upvotes: 1
Reputation: 791
Take a look at JRebel authors' nice summary on the topic:
http://zeroturnaround.com/blog/reloading_java_classes_401_hotswap_jrebel/#!/
Upvotes: 2