• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

How can an object in one JVM call a method on an object in a different JVM (different machine)? Normal method calls only work within the same JVM. We need a mechanism that makes remote calls feel like local calls.

Core Idea

RMI is a Java mechanism that allows an object in one JVM to invoke methods on an object located in another JVM. It creates the illusion of local method calls by handling all network communication transparently through stubs and serialization.

How It Works

  1. Remote Interface defines methods that can be called remotely (extends Remote)
  2. Implementation class implements the interface (extends UnicastRemoteObject)
  3. Server registers the object with RMI Registry using Naming.rebind()
  4. Client looks up the object using Naming.lookup() and gets a stub
  5. Client calls method on stub
  6. Stub serializes parameters, sends request over network
  7. Server receives, deserializes, executes method
  8. Result is serialized and sent back
  9. Client deserializes and returns result

Visual Explanation

G Client JVM Client Stub Server JVM Skeleton Remote Object Client JVM->Server JVM Network (RMI-IIOP)

Key Properties

  • Location transparency: Client cannot tell if object is local or remote
  • Object serialization: Parameters/returns converted to byte streams
  • Stub/Skeleton: Client proxy and server proxy handle communication
  • RMI Registry: Naming service to locate remote objects
  • Garbage collection: Remote objects can be collected when no references exist
  • Security: Can use SecurityManager to control remote code execution

Connections

Edge Cases & Gotchas

  • Network failures can cause RemoteException
  • Serialization has performance cost
  • Pass-by-value for normal objects, pass-by-reference for Remote objects
  • Class must be available on both client and server
  • Not used much today — replaced by REST, gRPC, SOAP