Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

listener interfaces ..

 
Jeffrey Pony
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
This one is again straight from the scwcd exam kit book
by Hanumant Deshmukh and Jignesh Malavia
( chapter 8 : review questions[4] ).
I realise that the container is not informed of
the class implementing HttpSessionBindingListener
via the deployment descriptor .
I also realise that the classes implementing the
other listener interfaces have to be mentioned
in the deployment descriptor.
How does this make a difference to the answer ?
I would appreciate if someone could explain this.
Thanks in advance
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeffrey
They don't make any difference to the answer. I think the explanation given was just to elaborate on the other options given in the question. As such, they are saying that even if a session attribute did implement the interfaces which are usually associated with deployment descriptor definitions (eg. HttpSessionListener), the methods of that interface would not be called on the implementing session attribute even if the event (eg. sessionDestroyed) did occur. As opposed to: They would be called if the appropriate listener class was defined in the deployment descriptor.
I guess they are just showing why or how you could eliminate the invalid answers.
 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Is the answer to the question 4 chapter 8:
valueUnbound() of HttpSessionBindingListener is called when the session is invalidated
Thanks
Ravi
 
Jeffrey Pony
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
option c seems fine .
Does'nt options a and b look promising.
when the session is invalidated hmmm the sessionDestroyed would be invoked and therefore the attributes associated with the particular session would also be removed .
Have I got this wrong ???
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeffrey
Check the question carefully: "Which of the following methods will be invoked on a session attribute that implements..."
The session attribute in this instance is an object that implements HttpSessionBindingListener, and as such provides implementations for the valueBound() and valueUnbound() methods. The valueUnbound() method is called when the session is invalidated which allows the session attribute object to respond in some or other way.
This is quite different to the listener classes defined in the deployment descriptor. ie Those classes which implement listener interfaces such as HttpSessionListener and HttpSessionAttributeListener. With HttpSessionAttributeListener, for instance, the attributeRemoved() method is called on the listener object for any session attribute that is removed from the session. This is different from the previous case where the session attribute itself is notified because it implemented the HttpSessionBindingListener interface.
Not sure if I have explained this all that clearly. I think Mike Curwen has a better crack at in in this thread.
Mark.
 
Jimmy Chiu
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,
I think you did an excellent job on explaining the scenario that session-attribute has �multiple-listening� roles.
In this case, a session-attribute not only is treated as part of the session-object�s data-field, but also served as session-object�s client-data-component.
That�s why this kind of session-attribute can implement both HttpSessionAttributeListener and HttpSessionBindingListener interfaces.
Am I right?
Thanks,
-Jimmy
[ March 27, 2003: Message edited by: Jimmy Chiu ]
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, that's not quite what I meant. There are two different angles to this:
  • Objects of a class that implement the HttpSessionAttributeListener interface, which you define as a listener in web.xml, will receive notifications when any attributes are added, removed or replaced in the session.
  • Objects of a class that implement the HttpSessionBindingListener interface, not configured as a listener in web.xml, will receive notifications when they are being added to or removed from a session.


  • Now consider this scenario:
  • Object A implements HttpSessionAttributeListener (Class A is a listener in web.xml)
  • Object B implements HttpSessionBindingListener.
  • Object B is added to the session. eg. session.setAttribute("myB", B)


  • What is the effect?
  • Object A's attributeAdded() method is called to indicate that an attribute has been added to the session.
  • Object B's valueBound() method is called to indicate that it (a session attribute), has been added to the session.


  • See the difference?
     
    Jimmy Chiu
    Ranch Hand
    Posts: 58
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Mark Howard:
    Hmmm, that's not quite what I meant. There are two different angles to this:
  • Objects of a class that implement the HttpSessionAttributeListener interface, which you define as a listener in web.xml, will receive notifications when any attributes are added, removed or replaced in the session.
  • Objects of a class that implement the HttpSessionBindingListener interface, not configured as a listener in web.xml, will receive notifications when they are being added to or removed from a session.


  • Now consider this scenario:
  • Object A implements HttpSessionAttributeListener (Class A is a listener in web.xml)
  • Object B implements HttpSessionBindingListener.
  • Object B is added to the session. eg. session.setAttribute("myB", B)


  • What is the effect?
  • Object A's attributeAdded() method is called to indicate that an attribute has been added to the session.
  • Object B's valueBound() method is called to indicate that it (a session attribute), has been added to the session.


  • See the difference?

    Surely, no problem to understand your points.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic