Java Language Remote Method Invocation (RMI)

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Remarks

RMI requires 3 components: client, server and a shared remote interface. The shared remote interface defines the client-server contract by specifying the methods a server must implement. The interface must be visible to the server so that it can implement the methods; the interface must be visible to the client so that it knows which methods ("services") the server provides.
Any object implementing a remote interface is destined to take the role of a server. As such, a client-server relationship in which the server can also invoke methods in the client is in fact a server-server relationship. This is termed callback since the server can call back the "client". With this in mind, it is acceptable to use the designation client for the servers that function as such.

The shared remote interface is any interface extending Remote. An object that functions as a server undergoes the following:

  1. Implements the shared remote interface, either explicitly or implicitly by extending UnicastRemoteObject which implements Remote.
  2. Exported, either implicitly if it extends UnicastRemoteObject, or explicitly by being passed to UnicastRemoteObject#exportObject.
  3. Binded in a registry, either directly through Registry or indirectly through Naming. This is only necessary for establishing initial communication since further stubs can be passed directly through RMI.

In the project setup, the client and server projects are completely unrelated, but each specifies a shared project in its build path. The shared project contains the remote interfaces.



Got any Java Language Question?