• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listeners question

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

The following is from David Bridgewater's book,

"Closedown of a web application triggers a call to the matching closedown events in session and context listeners. The order in which listeners are
called is then in reverse order of deployment description declaration, with session listeners being processed before context listeners."

What it exactly means?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It refers to the following part of the spec :
SRV.10.3.4 Notifications At Shutdown
On application shutdown, listeners are notified in reverse order to their declarations with notifications to session listeners preceeding notifications to context listeners. Session listeners must be notified of session invalidations prior to context listeners being notified of application shutdown.


Look at your list of listeners declared in the deployment descriptor. At shutdown, they will be notified in the order opposite to the order in the descriptor. Moreover, session listeners will be notified prior to context listeners.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satou,

so 2 rules to follow,

1) The listeners gets notified in the reverse order in the deployment descriptor

2) The session listeners gets notified before all other listeners no matter where they are declared in the deployment descriptor.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Any reason as to why Listeners gets notified in the reverse order in the web.xml file during a webapp shutdown??
 
Sateesh Mandapaka
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jothi,

"Closedown of a web application triggers a call to the matching closedown events in session and context listeners. The order in which listeners are
called is then in reverse order of deployment description declaration, with session listeners being processed before context listeners."


What i think is when we close the application , the order of execution of the listeners would be the order in which the Application is brought down.
I would say this is quite similar to delete a row in a DB table whose Primary Key is used as a Foreign key in another table.( Situation in case of Child records) We need to do a CASCADE i.e we need to first delete the child and then the parent record.

In similar lines , what i feel is we first act upon the servlet specific , session specific listeners and then act upon the more generic ones later.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sateesh,
I can understand the CASCADE delete because of the parent-child relation, but listeners have no relation between each others.
That still does not explain why they are destroyed in reverse order.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou,

You know the reason??
 
Sateesh Mandapaka
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

What i meant was , when we bring down the webapp the Context listener is one that acts on the context params (which are for the total web app) and not specific for one particular servlet or session.So what i thought was we should be acting on the specific ones before going on with the more generic ones.

Please let me know if i am wrong.
Appreciate any kind of ideas.

Thanks,
Sateesh.

SCJP (1.4 ) - 88%
Taming SCWCD,
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know the reason??

I wish I did No sorry. I was thinking of some implementation reasons. Like stack-like data structures. But that does not make sense. I also thought of the Observable pattern, but the API states that it does not guarantee the order of invocation. So why are listeners destroyed in reverse order ? I can't tell
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou,

This behavior is not container specific right?? It is part of J2EE...Am I right on this?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This behavior is not container specific right??

No. The spec clearly states that listeners must be notified in reverse order at shutdown. But it does not mention why.
As you are studying for SCWCD, maybe you should leave it for the moment and come back to it once you're finished with the exam. Concentrate on what you need to know, which is the content of your first post
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satisfied Satou!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic