Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

significance of listerner class order in web.xml

 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranchers,

Please shed some light on the significance of the order of the listener classes in web.xml especially when the web application is initialized or destroyed

Thanks in advance
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok ..Probably is asked too big a question ...

Here is what I found after digging into Specs and some hands on

1) During Web application execution, listeners are invoked in the order of their registration.

2) On application shutdown, listeners are notified in reverse order to their declarations with notifications to session listeners preceeding notifications to context listeners.

However, second behaviour was missing in Tomcat 5.5.17 . SessionListeners were never notified when I shut down the server.

Please add your thoughts to this thread

Thanks
 
Senthil Kumar
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my knowlede following is the order in which listeners are get executed.

1.ServletContextListener
2.RequestListener

3.RequestAttributeListener--
4.ServletContextAttributeListener--

3 and 4 are not necessarily in the above mentioned order.might change as which order you set the attributes.

5.HttpSessionActivationListener - when the session migrates
6.HttpSessionListener - when the session is created/invalidated
7.HttpSessionAttributeListener
8.HttpSessionBindingListener
HttpSessionBindingListener's valuebound() is called b4 HttpSessionAttributeListener's attributeAdded().Likewise unbound() b4 attributeReplaced() or attributeRemoved.


The REVERSE
1.requestDestroyed() - immediately after the response is sent

while the application shuts down.
2.HttpRequestAttributeListener to remove the attribute
3.HttpSessionBindingListener
4.HttpSessionAttributeListener
5.HttpSessionListener
6.ServletContextAttributeListener
7.Finally ServletContextListener

correct me if i'm wrong
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Senthil Kumar SS:

The REVERSE
1.requestDestroyed() - immediately after the response is sent

while the application shuts down.
2.HttpRequestAttributeListener to remove the attribute



I am having a few doubts

i) What happens to the pending requests when the server is shutdown

Are the requests serviced before the server shuts down? If yes, then in that case HttpRequestAttributeListener needs to be notified before ServletRequestListener


ii) sessionDestroyed is not getting called when I am shutting down the Tomcat

It seems that the session information is being preserved across restarts.

Does the spec talk about something like this ?
 
Senthil Kumar
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add to your doubts

1. In HttpSessionActivationListener WillPassivate() is called on which JVM(jvm1) and DidActivate is called on which JVM(jvm2).

2.As per the HFSJ book session migrates in the distributed web application.
In the case of session failover how come the session is moved from the JVM1 to JVM2 when already the JVM1 is down.obviously session on JVM1 would've been lost.Is the session replicated over all JVMs.But the book says it is not.

please some one clarify this
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I can answer your first doubt

HttpSessionActivationListener.sessionDidActivate() is called on JVM2 when the session is about to be activated on it

HttpSessionActivationListener.sessionWillPassivate is called on JVM1 when the session is about to be migrated from it

But still there are a lot of doubts left ... I am wondering why the ranchers are not coming forward to answer this thread
[ September 04, 2006: Message edited by: Vivek Pandey ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2. The session is being serialized in a distributed environement and it actually migrates when the server crashes. You can refer to Tomcat's documentation on laod balancing and clustering :
http://tomcat.apache.org/tomcat-5.0-doc/cluster-howto.html (4. TomcatA crashes)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic