Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listeners and Distributed JVMs

 
Sudd Ghosh
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi-
I am not at all able to understand the difference between HttpSessionAttributeListener and HttpSessionBindingListener. Pls can someone help me with this.
Also I understand that all JVMs in a distributed environment have their own copy of the ServletContexts and HttpSessions. If so, then how can we share any attribute if we want to ? In case we don't use an external resource (like database), do we have to manually replicate the attribute across all the sessions ?
Thanks, Sudd
 
Rishi Yagnik
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not at all able to understand the difference between HttpSessionAttributeListener and HttpSessionBindingListener. Pls can someone help me with this.
Hi Sudd
HttpSessionAttributeListener : configured in web.xml
HttpSessionBindingListener : not configured in web.xml
HttpSessionAttributeListener : This listener interface can be implemented in order to get notifications of changes to the attribute lists of sessions within this web application.
HttpSessionBindingListener : Object gets notified when it gets bound or unbound
all JVMs in a distributed environment have their own copy of the ServletContexts and HttpSessions.
Ans : Yes
see sharing an attribuute in disturbted will not work for servlet context OR session b'coz they are local to jvm for sharing an attributes better u need to make use of rdbms Or any external source.
see sharing a parameter u can do it by configuring in web.xml b'xoz parameter u defined in context-param that is available to all the servlet context but sharing is not the right word i feel
correct me if i am missing something
Rishi
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps more simply---
A HttpSessionBindingListener wants answers to the question "Am I being bound in or removed from a HttpSession?"
A HttpSessionAttributeListener wants answers to the question "Is something being bound in or removed from a HttpSession?"
In a distributed container, the HttpSession objects and all their attributes are shared between JVMs (although each one is usually only active on one JVM at a time). Everything else exists strictly on a per-JVM basis.
- Peter
 
Hari babu
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
When u say "session.setAttribute("myObject", JavaObject)", then the object implementing the HttpSessionAttributeListener is called, similarly for session.removeValue("myobject").
In the above if you want the "JavaObject" to be notified then you make the "JavaObject" class implement HttpSessionBindingListner
HTH
Hari
 
Sudd Ghosh
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the explanation.
Sudd
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic