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

HTTP Session listener and session destroyed call

 
Monmohan Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we need to implement an edit lock on some of our records so that they can't be simultaneously edited by two users.
Also we need to clean up the lock when the user time out happens.
We thought of implementing this using an HTTPSessionListener but the servlet 2.3 API suggests that the sessionDestroyed() is called after the session is destroyed. Then we have no way to decide what and which user to cleanup??
Looks like writing our own deamon thread is only possibility
Any thoughts on this will be helpful - posted this on servlet forum but no answers
 
Mallik Hiremath
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that you are talking about the HttpSession, you can use the sessionDestroyed() method and implement your functionality, because the sessionDestroyed looks like its being called just before the session is invalidated, from with in this method you can get hold of the HttpSessionEvent from the session event you can get the Session Object and get those values which you have stored in the Session
V 2.3 API says:
sessionDestroyed(HttpSessionEvent se)
public void sessionDestroyed(HttpSessionEvent se)Notification that a session is about to be invalidated.
Parameters:
se - the notification event
-Mallik
 
Monmohan Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I also though the same but
According to http://developer.java.sun.com/developer/EJTechTips/2003/tt0626.html
�javax.servlet.http.HttpSessionListener.
The methods in this interface are called when an HTTP session is created or destroyed. Whether the call to the method occurs before or after the session is invalidated, depends on which specification version (2.3 or 2.4) is being used.
It's worthwhile to verify the behavior of the platform implementation you are using if your application behavior depends on this detail.�
 
Mallik Hiremath
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, You are correct
In API 2.3 the sessionDestroyed() method is called just after the Session was invalidated
In Servlet API 2.4 the sessionDestroyed() method is called just before the Session is getting invalidated (means you can still get a reference to Session )
I don't know which API you are or planning to using!!

-Mallik
 
Christian Ebage
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

we need to implement an edit lock on some of our records so that they can't be simultaneously edited by two users.Also we need to clean up the lock when the user time out happens.We thought of implementing this using an HTTPSessionListener but the servlet 2.3 API suggests that the sessionDestroyed() is called after the session is destroyed. Then we have no way to decide what and which user to cleanup?? Looks like writing our own deamon thread is only possibility Any thoughts on this will be helpful

Have you considered wraping the current user's session id in a class then implement the HttpSessionBinding Interface? When the user logs in, you could wrap this class in the user's session, instead of the user's id itself directly in the session.When the session invalidates, the container calls the valueUnbound() method on the wrapper class. This gives you the chance to cleanup the current user. Hope this helps
Ebage
SCJP
SCWCD
SCEA
[ September 21, 2003: Message edited by: Christian Ebage ]
 
Monmohan Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, we will try this
 
Christian Ebage
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I meant the HttpSessionBindingListener interface. There is nothing like HttpSessionBinding interface.
Ebage
SCJP
SCWCD
SCEA
[ September 22, 2003: Message edited by: Christian Ebage ]
 
Monmohan Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understood that
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic