Question 5 of 15 · CIE-1 QB · 7 marks
Open in ChatGPTWhat is Remote Method Invocation (RMI)? Explain its working and compare it with RPC.
Introduction
Remote Method Invocation (RMI) is the object-oriented extension of RPC. In RPC a program calls a procedure on another machine; in RMI it invokes a method on a remote object, and the object stays alive on the server between calls with its own state.
Working of RMI
- The server registers its remote object in a registry (rmiregistry) under a name.
- The client looks up the name and receives a remote reference: a stub that implements the same interface.
- The client calls a method on the stub. The stub marshals the method name and arguments, marshalling objects by serialization.
- The skeleton (server side) unmarshals the call and invokes the method on the real object.
- The return value is marshalled back, and the client stub returns it to the caller as if it were local.
- Any exception on the server is propagated to the client as a remote exception.
Diagram
RPC vs RMI
| Point | RPC | RMI |
|---|---|---|
| Unit called | A procedure or function | A method on a remote object |
| State | Stateless; each call is independent | The remote object keeps state between calls |
| Arguments | Passed by value, in a flat marshalled form | Objects passed by value (serialized) or by reference (remote reference) |
| Interface definition | IDL or a protocol definition | A Java (or IDL) interface shared by client and server |
| Location | Server address is explicit | Object is found through a registry or naming service |
| Examples | Sun RPC, gRPC, XML-RPC | Java RMI, CORBA objects, .NET Remoting |
Example
A banking application exposes Account.getBalance() as a remote object. The client looks up Account in the registry, then calls getBalance(); the object on the server holds the account's state, so the client does not resend the account data on every call.
Conclusion
RMI adds object identity and state to RPC's call transparency. Choose RPC for stateless function-style services, and RMI when the remote entity has state that must persist across calls.