In Chapter 10, while discussing how RMI customizes the serialization algorithm, I said:
annotateClass( )when it writes out class descriptions. Annotations are used to provide extra information about a class that comes from the serialization mechanism and not from the class itself. The basic serialization mechanism has no real need for annotations; most of the information about a given class is already stored in the stream...
RMI, on the other hand, uses annotations to record codebase information. That is, RMI, in addition to recording the class descriptions, also records information about the location from which it loaded the class’s bytecode.
These paragraphs, which may have seemed opaque before, should now make more sense. RMI’s dynamic classloading is based on two ideas:
If an object is serialized and sent over the wire, the required class definitions might not be available on the other side.
Automatically including URLs from which
classes can be downloaded inside serialized
objects allows special-purpose classloaders, such
URLClassLoader class, to automatically
load classes from over the wire when they’re
needed to deserialize an object.
The basic algorithm, which is built into RMI’s deserialization mechanism, works as follows:
An instance is sent over the wire. As part of the serialized information about the instance, all the related class definitions are also sent over the wire (including the definitions of ...