|CONTENTS | PREV | NEXT||Java Remote Method Invocation|
Call and return data in RMI calls are formatted using the Java Object Serialization protocol. Each method invocation's CallData is written to a Java object output stream that contains the ObjectIdentifier (the target of the call), an Operation (a number representing the method to be invoked), a Hash (a number that verifies that client stub and remote object skeleton use the same stub protocol), followed by a list of zero or more Arguments for the call.
In the JDK1.1 stub protocol the Operation represents the method number as assigned by rmic, and the Hash was the stub/skeleton hash which is the stub's interface hash. As of the Java 2 stub protocol (Java 2 stubs are generated using the
rmic), Operation has the value -1 and the Hash is a hash representing the method to call. The hash is described in the section "The
ObjectIdentifier Operation Hash Argumentsopt
Number Time Count
A ReturnValue of an RMI call consists of a return code to indicate either a normal or exceptional return, a UniqueIdentifier to tag the return value (used to send a
DGCAckif necessary) followed by the return result: either the Value returned or the Exception thrown.
0x01 UniqueIdentifier Valueopt
0x02 UniqueIdentifier Exception
Note - ObjectIdentifier, UniqueIdentifier, and EndpointIdentifier are not written out using default serialization, but each uses its own special write method (this is not the writeObject method used by object serialization); the write method for each type of identifier adds its component data consecutively to the output stream.
RMI overrides the
ObjectInputStreamrespectively. Each class is annotated with the codebase URL (the location from which the class can be loaded). In the
annotateClassmethod, the classloader that loaded the class is queried for its codebase URL. If the classloader is non-
nulland the classloader has a non-
nullcodebase, then the codebase is written to the stream using the
ObjectOutputStream.writeObjectmethod; otherwise a
nullis written to the stream using the
writeObjectmethod. Note: as an optimization, classes in the "
java" package are not annotated, since they are always available to the receiver.
The class annotation is resolved during deserialization using the
resolveClassmethod first reads the annotation via the
ObjectInputStream.readObjectmethod. If the annotation, a codebase URL, is non-
null, then it obtains the classloader for that URL and attempts to load the class. The class is loaded by using a
java.net.URLConnectionto fetch the class bytes (the same mechanism used by a web browser's applet classloader).