wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes listener class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "listener class" Watch "listener class" New topic
Author

listener class

agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
My doubt is
How Container figures out about listener type while we never give its type?
Can we imagine that Container instantiates all the listeners at deployment time in order to figure out its type?
Thanx
lalit upadheyay
Ranch Hand

Joined: Jun 20, 2005
Posts: 110
through the listener interface type implemented by the class.


SCJP1.4, SCWCD1.4, SCBCD5.0(working on...)
agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
Thanx....
It means Container instantiates all the listeners at startup time?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

SRV.10.3.3 Listener Registration

TheWeb container creates an instance of each listener class and registers it for event notifications prior to the processing of the first request by the application. 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.


[My Blog]
All roads lead to JavaRanch
lalit upadheyay
Ranch Hand

Joined: Jun 20, 2005
Posts: 110
I guess, that the container instantiates the listenres as needed i.e.

context listeners are instantiated when ServletContext (one for the web app) is created.

request listeners are instantiated when first request arrives.
session listeners are instantiated when first session is created.

attribute listeners are instantiated when the attribute class implementing them are instantiated.
agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
Thanx kurinosuke.....This very was my assumption too.
One more thing: while executing sessionCreted() method of HttpSeesionListener class ,if any attribute is added to the session,it should call attributeAdded() method in HttpSessionAttributeListener.But if method sessionCreated() is not completed yet,will Container first transfer the control to attributeAdded() and will come to sessionCreated() later?
agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
Hai Lalit, just saw your posts but they seem to be wrong.Because Container first wants to instantiate instance of class implementing ServletContextListener. But how will it know about its type until it instantiates it.........Correct me if I am wrong!
Thanx
lalit upadheyay
Ranch Hand

Joined: Jun 20, 2005
Posts: 110
yes, you are right. listener type cannot be determined before instantaiting the class.
agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
Lalit also help me regarding one more doubt in this very post.........
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Originally posted by agrah upadhyay:

One more thing: while executing sessionCreted() method of HttpSeesionListener class ,if any attribute is added to the session,it should call attributeAdded() method in HttpSessionAttributeListener.But if method sessionCreated() is not completed yet,will Container first transfer the control to attributeAdded() and will come to sessionCreated() later?


There is no way that the control will be changed from sessionCreated to attributeAdded. There either two possibilities I think :
1. The container creates a new thread for each listener, so the HttpSessionListener and HttpSessionAttributeListener can both be called at the same time
2. The container does not create new threads, and in this case, you'll have to wait until sessionCreated ends.

Sry, I don't know which one it is.
You should not have heavy process in your listeners anyway, so sessionCreated SHOULD be finished before attributeAdded is called
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Trying it, it seems that the container waits until sessionCreated is finished.
You should not have to worry about that kind of problem.
agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
I got your point but.......What do you mean by heavy process-in terms of memory?-How?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: listener class