Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Active HttpSessions in Context

 
Mathew Sam
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any API which allows to find the number of active httpsession in a context?



Regards,
Sam
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use HttpSessionListener interface

create a class implementing this interface. you implement 2 of its methods - 1 is called when any session is created, and 1 when any is destroyed.

so at any moment you can get #created minus #destroyed = count of active

i guess, you might need to know the count, so in that class, you can, for example write the count to a file, or to Sysout.

add this class to the web.xml. and have the server know of this addition. and there you go...
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also, the first time the listener's sessionCreated method is called, put the instance of the listener to the servlet context as an attribute, so every body in the context can use it
 
Mathew Sam
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually the requirement is to invalidate all the active httpsession when the application is shutdown. I want to get the refernces of all active httpsession to explicity invalidate when the application is stopped.
 
Mathew Sam
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically looking for the functinality of HttpSessionContext.getIds() which is deprecated.
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose there is no such public API for this. It would break the security.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic