Serialization and Checkpointing

All modules are serializable. Serialization is a feature of Java that allows an instance of a class to be converted to a stream of binary data in a platform independent way. Serialized forms of Java modules can be saved to disk or transmitted over a network.

D2K modules are serializable, however, we do not use serialization to save D2K modules in itineraries. When Java classes are serialized they are saved with a serialized version ID that changes whenever any of their method names, fields name or class structure in general are changed. So, just about any time you change a Java class, this serial version id changes. The problem is old instances saved before the changes can no longer be read. If we saved serialized modules in the itineraries, every time any of the modules in that itinerary changed, the itinerary could no longer be read in, and it would have to be reconstructed.

So when we save an itinerary, we save only the properties of the modules rather than serializing the modules themselves. In this way, it is not necessary to serialize the modules, and we can change them without corrupting any itinerary that contains them. Yet it ensures that any properties that have been set will be saved.

However, there are many times where longer-term persistence is not an issue, and in these case we do employ serialization. For running D2K on more than one machine, modules will be moved, by the system, from one machine to another. Serialization is used for this. Another good example is checkpointing (version 3.0). Checkpoints are actually saved in the same format as itineraries, however, the modules are actually serialized and included in the output file.

So, even though serialization is not used when saving D2K itineraries, it is very important that we understand it and develop our modules in such a way that they will serialize properly. There is some Sun documentation on the Java web site. If a Java object is be be serializable, all objects that it contains which are not transient must also be serializable. For fields that should not be serialized, use the transient keyword.