Java RMI or Remote Method Invocation is an example of Remote Procedure Call (RPC) enabling client program to locate the server object and remotely invoke the methods from server through server’s stub and skeleton function. Java RMI is usually referred to Distributed Object rather than RPC. This is because Java natively is object oriented programming. So we say object as a whole. Moreover, RPC somehow is mentioned to procedural programming.
The main Java RMI component consists of 3 elements:
- Invoke method on remote object
- Process that owns remote object
- Name server that relates objects with unique names
From the figure above, we can see the process of Java RMI is divided into 4 steps:
- Instantiate server object and then register it to RMI registry service with unique name
- Client program locates server object from RMI registry service with associated name
- Once server object is found is RMI registry, RMI registry returns server stub
- Server stub handles the data communication with Server skeleton on server side. Be remember that, server stub and skeleton do marshalling and unmarshalling
From here I would describe each detail element in the figure.
- Server Object Interface
- An interface defines the methods for the server object
- Server Object
- An instance of the server object interface
- Server Stub
- An object that resides on the client host and serves as a representative of the remote server object
- Server Skeleton
- An object that resides on the server host. It communicates with the stub and the actual server object
- RMI Registry
- It is service to register remote objects and to provide naming services for locating objects
- Client program
- A program that invokes the methods in the remote server object
Be sure you understand the process of Java RMI before we are moving to the implementation. Any question or comment would be welcome.