Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listener Registration

 
Kamal Tripathi
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source: Servlet 2.4 Spec SRV.10.3.3 Listener Registration


The Web 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.

In the statement in bold, I understood that listeners are registered in order in which they appear in DD, but what is exactly meant by registration accd to interfaces they implement ??

On the same lines I wanted to ask if in a webapp's DD I configure an HttpSessionAttributeListener and also define a class A implementing HttpSessionBindingListener interface.

Now when objects of class A are set as attributes in session which listener will run first???
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the best you can do, is test this by your self.

If you have a problem implementing this, you can ask!!
 
Chithra Salam
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kamal Tripathi wrote:

On the same lines I wanted to ask if in a webapp's DD I configure an HttpSessionAttributeListener and also define a class A implementing HttpSessionBindingListener interface.

Now when objects of class A are set as attributes in session which listener will run first???
.

The Web container registers the listener instances according to the interfaces they implement and the order in which they appear in the deployment descriptor-means

If suppose a LisitenerclassA implements HttpSessionAttributeListener ,HttpSessionBindingListener and another class LisitenerclassB implements HttpSessionAttributeListener ,HttpSessionBindingListener

and in dd we declare
<listener><listener-class><com.example.LisitenerclassB ></listener-class></listener>
<listener><listener-class><com.example.LisitenerclassA></listener-class></listener>
Now order of creation of instance of classes is LisitenerclassB ,LisitenerclassA.
and then order of registration of classes for events are LisitenerclassB regstrd against HttpSessionAttributeListener
LisitenerclassB regstrd against HttpSessionBindingListener
LisitenerclassA regstrd against HttpSessionAttributeListener
LisitenerclassA regstrd against HttpSessionBindingListener .

So a HttpSessionAttribute event [replace an attribute including a binding event]occur LisitenerclassB will be notified 1st and method invocation will be in the order attributeReplaced,valueBound- means in the order in which interface is been regstrd.

Kamal Tripathi wrote:On the same lines I wanted to ask if in a webapp's DD I configure an HttpSessionAttributeListener and also define a class A implementing HttpSessionBindingListener interface.
--- When you say configure an HttpSessionAttributeListener in DD that includes that class A implements HttpSessionAttributeListener as well rght .I think now you got the answer for this as well.
Thanks,
Chithra Salam
SCJP-85%,SCWCD-in progress.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic