Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

order in which listeners are called

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

What is the order(with respect to the order in Deployment Descriptor) in which Listeners are called in an application if two Listeners implement the same Interface. I have read that session listeners are processed before context listeners and are called in the reverse order of DD declaration. Is this correct? Please let me know.

Thanks in advance
Chandu
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you read this ?

From the spec:
The Web container registers the listener instances according to the interfaces they implement
and the order in which they appear in the deployment descriptor. During Web
application execution, listeners are invoked in the order of their registration.
 
Chandra Sagi
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The Web container registers the listener instances according to the interfaces they implement and the order in which they appear in the deployment descriptor. During Web application execution, listeners are invoked in the order of their registration.[/QB]



I have read it from SCWCD Study guide - Bridgewater pg 257. So, the order is not purely dependent on the deployment descriptor itself. How could we know which interfaces are registered first?

Thanks for your reply,
Cheers
Chandu
 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Listeners are registered and called in the order they're declared in the DD.

When application is shutting down, they are called in the reverse order of their DD declaration.

No listener has precedence over the others. If you want one listener to be called before the others, declare it first in your DD.
 
Chandra Sagi
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frederic and Satou,

Cheers
Chandu
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Frederic Esnault:
Listeners are registered and called in the order they're declared in the DD.

When application is shutting down, they are called in the reverse order of their DD declaration.

No listener has precedence over the others. If you want one listener to be called before the others, declare it first in your DD.



I think there is no question of precendence of listeners of different types, as they are called when the particular event is occured. If same type of listeners are defined in the web application, then the execution order is as per the DD when the event occur. This is about Calling the listeners. At the loading time the listener are loaded in order they defined in DD.

Thanks
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would someone please consolidate the different answers in this thread to a complete answer to the question originally raised?
I appreciate your help.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To summarize:
Listeners are registered and called in the order they're declared in the DD, no matter of there type.
 
Ramasubbhu Allur Kuppusamy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou,
Thanks for your rapid response .
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou's summary is correct, but don't forget the special case of application shutdown. In this case, they are called in the reverse order in which they are declared in the DD.
 
    Bookmark Topic Watch Topic
  • New Topic