It Is Easy to Send More Data Than Is Required

• The description of the ValueObject class • The description of the Money class • The instance data associated with the specific instance of Money . This isnt a lot of information, but its information that RMI computes and sends with every method invocation. [ 7] Even if the first two bullets comprise only 100 extra bytes of information, the cumulative impact is probably significant. [ 7] Recall that RMI resets the serialization mechanism with every method call. The second problem is that each serialized instance is treated as an individual unit. If we are sending large numbers of instances within a single method invocation, then there is a fairly good chance that we could compress the data by noticing commonalities across the instances being sent.

10.6.3 It Is Easy to Send More Data Than Is Required

Serialization is a recursive algorithm. You pass in a single object, and all the objects that can be reached from that object by following instance variables, are also serialized. To see why this can cause problems, suppose we have a simple application that uses the Employee class: public class Employee implements Serializable { public String firstName; public String lastName; Public String socialSecurityNumber; } In a later version of the application, someone adds a new piece of functionality. As part of doing so, they add a single additional field to Employee : public class Employee implements Serializable { public String firstName; public String lastName; Public String socialSecurityNumber; Public Employee manager; } What happens as a result of this? On the bright side, the application still works. After everything is recompiled, the entire application, including the remote method invocations, will still work. Thats the nice aspect of serialization™we added new fields, and the data format used to send arguments over the wire automatically adapted to handle our changes. We didnt have to do any work at all. On the other hand, adding a new field redefined the data format associated with Employee . Because serialVersionUID wasnt defined in the first version of the class, none of the old data can be read back in anymore. And theres an even more serious problem: weve just dramatically increased the bandwidth required by remote method calls. Suppose Bob works in the mailroom. And we serialize the object associated with Bob. In the old version of our application, the data for serialization consisted of: • The class information for Employee • The instance data for Bob In the new version, we send: • The class information for Employee • The instance data for Bob • The instance data for Sally who runs the mailroom and is Bobs manager • The instance data for Henry who is in charge of building facilities • The instance data for Alison Director, Corporate Infrastructure • The instance data for Mary VP in charge of IT And so on... The new version of the application isnt backwards-compatible because our old data cant be read by the new version of the application. In addition, its slower and is much more likely to cause network congestion.

10.7 The Externalizable Interface