get users online

Asked by marc

Hi,

Let's say when a user login on my website I create a session variable like:
session.put("id","3");

Each user has got a different id. How can I retrieve a list of the session id to know the users online?

Cheers,
Marc

Question information

Language:
English Edit question
Status:
Solved
For:
play framework Edit question
Assignee:
No assignee Edit question
Solved by:
Jean-Francois POUX
Solved:
Last query:
Last reply:
Revision history for this message
Best Jean-Francois POUX (jfp-taldius) said :
#1

Hi Marc,

Unfortunatly, the framework has no built-in mecanism to do that. Play does not track sessions, but instead, at the end of the request, stores the session data into a signed cookie. This approch has drawbacks: can't easily track number os sessions, 4Ko of data max per session (that one's not really a drawback, a session object should'nt be a cache/generic object trashcan), etc... But on the other hand, should you design a stateless app, then it's gonna run out the box on a cluster of play instances, without copying session between play instances, or such heavy mecanisms.

So, if you need to count online sessions, you'll have to go for a dedicated mecanism: track activity per user: date, identifiers, and so. Expire it after no activities, count users. If you know your application is going to be deployed on a single instance, the best place to have this data is likely in a static collection. If multiple instances of your application are going to be required, then you should go for a database or in a cache entry if you're running in memcached.

Revision history for this message
marc (marc-ttux) said :
#2

Ok, thank you for your help. I'll sort out something.