wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HttpSessionActivationListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HttpSessionActivationListener" Watch "HttpSessionActivationListener" New topic
Author

HttpSessionActivationListener

Andy Smith
Ranch Hand

Joined: Sep 28, 2003
Posts: 239
Whats the use of HttpSessionActivationListener. I know that this is to be used for Distributed enviroments, but i dont have much ideas ....


Share Knowledge to gain it.
SCJP 2, SCWCD 2, SCDJWS, IBM 141 (In Progress), IBM 486 (Next)
maneesh subherwal
Ranch Hand

Joined: Aug 26, 2002
Posts: 42
Andy,
The HttpSessionActivationListener is used for monitoring sessions on the server. When a session is activated, Notification that the session has just been activated will be received by the SessionDidActivate Method and when the session is about to be destroyed, the sessionWillPassivate is used.
Objects that are bound to the session can be initialised or destroyed based upon the listener. Also, when the session migrates between servers, the sessionwillpassivate is called and once it is successfully moved, the sessionDidActivate will be called. It is interesting to note that the sesssion is not yet ready for service at the time the sessionDidActivate method is called.
hope this helps...
Thanks,
Maneesh


Sun Certified Java Programmer 2 (1.4)<br />Sun Certified Web Component Developer
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Here I got sthing from the servlet 2.4 Specification... I think it's useful for you too..
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.

We just use it to be notified about the sessions travelling aroung the JVMs, if I am not wrong...
Any other suggestions are welcome too...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Andy Smith
Ranch Hand

Joined: Sep 28, 2003
Posts: 239
What are the diffenerent scenarios when a servlet can passivate a session??
Is there any case besides migration?
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
I don't think a servlet can passivate sessions, Andy... And also there is only one case that the notification will happen only when the sessions are migrated around JVMs...
It's good to share knowledge like this...
Andy Smith
Ranch Hand

Joined: Sep 28, 2003
Posts: 239
Thanx Naing..
Yes this s the great way to share the knowledge... and i m learning a lot by this way.. i would like other to encourage and participate more.. this would also improve ur thinking process..
I have read some where on some JRun tutorial..
********************
Understanding the HttpSessionActivationListener
When sessions are activated or passivated, JRun notifies the HttpSessionActivationListener.
Passivation occurs when JRun does not invalidate a session, but backs it up to disk to free up resources, or when a "mirrored" JRun server fails and another JRun server picks up its sessions. This is also called session persistence.
Activation occurs when the client with a passivated session makes a request and the session must be retrieved from disk or loaded into a new JRun server.
The following example of a simple HttpSession event listener implements the methods of the HttpSessionActivationListener interface. When one of these events occurs, a line is printed to the standard output.
...
public void sessionWillPassivate(HttpSessionEvent event) {
System.out.println("Session was passivated");
}
public void sessionDidActivate(HttpSessionEvent event) {
System.out.println("Session was activated");
}
************************

So I think that sessions can be passivated in more then one way..
at least to free up the resources.. in addition to migration..
Naing wat do u say??
Any other idea from any one??

[ November 26, 2003: Message edited by: Andy Smith ]
maneesh subherwal
Ranch Hand

Joined: Aug 26, 2002
Posts: 42
i think Andy is correct about sessions being passivated when they are not being used for sometime to free up resources. However, I think the major use is when the sessions are migrated from one server to another. The sessionwillpassivate is called in the first server and the sessionDidActivate is called in the second server. This is used when serialized objects exist in the session. If you do contain an object in the session that contains transient values, I believe they will not be transferred over.
I hope this helps.
Thanks,
Maneesh
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Andy Smith:

Passivation occurs when JRun does not invalidate a session, but backs it up to disk to free up resources, or when a "mirrored" JRun server fails and another JRun server picks up its sessions. This is also called session persistence.
Activation occurs when the client with a passivated session makes a request and the session must be retrieved from disk or loaded into a new JRun server.
[ November 26, 2003: Message edited by: Andy Smith ]

Hi Andy,
I think it's App Server specific implementation... JBoss is trying to modify the specification and implements on its own way on HttpSessionActivationListener to make better usage on it... :roll:
I think since the situation, in which sessions are travelling around the JVMs looks like the situation, in which sessions are travelling to and from between the disk and server, JBoss then applied this concept... It's just my opinion on it... I'm not very sure about that... :roll:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpSessionActivationListener