I want a clear idea on Session Migration. The HFSJ book doesn't mention it clearly. When Session Migration is done, do all the attributes in HttpSession object need to be serialized. If not, should they be declared transient. If they need to be seriailized, does the object graph principle needs to be satisfied for all the attributes in the HttpSession object. The book mentions that HttpSessionActivationListener makes it work even if the instances of attributes in HttpSession object are not serialized. Also it mentions that some instances can be set to null. I was confused by reading the topic. Since this can be tested only in distributed environment, it would be helpful if any one could shed some light on this topic.
do all the attributes in HttpSession object need to be serialized. If not, should they be declared transient.
Session migration doesn't require all the attributes to be serialized. It is not required that if you do not serialize an attribute, they should be declared transient.
The book says that if an attribute is serialized during session migration the container is required to migrate it for sure. But it is not required for them to be migrated. We could have the attribute object class implement HttpSessionActivationListener and use sessionWillPassivate and sessionDidActivate to see you recieved the attribute object.
This might not have cleared all your doubts, but I guess it helped you a little.
First, when session migrates, it's required for the container to migrate the attributes that implement the Serializable interface. Other attributes may or may not be migrated. The thing about HttpSessionActivationListener is that attributes not implementing the Serializable interface may use this Listener to be notified of HttpSession migration events and then implement by themselves a way to migrate to the new VM.
Frederic, I have understood the same way which you have written. But one thing i don't understand is..
Ok let me explain this by giving a scenario:
Suppose, first time a user has requested an application, we have created a session object for him and placed some info in the session object. Suppose they are some attributes which are not serialized and i haven't implemented SessionActivationListener on that attribute. So by no means it is serialized.
Now suppose the user comes the next time and requests by sending the cookie or session id (whatever) with the request and the request this time has passed to a differnt JVM (different machine) then you migrate the session object which was on previous JVM to here. So how are going to restore the state, if some of the attributes in the session objects are not serialized.
Also Frederic, you didn't mention anything about how the object graph of an object. Does it matters or not.
I would appreciate if Marc or Fred looks into this issue.
Hi Pavan, We are using Weblogic 8.1 sp5 and we faced a problem with session migration issue in production. which can answer your question.
When an Object is migrated from one VM to Another, All the Objects required by the session, needs to be serialized, (it can be either manually serializable through listener or declaring an object implements serializable ).
if we are not doing so, When the user tries to communicate with session replicated server would result in Session drops, which ultimately results a server error and users gets a error page.
Guna<br />SCJP 1.4 86<br />SCWCD 1.4 94
Joined: Mar 08, 2006
Hi Varathan, Thank you very much. That helps me a lot. Could you please do me a favour by sending me the error message which you got when you were trying to access it.
Thanks, Pavan Kumar Tammana
Joined: Nov 11, 2005
Hi Pavan, I don't have a exact error message description, but this is the behaviour i understood from the problem.
User gets a http 500 error or java excepion page(mostly null pointer exception) depending on scenario. and inside the server, when we process the request, we search for the particular object in the session. if the object is missing(since it didnt migrated the object from the replicated source server), then it throws null pointer exception.
Joined: Mar 08, 2006
Hey Guna, Thank you very much. Pavan Kumar Tammana