• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does HttpSessionActivationListener relate to Serialization?

 
Mohit Jain
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers

In HFSJ page# 258 it says something about HttpSessionActivationListener as -

During session migration -

1. If attributes are Serializable, we probably don't need this listener.

2. This listener is mostly used to give attributes a chance to make their instance variables ready for Serialization.

Does this mean that for session migration attributes must be Serializable?? don't we require HttpSessionActivationListener then??

If attributes are not Serializable, will they not be transferred?? and then how does HttpSessionActivationListener fit into session migration??

How does session migration and Serialization relate to each other??

Please help me understand this.
[ December 25, 2007: Message edited by: Mohit Jain ]
 
vitesse wei
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you implement the serialization for attributes,when session was migrated to another JVM,those attribute will automatically be serialized the deserialized,you do not need to worry about it,but if you do not implement the serialization for you attributes,then you can use this listener to notified your attribute,and they can get ready before they are migrated and after they are migrated,the listener is a work-around for attribute serialization.
hope help you.
 
Mohit Jain
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vitesse wei:
If you implement the serialization for attributes,when session was migrated to another JVM,those attribute will automatically be serialized the deserialized,you do not need to worry about it,but if you do not implement the serialization for you attributes,then you can use this listener to notified your attribute,and they can get ready before they are migrated and after they are migrated,the listener is a work-around for attribute serialization.
hope help you.


My question is that - How does serialization help the process of attribute migration(with session)??

With non-serializable attributes, what's that extra THING this listener provides which enables attribute migration(within session) without serializability??

I feel these points are not well explained on page#258 in HFSJ.
Can somebody please provide a good explanation for this.
Thanks!!
 
S Vilish
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohit,
Suppose your web application is running in distributed environment where two or more application servers are used so that there is no zam in peak seasons like festivals. Now the load balancer may decide at any time (in order to balance the load)to responed to your request from a different server not at the same at which request was received initially. In distributed environment all major object e.g Product, Order should be serializble otherwise you will not be able to get them on different server after migration. These object should be attached to session for the purpose of application. Now there may be some other minor object not serializable needed in the process eg. product price. whcih is used in the session. Now if you use HttpSessionActivationListener, just before migrattion in sessionWillPassivate(), you can add these attibutes to some serilizedCollection object and in sessionDidActivate, retrieve them back so that they don't come as null.

Though i didn't the use of this listener but above assuption is based on a system i works. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic