I am re going through chapter 6 where i felt weak and now on page 260 here is a whole concept i am unable to understand. Please help me understanding it.
It says that
Session Migration and Serialization A container is required to migrate Serializable attributes(which assumes that all instances variables within the attribute are either Serializable or null.
But a Container is not required to use serialization as the mean of migrating HttpSession Object
What does that mean to you? Simple make sure you attribute class types are Serialzable and you never have to worry about it.
But if the yare not Serializable (which could be because on of the attribute object's instance varibales i snot Serializable), have your
attribute object class implement HttpSessionActivationListener and use the activation/passivation callsback to work around it.
The container is not required to use Serialization, so there's no guarantee that readObject() and writeObject() will be called on a
Serializable attribute or one of its instance variables!
If you are familiar with Serialization, you know that a class implements Serializable can also choose to implement a writeObject()method, called by the
VM container whenever an object is serialized and a readObject() method, called when an object is deserialized. A Serializable object can use these
methods to for example, set non-Serializable fields to null during Serialization(writeObject() and then restore the fields during deserialization(readObjet()).
But the methods won't necessarily be called during session migration! So if you need to save and restore instance variable state in your attribute, use
HttpSessionActivationListener, and use the two event calledbacks(sessionDidActivate() and sessionWillPassivate()) the way you would use readObjet()
Please help. I am totally lost in what the book is trying to tell.
Migration of sessions will be handled by container-specific facilities. If you want to be notified before a session is migrated (because, for instance, you need to close some connections) or after a session is migrated (because you need to setup some connections) let your objects implement the HttpSessionActivationListener.
In short: Session migration is moving the Session object from one JVM to another JVM.
But a Container is not required to use serialization
What they mean here is that the container is not required to use the "standard" java serialization mechanism (as described in "SCJP Sun Certified Programmer for Java 6 Exam, Sierra & Bates" Chapter 6 page 459), but the container provider can choose it's own mechanism for saving the state of objects in one JVM, transferring them, and recreating them on the other side (other JVM).
A container is required to migrate Serializable attributes
The one thing that the container provider is obliged to do is that it has to move all the objects, that implement the marker interface Serializable, in a Session to the other JVM.