What is Java RMI
Java Remote Method Invocation is a Java API that performs object-oriented equivalent of remote procedure calls, with support for direct transfer of serialized Java classes and distributed GC. RMI can be seen as the process of activating a method on remote running object.
At a high-level prospective, Java RMI consists of several well-split layers:
-
Application Layer
Provides remote interface.
-
Stub/Proxy Layer
This layer automatically handles method invocation marshalling and unmarshalling, network transmission.
-
Remote Reference Layer
-
Transport Layer
Provides TCP-based communication for RPC.
Example
Remote Interface
Defines methods callable remotely.
1 | import java.rmi.Remote; |
Remote Object Implementation
Implement the interface defined and extend the remote object class.
1 | import java.rmi.server.UnicastRemoteObject; |