Q19Distributed Systems
Question
Explain the mechanisms of Remote Method Invocation (RMI) in distributed computing. How does it differ from RPC? Explain with the help of a diagram.
Answer
An exhaustive theoretical breakdown of Remote Method Invocation (RMI). Violently contrasts the purely procedural nature of RPC against the massive Object-Oriented architecture of Java RMI, detailing the execution of Stubs, Skeletons, and distributed Garbage Collection.
RPC (Remote Procedure Call) was designed for primitive C programs, allowing a local machine to execute a procedural function on a remote machine. RMI (Remote Method Invocation), pioneered by Java, represents a massive architectural leap. It completely integrates distributed computing with strict Object-Oriented paradigms, allowing a program on Node A to violently invoke methods on an Object physically residing in the RAM of Node B, passing complex objects (not just primitive integers) by value or reference.
The absolute core of RMI is achieving total transparency through Proxy objects.
- The Stub (Client-Side Proxy): The client program does not talk to the network. It calls a method on a local
Stubobject. The Stub acts as a violent interceptor. It mathematically serializes the method name and complex object parameters into a flat binary stream (Marshalling) and blasts it via TCP to the server. - The Skeleton (Server-Side Proxy): The server network socket passes the byte stream to the
Skeleton. The Skeleton violently unmarshals the binary back into Java Objects, locates the actual target Object in server RAM, and invokes the physical method. The return value is marshalled and sent backward through the pipeline.
- Paradigm: RPC is Procedural (invokes flat functions). RMI is Object-Oriented (invokes methods on specific instantiations of objects with state).
- Parameter Passing: RPC can only pass primitive structs by value. RMI can mathematically pass massive, complex Object Graphs by value (Serialization) OR pass remote object references. If RMI passes a reference, the client can mathematically invoke methods on the returned object, creating a massive chain of distributed execution.
- Distributed Garbage Collection: Because RMI objects exist across networks, Java must execute Distributed Garbage Collection. The server mathematically tracks leased references; if a client disconnects or times out, the server violently purges the object from RAM to prevent catastrophic memory leaks.