Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to track all sessions?

 
James Hodgkiss
Ranch Hand
Posts: 401
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create a page where I can list everyone (along with their current search term) that is logged into my site with a valid session.

Can anyone advise the best way of going about this?

Thanks,
James
 
Sudipta Laha
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If i am correct this may be one of the way, but there may be better implementations.

When the user login a session object is created for that user and is used for his session till he logs out. We may store a string containing the current search details in the session object.
For retrieving the details of all the sessions, we may store the session object in a map(when the user logs in) and when we delete/invalidate a session we may remove it from the map.

Any modification made in the session object for a user will also be available in the map. So its can be used to display all the sessions.

Some places DBs are also used to store session object.
 
James Hodgkiss
Ranch Hand
Posts: 401
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sudipta,

Is the best (only?) way to detect session deletion/invalidation via the HttpSessionListener and it's sessionDestroyed method?

Cheers,
James
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far that i know, the only way to know if a session it is about to be destroyed it is by HttpSessionListener.

If you want, you can record who is logged through RequestListener or Filter. It's up to you.
 
James Hodgkiss
Ranch Hand
Posts: 401
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much to you both for the help - HttpSessionListener's sessionCreated and sessionDestroyed methods did the job.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic