Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Session Implementation

I am developing a multiplayer online game. I have the following issue:

When the user breaks his/her connection with the server, he needs to reconnect. At the first connection, during registration, the registration module produces a special ResponseDispatcher which holds the reference to the connection Channel. But if the user logs out, this Channel becomes invalid. Even though I can detect the problem and clean up resources, I have to store the reference to the registration module and Connection module to the game module, in order to renew the Channel when the user authorises and reconnects again. This creates a lot of interdependencies among modules and it gets really hard to maintain.

What I need is something like an HttpSession in Servlet Container, so that I can get the references to my channel and session resources from all modules of my server.

How is HttpSession implemented in Servlet? Is it a global hashmap storing all JSESSIONID, from which the container determines which attribute map to return? If it is a global sysmbol table, will it hit the performance (even though the time is O(1) for hashMap, there might be session modifications so it probably has to be synchronized)?

PS. Maybe some recommendations of design patterns for this case would also do.

like image 945
Artem Moskalev Avatar asked Oct 23 '13 12:10

Artem Moskalev


2 Answers

I would recommend trying Shiro

Shiro can handle Session Management outside of a servlet container.

You may want to back Shiro with EhCache to provide proper caching and, if required, session persistence (and load balancing, etc...)

like image 97
Bruno Grieder Avatar answered Oct 01 '22 17:10

Bruno Grieder


Have a look at the Facade Pattern

enter image description here

like image 21
Varun Achar Avatar answered Oct 01 '22 19:10

Varun Achar