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

Remote Object Invocation & RMI

The document provides an overview of Remote Method Invocation (RMI) in Java, detailing its architecture, components such as stubs and skeletons, and the step-wise process of RMI communication. It outlines the advantages of RMI, including simplicity and flexibility, as well as its disadvantages, such as efficiency and security concerns. The RMI architecture consists of multiple layers, including the application layer, proxy layer, remote reference layer, and transport layer, facilitating distributed object communication across different systems.

Uploaded by

ppkarhade
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 views7 pages

Remote Object Invocation & RMI

The document provides an overview of Remote Method Invocation (RMI) in Java, detailing its architecture, components such as stubs and skeletons, and the step-wise process of RMI communication. It outlines the advantages of RMI, including simplicity and flexibility, as well as its disadvantages, such as efficiency and security concerns. The RMI architecture consists of multiple layers, including the application layer, proxy layer, remote reference layer, and transport layer, facilitating distributed object communication across different systems.

Uploaded by

ppkarhade
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

Module 2-Communication

Remote Object Invocation


 Objects that are distributed across various address spaces, either on multiple computers connected
by a network or even in different processes on the same computer are referred to as distributed
objects.
 The main method of distributed object communication is with remote method invocation(RMI) by
message passing
Remote Method Invocation (RMI)
 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 stub and skeleton.

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:
 It initiates a connection with remote Virtual Machine (JVM),
 It writes and transmits (marshals) the parameters to the remote Virtual Machine (JVM),
 It waits for the result
 It reads (unmarshals) the return value or exception, and
 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:
 It reads the parameter for the remote method
 It invokes the method on the actual remote object, and
 It writes and transmits (marshals) the result to the caller.
Figure-Remote Method Invocation (RMI)

RMI Architecture
 RMI architecture describes how remote objects behave and how parameters are passed between
remote methods.
 Remote method can be invoked by referring to the remote objects.
 When a remote object is referenced, the object is not sent over the network to the client that requests
it. Instead, a proxy object (often referred to as stub), which is a client-side proxy for the remote
object, is sent.
 The client interacts only with this stub class. The stub class is responsible for handling data between
the local and the remote systems.
 A skeleton class is responsible for handing over the method, class and data to the actual object being
referenced on the server side.
 The actual implementation of the client-server application takes place at the Application layer. Any
application that makes some of its methods available to its remote clients must first declare the
methods in an interface that extends [Link]. Remote, which is an empty interface.
 The Java RMI architecture consists of three layers:
(i) Application layer
(i) Proxy Layer (or Stub/Skeleton layer)
(ii) Remote Reference Layer (RRL)
(iii) Transport Layer.
Application Layer
 Responsible for running client and server application
 Client application invoke method defined by server application
Proxy Layer (Stub/Skeleton layer)
 The proxy layer is responsible for managing the remote object interface between the server and
client.
 In this layer, the stub class is the client-side Proxy for the remote object. stub is responsible for
initiating a call to the remote object it represents and is the application interface to that object.
 It is also responsible for marshalling the method arguments to a marshal stream. This stream is a
stream object, which simply transports the parameters, exceptions and errors needed for the method
dispatch and returns the results.
 Both the stub and skeleton classes use this stream to communicate with each other. Once the results
are returned to the client stub, the results are un-marshalled.
 The skeleton class is similar to the stub class in many ways. The only difference is that it exists on
the server side.
 The responsibility of the skeleton class is to send parameters to the method implementation and
sending the return values.
 They are generated using the RMI stub compiler (RMIC). When the remote object from the naming
server is requested, the stub class is downloaded to the client machine.
 The stub and skeleton classes implement the same interfaces as the remote object.
Remote reference layer
 This layer gets a stream-oriented connection from the transport layer.
 It is responsible for dealing with the semantics of remote invocations.
 It is also responsible for handling duplicated objects and for performing implementation specific
tasks with remote objects.
Transport layer
 The transport layer is responsible for setting up the connection and transportation of data from one
machine to another.
 The default connection is set up only in the TCP/IP protocol.

RMI Process
Step-wise RMI Process
1. Server registers remote object
o The server application creates the remote object and binds (registers) it in the RMI Registry with
a name.
2. Client looks up the remote object
o The client application contacts the RMI Registry and requests the remote object reference using
that name.
3. Registry returns remote object reference
o The registry sends back a reference (stub-related info) so the client can access the remote object.
4. Client gets a Stub
o The client obtains/creates the client stub (a proxy object that looks like the real remote object).
5. Client calls method via Stub
o Client invokes the remote method as if it were local.
o The stub forwards the request to the transport/network layer.
6. Marshalling: parameters sent
o The stub serializes (marshals) method parameters into a network-friendly form and sends them
to the server side.
7. Request reaches Remote Reference Layer (server side)
o Server transport forwards the request to the Remote Reference Layer (RRL).
8. RRL validates & forwards to Skeleton
o RRL checks things like call semantics (reference, dispatching) and forwards the request to the
server skeleton.
9. Skeleton unpacks & calls actual method
o The skeleton deserializes (unmarshals) the parameters and invokes the actual method on the
server object.
10. Server executes method
o The server application runs the method logic and produces the result (or exception).
11. Server packs result into Skeleton
o The result is passed back to the skeleton for return processing.
12. Skeleton → Remote Reference Layer
o Skeleton sends the packed result to the Remote Reference Layer.
13. Return through Transport Layer
o The result travels back through the transport/network layer to the client side.
14. Client-side Skeleton/transport passes to Stub
o The received data is delivered to the client stub.
15. Unmarshalling + return to Client
o The stub unpacks (unmarshals) the result and returns it to the client application like a
normal method return.

Advantages of RMI
1) Simple and clean to implement that leads to more robust, maintainable and flexible applications.
2) Distributed systems creations are allowed while decoupling the client and server object simultaneously.
3) No client installation is needed except java capable browsers.
4) At the time of changing the database, only server objects are to be complied but not the server interface
and client remains the same.

Disadvantages of RMI
1) Less efficient than socket object.
2) Assuming the default threading will ignoring the coding, being the servers are thread-safe and robust.
3) Cannot use the code out of the scope of java.
4) Security issues need to be monitored more closely.

You might also like