0% found this document useful (0 votes)
4 views4 pages

Chpater 2 - Case Study Java Rmi

The document explains Remote Method Invocation (RMI) in Java, which allows objects to invoke methods on remote objects in different JVMs using stub and skeleton objects for communication. It outlines the requirements for distributed applications and provides a step-by-step guide to creating an RMI application, including defining a remote interface and implementing it. The document emphasizes the elimination of skeletons in Java 2 SDK and details the process of client-server interaction in RMI applications.

Uploaded by

naincyphotos1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Chpater 2 - Case Study Java Rmi

The document explains Remote Method Invocation (RMI) in Java, which allows objects to invoke methods on remote objects in different JVMs using stub and skeleton objects for communication. It outlines the requirements for distributed applications and provides a step-by-step guide to creating an RMI application, including defining a remote interface and implementing it. The document emphasizes the elimination of skeletons in Java 2 SDK and details the process of client-server interaction in RMI applications.

Uploaded by

naincyphotos1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

The RMI (Remote Method Invocation) is an API that provides a mechanism to create

distributed application in java. The RMI allows an object to invoke methods on an object
running in another JVM.

The RMI provides remote communication between the applications using two
objects stuband skeleton.

Understanding stub and skeleton

RMI uses stub and skeleton object for communication with the remote object.

A remote object is an object whose method can be invoked from another JVM. Let's
understand the stub and skeleton objects:

stub
The stub is an object, acts as a gateway for the client side. All the outgoing requests are
routed through it. It resides at the client side and represents the remote object. When the
caller invokes method on the stub object, it does the following tasks:

1. It initiates a connection with remote Virtual Machine (JVM),


2. It writes and transmits (marshals) the parameters to the remote Virtual Machine
(JVM),
3. It waits for the result
4. It reads (unmarshals) the return value or exception, and
5. It finally, returns the value to the caller.

skeleton

The skeleton is an object, acts as a gateway for the server side object. All the incoming
requests are routed through it. When the skeleton receives the incoming request, it does the
following tasks:

1. It reads the parameter for the remote method


2. It invokes the method on the actual remote object, and
3. It writes and transmits (marshals) the result to the caller.

In the Java 2 SDK, an stub protocol was introduced that eliminates the need for skeletons.

Understanding requirements for the distributed applications

If any application performs these tasks, it can be distributed application.


.
1. The application need to locate the remote method
2. It need to provide the communication with the remote objects, and
3. The application need to load the class definitions for the objects.

The RMI application have all these features, so it is called the distributed application.

Java RMI Example

The is given the 6 steps to write the RMI program.

1. Create the remote interface


2. Provide the implementation of the remote interface
3. Compile the implementation class and create the stub and skeleton objects using the
rmic tool
4. Start the registry service by rmiregistry tool
5. Create and start the remote application
6. Create and start the client application

RMI Example

In this example, we have followed all the 6 steps to create and run the rmi application. The
client application need only two files, remote interface and client application. In the rmi
application, both client and server interacts with the remote interface. The client application
invokes methods on the proxy object, RMI sends the request to the remote JVM. The return
value is sent bck to the proxy object and then to the client application.

Defining the Remote Interface


A remote interface provides the description of all the methods of a
particular remote object. The client communicates with this remote
interface.

To create a remote interface −

 Create an interface that extends the predefined interface Remotewhich


belongs to the package.
 Declare all the business methods that can be invoked by the client in this
interface.
 Since there is a chance of network issues during remote calls, an exception
named RemoteException may occur; throw it.

Following is an example of a remote interface. Here we have defined an


interface with the name Hello and it has a method called printMsg().

Developing the Implementation Class


(Remote Object)
We need to implement the remote interface created in the earlier step.
(We can write an implementation class separately or we can directly
make the server program implement this interface.)

To develop an implementation class −

 Implement the interface created in the previous step.

 Provide implementation to all the abstract methods of the remote interface.

Following is an implementation class. Here, we have created a class


named ImplExample and implemented the interface Hello created in
the previous step and provided body for this method which prints a
message.

You might also like