RMI Execution Compilation Distribution Stepwise

RMI Execution Compilation Distribution Stepwise

RMI application involves 4 programs (as illustrated in the first simple Interest Calculation application) and let us go for RMI Execution to see how to execute them to get the desired output step by step.

a) Compile all the 4 programs with javac command as usual as follows:

c\snr> javac Interest*.java

RMI Execution

This compiles all the 4 programs at a time and obtains 4 different .class files. Do not attempt to compile each program separately which sometimes says the remote interface is not available. To do so, set the classpath of JDK at the DOS prompt eventhough you set it in system environment variables.

b) Generate stub and skeleton

Creating RMI Stub and Skeleton

c\snr> rmic InterestImpl

The above rmi compiler (rmic stands for rmi compiler), generates stub and skeletons and they are .class files as follows:

i) InterestImpl_stub.class
ii) InterestImpl_skel.class

Observe, the stub and skeleton are generated on implementation file. From JDK 1.2, skeleton is not created with the introduction dynamic stubs creation. Even without skeleton generation, still your program works.

RMI Execution

Observe, I obtained only stub with RMI compiler.

c) Open two DOS prompts: one for server and one for client.

i) from the sever prompt, start rmi registry as follows:

c\snr> start rmiregistry


The second window is rmi registry.

The above command gets a window, minimize it and it must be working at the background as long as client and server communicates (like Tomcat server running all through the Servlet communication). It is a service between client and server. RMI registry can treated as a middleware component between client and server. For this reason, RMI is known as middleware technology. The other middleware technologies are CORBA (Common Object Request Broker Architecture) of OMG (Object Management Group) and DCOM (Distributed Component Model) of Microsoft.

ii) from the same server prompt, run the server program as follows:

c\snr> java InterestServer


Observe, the DOS prompt is not terminated, means, the server is waiting for the requests from client. When client request comes and honoured, the prompt terminates.

iii) from the client prompt, run the client program and we will get output as follows(at client DOS prompt).

c\snr> java InterestClient


You can see the output at client prompt as in the above screenshot.

What is file distribution in RMI?

From the above notes, you come to know now there are many files comprising a RMI application like four .class files, rmi registry, stub and skeleton. Now which file should be placed on client side and server side for smooth communication comprises file distribution in RMI.

It is easy to remember, just remind yourself
With client side statement: Interest i2 = (Interest) Naming.lookup(“roses”) which implies client requires Remote interface.
With server side statement: Interest i1= new InterestImpl() which implies server requires Remote interface and Implementation file. Now make table as follows.

Client side Server side
Remote interface Remote interface
Implementation file
Stub Skeleton
Remote registry
Client program Server program

Now observe, the implementation file comes to server side. That is, client does not have the implementation of abstract methods. So when client invokes a remote method, the method is executed on server side (and not on client side).

Learn another RMI application with database access and setting security manager etc.

Leave a Reply

Your email address will not be published. Required fields are marked *