CONTENTS | PREV | NEXT | Java Remote Method Invocation |
When parameters and return values for a remote method invocation are unmarshalled to become live objects in the receiving JVM, class definitions are required for all of the types of objects in the stream. The unmarshalling process first attempts to resolve classes by name in its local class loading context (the context class loader of the current thread). RMI also provides a facility for dynamically loading the class definitions for the actual types of objects passed as parameters and return values for remote method invocations from network locations specified by the transmitting endpoint. This includes the dynamic downloading of remote stub classes corresponding to particular remote object implementation classes (and used to contain remote references) as well as any other type that is passed by value in RMI calls, such as the subclass of a declared parameter type, that is not already available in the class loading context of the unmarshalling side.
To support dynamic class
loading, the RMI runtime uses special subclasses of
java.io.ObjectOutputStream
and
java.io.ObjectInputStream
for the marshal streams that
it uses for marshalling and unmarshalling RMI parameters and return
values. These subclasses respectively override the
annotateClass
method of
ObjectOutputStream
and the resolveClass
method of ObjectInputStream
to communicate information
about where to locate class files containing the definitions for
classes corresponding to the class descriptors in the stream.
For every class
descriptor written to an RMI marshal stream, the
annotateClass
method adds to the stream the result of
calling
java.rmi.server.RMIClassLoader.getClassAnnotation
for
the class object, which may be null
or may be a
String
object representing the codebase URL path (a
space-separated list of URLs) from which the remote endpoint should
download the class definition file for the given class.
For every class
descriptor read from an RMI marshal stream, the
resolveClass
method reads a single object from the
stream. If the object is a String (and the value of the
java.rmi.server.useCodebaseOnly
property is not
true
), then resolveClass
returns the
result of calling RMIClassLoader.loadClass
with the
annotated String
object as the first parameter and the
name of the desired class in the class descriptor as the second
parameter. Otherwise, resolveClass
returns the result
of calling RMIClassLoader.loadClass
with the name of
the desired class as the only parameter.
See the section "The RMIClassLoader Class" for more details about class loading in RMI.