Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSessionActivationListener

 
Lee Kian Giap
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have an attribute class implements HttpSessionActivationListener,
and the object instantiated from this attribute class is set to session attribute. Therefore, when the session passivate and activate, this attribute object will be notified....

Am I possible to write a class (which is not attribute class that use to instantiate an attribute object, and is not going to be set to session attribute) implements HttpSessionActivationListener ?? if yes , when will this class be notified, since this Listener are not going to be in the Deployment Descriptor ??

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand what you're asking. An object will be notified if it is registered with a session (which requires that the class implements the interface). If it's not registered it won't be notified, no matter which interfaces it does or does not implement.
 
Lee Kian Giap
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay ,

1) HttpSessionListener

I got something as below:

public class MySessionClass implements HttpSessionListener {
....

public void sessionCreated(HttpSessionEvent event) {
// code run when notified
}

public void sessionDestroyed(HttpSessionEvent event) {
// code run when notified
}

}

for the above class , I must configure it in DD
<listener-class>
MySessionClass
</listener-class>


2)(a) HttpActivationListener

I got something as below:

public class Person implements HttpActivationSessionListener {
....

public void sessionWillPassivate(HttpSessionEvent event) {
// code run when notified
}

public void sessionDidActivate(HttpSessionEvent event) {
// code run when notified
}

}

and in the servlet :
...
Person p = new Person();
session.setAttribute("Person1",p);
...

2)(b) HttpActivationListener

I got something as below:

public class MyListenerClass implements HttpActivationSessionListener {
....

public void sessionWillPassivate(HttpSessionEvent event) {
// code run when notified
}

public void sessionDidActivate(HttpSessionEvent event) {
// code run when notified
}

}

and this type of listener does not have any configuration in DD <listener-class>

=================

for (1) , it is clear that when ever there is a change in session Attribute (i.e. session.setAttribute() or session.removeAttribute()) , it will be notified

=================

for (2)(a), It will be notified when session is passivate from one JVM and activate in another JVM because the Person object is set to session attribute

=================

for (2)(a), will this be notified ? If yes , when does it notified ???

=================


I ask this question is because when I come through HF book page264 , it mentioned that the HttpSessionActivationListerner usually implemented by
(i) an Attribute class ( so this is exactly the situation in above mentioned 2a)
(ii) some other class ( ... as above mentioned 2b , I was not able to figure out when does it be notified)

Please help !!

Thanks !!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic