Two Laptop Bag*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Listeners and Distributed JVMs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Listeners and Distributed JVMs" Watch "Listeners and Distributed JVMs" New topic
Author

Listeners and Distributed JVMs

Sudd Ghosh
Ranch Hand

Joined: Oct 23, 2002
Posts: 187
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


SCJP 1.4, SCWCD, SCBCD 1.3
Rishi Yagnik
Ranch Hand

Joined: Jan 04, 2001
Posts: 84
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

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Jun 25, 2001
Posts: 208
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

Joined: Oct 23, 2002
Posts: 187
Thanks for the explanation.
Sudd
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Listeners and Distributed JVMs