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

 
bernard savary
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Ranchers,
I have a question regarding HttpSessionActivationlistener , In HF they mention that the class that implements a HttpSessionActivationlistener is mostly the attribute class that would be bound to a session . In that case lets say there are 2 sessions session A & session B and a attribute clas object obj1 which is only bound to session B . Suppose now only session A is going to be passivated then the attribute object is atill notified and may do some kind of its own passivation depending on user code but this would mean that its doing something unecessary , Am i correct ? Please let me know .
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2 sessions session A & session B

Two sessions ? How would you do that ? If you're talking of two different users, then you're probably talking of two different objects in two different sessions, otherwise what would be the point in setting that object in a session in the first place ? Such an object would be put in application scope, not session scope.
 
bernard savary
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Christophe ,
lets say 2 different objects a and b that would would be bound to session A and B . now a and b are implementing HTTPSessionActivationListener not just a HTTPSessionBindingListener , so even if session A is passivated then object b is notified because it is a listener for activation/passivation of any session .Am I right ?
 
Neeraj Singhal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so even if session A is passivated then object b is notified because it is a listener for activation/passivation of any session


Agreed that a and b are listeners for activation/passivation, but NOT for "any session". ONLY for the session(s) with which they are bound.

So when session A is passivated, all the objects bound to session A are notified.

Thanks
Neeraj
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I support what Neeraj says. When sessionA is passivated, the container does not look in sessionB. It only notifies objects in sessionA. Would it make sense not notify objects not being passivated ?
 
bernard savary
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So that means I cannot have a seperate HTTPSessionActivation listener right ? i.e An object which is not bound to any session but serves only as a listener .
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An object which is not bound to any session but serves only as a listener

Nope.

HTTPSessionActivationListener :
Objects that are bound to a session may listen to container events notifying them
that sessions will be passivated and that session will be activated. A container that
migrates session between VMs or persists sessions is required to notify all
attributes bound to sessions
implementing HttpSessionActivationListener.
 
bernard savary
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank thats crystal clear now!
 
Chris Duerr
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,

I was concerned with the same probleme for a while. And this was mainly because the HF states a HttpSessionActivationListener can be both, an attribute class instance bound to a session AND "some other class". They even give an example on that (HF SCWCD pp. 261).

That's confusing and may explain bernards original post. By now I guess the HF is wrong - only attribute classes can implement HttpSessionActivationListener in a meaningful way.

Justification:

1) The spec says that and nothing else.
2) I tried it with Tomcat, attribute classes where triggered correctly, "some other classes", properly declared in the DD, not. OK, I didn't run a cluster to test this. I redeployed a single instance to trigger the passivation and activation of the session, thus the test is not perfect.
3) What will happen, if the attribute class has not the no-arg constructor and is registered as HttpSessionActivationListener in the DD (as suggested in the HF)? How will the container create an instance to call its methods?

Has anyone out there ever seen a HttpSessionActivationListener declared in the DD but not bound to a session triggered?

Chris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic