RMI

Remote Method Invocation (RMI):

 It is a distributed systems technology that allows one Java Virtual Machine (JVM) to invoke object methods that will be run on another JVM located elsewhere on a network.

Stub skeleton

       Figure: The RMI client stub calls the RMI server skeleton.
  1. The skeleton object is responsible for listening for incoming RMI requests from the stub object and passing these requests on to the RMI service.
  2. The skeleton object passes the results back to the stub object in the RMI client.
  3. Communication occurs between stub and skeleton using TCP sockets

Steps to implement RMI:

1. Define the RMI service interface. It should extend the java.rmi.Remote interface and the methods should throws RemoteException.

2. Create the server class that:

                          a. Export the remote object using exportObject method: 

                                                         UnicastRemoteObject.exportObject(lBankAccount, 0);

                          b. Register (rebind) the service in the rmiregister, so other clients can access it.       

                                                          Naming.rebind(url, stub);

 3. Create the client class. The client obtains the object reference to the remote interface using lookup in the rmiregistry.           

                                                         Naming.lookup (url);

The following is an example of RMI Bank Account application, The server supplies operations (deposit, withdraw and getDeposit) to be called remotely by the Client on  the bank account. 

The Server Application:

The Client Application:

Running the RMI System:

Youtube link for the tutorial: 

https://www.youtube.com/watch?v=N_6c0zsbdSQ

  1. Copy the necessary file (BankAccount interface) to a directory on the local file system of all clients and the server.
  2. Compile both Server and Clien application using command javac *.java
  3. Run the rmiregistry application, using command: rmiregistry.Rmiregistry
  4. In a separate console window, run the server.Runserver
  5. In a separate console window, and preferably a different machine, run the client.

Runclient

Add a comment