Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

4.4 Rmi RPC

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

RPC and JAVA RMI

Remote Procedure Call (RPC)


• Remote Procedure Call (RPC) is a protocol that one program can use
to request a service from a program located in another computer on
a network without having to understand the network's details.
• A procedure call is also sometimes known as a function call or
a subroutine call.
• RPC uses the client-server model.
• The message-passing nature of network communication is hidden
from the user.
A remote procedure call occurs in the following steps:
1. The client procedure calls the client stub in the normal way.
2. The client stub acts a proxy and builds a message and calls the local operating system.
3. The client's OS sends the message to the remote OS (via TCP/UDP).
4. The remote OS gives the message to the server stub.

5. The server stub unpacks the parameters and calls the server.
6. The server does the work and returns the result to the server stub.
7. The server stub packs it in a message and calls its local OS.
8. The server's OS sends the message to the client's OS.
9. The client's OS gives the message to the client stub.
10. The client stub unpacks the result and returns to the client.
RPC Vs RMI

RPC is C based, and as such it has structured


programming semantics
 RMI is a Java based technology and it's
object oriented and can be used for complex
applications.

With RPC you can just call remote functions exported into
a server,
 RMI you can have references to remote objects and
invoke their methods, and also pass and return more
remote object references that can be distributed among
many JVM instances, so it's much more powerful.
Remote method invocation(RMI)
• Remote Method Invocation (RMI) is an API which allows an object to
invoke a method on an object that exists in another address space,
which could be on the same machine or on a remote machine.
• Through RMI, object running in a JVM present on a computer (Client
side) can invoke methods on an object present in another JVM (Server
side).
• RMI creates a public remote server object that enables client and
server side communications through simple method calls on the
server object.
• RMI is used for building distributed application.
Working of RMI
Marshalling
During communication between two machines
through RPC or RMI, parameters are packed
into a message and then sent over the
network.

This packing of parameters into a message


is called marshalling.

On the other side these packed parameters


are unpacked from the message which is
called unmarshalling.
Stub
5
 The stub is an class, acts as a gateway for the client side.
 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
6

 The skeleton is a class, 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.
RMI Application Development
Steps for Developing the RMI Application
• Define the remote interface
• Define the class and implement the
remote interface(methods) in this class
• Define the Server side class
• Define the Client side class
• Compile the all four source(java) files
• Generate the Stub/Skeleton class by
command
• Start the RMI remote Registry
• Run the Server side class
• Run the Client side class(at another JVM)

You might also like