(PDC) Lecture 10 - Remote Method Invocation (RMI)
(PDC) Lecture 10 - Remote Method Invocation (RMI)
Invocation (RMI)
• Defines: The methods that the remote object will expose to the clients.
• Extends: java.rmi.Remote interface.
• Methods: Declared with the throws RemoteException to handle remote exceptions.
RMI Server Side
The server-side of Remote Method Invocation (RMI) is the RMI registry. The RMI registry is
a namespace that contains all remote server objects, each with a unique bind name. It allows
remote clients to get a reference to these objects.
• Implements: The remote interface.
• Creates: An instance of the remote object.
• Binds: The object to the RMI registry using java.rmi.registry.Registry to make it
available for clients.
RMI Client Side
Through RMI, an object running in a JVM present on a computer (Client-side) can invoke
methods on an object present in another JVM (Server-side).
• Locates: The remote object using the RMI registry.
• Obtains: The stub (proxy object representing the remote object).
• Invokes: Methods on the stub as if they were local.
How to Run RMI:
Compile all three files separately using java:
• javac MyRemoteInterface.java
• javac MyServer.java
• javac MyClient.java
In a terminal or command prompt, start the RMI registry:
• start rmiregistry (Windows)
• rmiregistry & (Unix/Linux)