aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HttpSessionActivationListener example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HttpSessionActivationListener example" Watch "HttpSessionActivationListener example" New topic
Author

HttpSessionActivationListener example

Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
Hello,

On page 260 of HFSJ it is given that

"A container is required to migrate Serializable attributes,but a container is not required to use serialization as the means for migrating the HttpSession object"

That I understood ,but further it says "make sure your attribute class types are serializable .But if they are not serializable ,have your attribute object class implement HttpSessionActivationListener and use the activation/passivation callbacks to work around it"

My question is how can we do the above? Any example? Do they mean if attribute is not serializable,but if it implements HttpSessionActivationListener it automatically becomes seriallized object? Is my understanding correct?I understood that purpose of having HttpSessionActivation listener is to notify attributes about the migration of HttpSession to different VM.But I didn't understand about seriallizing attribute instance variables part.Can anybody explain with example if possible?


SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Patil Niteen
Ranch Hand

Joined: Dec 10, 2009
Posts: 48

Veena Pointi wrote:
but further it says "make sure your attribute class types are serializable .But if they are not serializable ,have your attribute object class implement HttpSessionActivationListener and use the activation/passivation callbacks to work around it"




SCJP 1.4, SCWCD 5
Patil Niteen
Ranch Hand

Joined: Dec 10, 2009
Posts: 48

Patil Niteen wrote:
Veena Pointi wrote:
but further it says "make sure your attribute class types are serializable .But if they are not serializable ,have your attribute object class implement HttpSessionActivationListener and use the activation/passivation callbacks to work around it"




The above statement in the quotes says that:
If the attributes are serializable , the container takes care of the migration of the attributes. If the attributes are not serializable , its upto the user to implement the serialization functionality in the activation/passivation callbacks methods after implementing HttpSessionActivationListener.

Correct me if I am wrong!
Patil Niteen
Ranch Hand

Joined: Dec 10, 2009
Posts: 48

Do they mean if attribute is not serializable,but if it implements HttpSessionActivationListener it automatically becomes seriallized object? Is my understanding correct?

No, the attribute object doesn't become a seriallized object automatically after implementing HttpSessionActivationListener . HttpSessionActivationListener provides two methods void sessionDidActivate(HttpSessionEvent se) and void sessionWillPassivate(HttpSessionEvent se) for the purpose of notification of activation and passivation of the session object during migration.

Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
Thank you for replieng.I could understand your explanation.

If the attributes are not serializable , its upto the user to implement the serialization functionality in the activation/passivation callbacks methods after implementing HttpSessionActivationListener.


My question is how do we implement serialization functionality in the activation/passivation callbacks ?Let us take following Dog object with name "abc"

Dog dg = new Dog("abc");
session.setAttribute("dog"dg);

Assuming that dg is not seriallized ,how do we make use of activation/passivation callbacks to seriallize it ?
Patil Niteen
Ranch Hand

Joined: Dec 10, 2009
Posts: 48

Hi,

My question is how do we implement serialization functionality in the activation/passivation callbacks ?Let us take following Dog object with name "abc"

Dog dg = new Dog("abc");
session.setAttribute("dog"dg);

Assuming that dg is not seriallized ,how do we make use of activation/passivation callbacks to seriallize it ?



The Dog class can be written as:

public class Dog implements HttpSessionActivationListener {

private String name;

public void sessionWillPassivate(HttpSessionEvent se) {

//write code to get the non-serializable field in a state that can survive a move to a new VM(searilize)
}

public void sessionDidActivate(HttpSessionEvent se) {

//code to restore the state of the field.(deserialize)

}

}
In this way we can monitor the session states using the HttpSessionActivationListener.
Thanks,
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Have a look on here


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpSessionActivationListener example