Parameter Passing in Remote Method Invocation - rsanchez-wsu/jfiles GitHub Wiki
A parameter passed to a remote object can be of any type that is serializable, such as primitives and other remote objects. The rule applies to return values.
Passing Non-remote Objects
Non-remote objects that are passed to or returned by a remote method invocation are passed by copy. In other words, the object is serialized.
Passing Remote Objects
Remote objects passed to/by remote method invocations are passed as stubs with the exception of remote objects that are not exported. Remote objects that are passed as a parameter are only allowed to implement remote interfaces.
Referential Integrity
If two references to the same object are passed remotely from one JVM to another in a remote method call, those references refer to a single copy of the object in the receiver JVM.
Class Annotation
During a remote method call, the RMI system adds the class' uniform resource locator to the class descriptor in the call stream. Classes must be downloaded on demand when a remote method is invoked.
Parameter Transmission
Parameters to a call of any RMI function are written to a stream that is a subclass of java.io.ObjectOutputStream. The subclass overrides the replaceObject method to write the stubs of exported remote objects to the stream. Object parameters are written to the stream using the writeObject method from ObjectOutputStream. replaceObject is called for each object written to the stream using writeObject.
replaceObject returns the following:
- If the parameter passed to replaceObject was a remote object, and that object was exported, a stub of the remote object will be returned.
- If the parameter passed was a remote object that was not exported, the object itself is returned.
- If the parameter passed was not a remote object, the object itself is returned.
ObjectOutputStream employs the annotateClass method that inserts the location of the class onto the call stream so that the receiver may download it.
reference: https://docs.oracle.com/javase/7/docs/platform/rmi/spec/rmi-objmodel7.html