| CONTENTS | PREV | NEXT | Java Remote Method Invocation |
An argument to, or a return value from, a remote object can be any object that is serializable. This includes primitive types, remote objects, and non-remote objects that implement thejava.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.
2.6.1 Passing Non-remote Objects
A non-remote object, that is passed as a parameter of a remote method invocation or returned as a result of a remote method invocation, is passed by copy; that is, the object is serialized using the object serialization mechanism of the Java platform.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.
2.6.2 Passing Remote Objects
When passing an exported remote object as a parameter or return value in a remote method call, the stub for that remote object is passed instead. Remote objects that are not exported will not be replaced with a stub instance. A remote object passed as a parameter can only implement remote interfaces.
2.6.3 Referential Integrity
If two references to an object are passed from one JVM to another JVM in parameters (or in the return value) in a single remote method call and those references refer to the same object in the sending JVM, those references will refer to a single copy of the object in the receiving JVM. More generally stated: within a single remote method call, the RMI system maintains referential integrity among the objects passed as parameters or as a return value in the call.
2.6.4 Class Annotation
When an object is sent from one JVM to another in a remote method call, the RMI system annotates the class descriptor in the call stream with information (the URL) of the class so that the class can be loaded at the receiver. It is a requirement that classes be downloaded on demand during remote method invocation.
2.6.5 Parameter Transmission
Parameters in an RMI call are written to a stream that is a subclass of the classjava.io.ObjectOutputStreamin order to serialize the parameters to the destination of the remote call. TheObjectOutputStreamsubclass overrides thereplaceObjectmethod to replace each exported remote object with its corresponding stub instance. Parameters that are objects are written to the stream using theObjectOutputStream'swriteObjectmethod. TheObjectOutputStreamcalls thereplaceObjectmethod for each object written to the stream via thewriteObjectmethod (that includes objects referenced by those objects that are written). ThereplaceObjectmethod of RMI's subclass ofObjectOutputStreamreturns the following:
- If the object passed to
replaceObjectis an instance ofjava.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 ofjava.rmi.Remoteand the object is not exported to the RMI runtime, thenreplaceObjectreturns the object itself. A stub for a remote object is obtained via a call to the methodjava.rmi.server.RemoteObject.toStub.- If the object passed to
replaceObjectis not an instance ofjava.rmi.Remote, then the object is simply returned.RMI's subclass ofObjectOutputStreamalso implements theannotateClassmethod 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 howannotateClassis used.Since parameters are written to a single
ObjectOutputStream, references 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 singleObjectInputStream.Any other default behavior of
ObjectOutputStreamfor writing objects (and similarlyObjectInputStreamfor reading objects) is maintained in parameter passing. For example, the calling ofwriteReplacewhen writing objects andreadResolvewhen 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
ObjectOutputStreamand has the same replacement behavior as parameter transmission.
CONTENTS | PREV | NEXT
Copyright © 1997-2001 Sun Microsystems, Inc. All Rights Reserved.