|CONTENTS | PREV | NEXT||Java Remote Method Invocation|
java.io.Serializableinterface. For more details on how to make classes serializable, see the "Java Object Serialization Specification." Classes, for parameters or return values, that are not available locally are downloaded dynamically by the RMI system. See the section on "Dynamic Class Loading" for more information on how RMI downloads parameter and return value classes when reading parameters, return values and exceptions.
So, when a non-remote object is passed as an argument or return value in a remote method invocation, the content of the non-remote object is copied before invoking the call on the remote object.
When a non-remote object is returned from a remote method invocation, a new object is created in the calling virtual machine.
java.io.ObjectOutputStreamin order to serialize the parameters to the destination of the remote call. The
ObjectOutputStreamsubclass overrides the
replaceObjectmethod to replace each exported remote object with its corresponding stub instance. Parameters that are objects are written to the stream using the
replaceObjectmethod for each object written to the stream via the
writeObjectmethod (that includes objects referenced by those objects that are written). The
replaceObjectmethod of RMI's subclass of
ObjectOutputStreamreturns the following:
replaceObjectis an instance of
java.rmi.Remoteand that object is exported to the RMI runtime, then it returns the stub for the remote object. If the object is an instance of
java.rmi.Remoteand the object is not exported to the RMI runtime, then
replaceObjectreturns the object itself. A stub for a remote object is obtained via a call to the method
replaceObjectis not an instance of
java.rmi.Remote, then the object is simply returned.
ObjectOutputStreamalso implements the
annotateClassmethod that annotates the call stream with the location of the class so that it can be downloaded at the receiver. See the section "Dynamic Class Loading" for more information on how
Since parameters are
written to a single
that refer to the same object at the caller will refer to the same
copy of the object at the receiver. At the receiver, parameters are
read by a single
Any other default
ObjectOutputStream for writing objects
ObjectInputStream for reading objects)
is maintained in parameter passing. For example, the calling of
writeReplace when writing objects and
readResolve when reading objects is honored by
RMI's parameter marshal and unmarshal streams.
In a similar manner to
parameter passing in RMI as described above, a return value (or
exception) is written to a subclass of
ObjectOutputStream and has the same replacement
behavior as parameter transmission.