0% found this document useful (0 votes)
3 views

U3_C7_L2_Java Remote Method Invocation

The document discusses Java Remote Method Invocation (RMI), an object-oriented API for Java that allows remote method calls between clients and servers. It covers the architecture of RMI, including the object registry, remote interfaces, server-side and client-side software, and the generation of stubs and skeletons. Additionally, it compares RMI with socket APIs, highlighting the trade-offs in terms of performance and ease of development.

Uploaded by

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

U3_C7_L2_Java Remote Method Invocation

The document discusses Java Remote Method Invocation (RMI), an object-oriented API for Java that allows remote method calls between clients and servers. It covers the architecture of RMI, including the object registry, remote interfaces, server-side and client-side software, and the generation of stubs and skeletons. Additionally, it compares RMI with socket APIs, highlighting the trade-offs in terms of performance and ease of development.

Uploaded by

Ral Ralte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Distributed Computing – Unit III – Chapter 7 - Lecture 2

Java Remote Method Invocation

Satish Narayana Srirama


satish.srirama@uohyd.ac.in

30/10/2024 Satish Srirama 1


Outline
• The Java RMI Architecture
• Object Registry
• The API for the Java RMI

30/10/2024 Satish Srirama 2


Remote Method Invocation
• Remote Method Invocation (RMI) is an object-oriented
implementation of the Remote Procedure Call (RPC) model
• It is an API for Java programs only
• Using RMI, an object server exports a remote object and registers it
with a directory service
– e.g. RMI registry
• The object provides remote methods, which can be invoked in
client programs
• Syntactically:
– A remote object is declared with a remote interface, a Java interface
– The remote interface is implemented by the object server
– An object client accesses the object by invoking the remote methods
associated with the objects using syntax provided for remote method
invocations

30/10/2024 Satish Srirama 3


The Java RMI Architecture
Directory service

object object
client server
supports the interface with
the application program

maps the platform-independent stub/skeleton stub skeleton


layer to the platform-dependent transport
layer; carries out remote reference protocols remote reference layer remote reference layer
transport layer transport layer
sets up, maintains, and shuts down
connections; and carries out the
transport protocol

logical data path

physical data path


30/10/2024 Satish Srirama 4
Object Registry
• The RMI API allows a number of directory services to be
used for registering a distributed object
• We will use a simple directory service called the RMI
registry, rmiregistry
– It is provided with the Java Software Development Kit (SDK)
• The RMI Registry is a service whose server, when active,
runs on the object server’s host machine by convention
– By default, it runs on the TCP port 1099
• Java Naming and Directory Interface (JNDI) can also be used
for registering
– More general than the RMI registry
– Defined to be independent of any specific directory service
implementation
– Supports LDAP, DNS, RMI, CORBA etc.
https://docs.oracle.com/javase/tutorial/jndi/overview/index.html
30/10/2024 Satish Srirama 5
The interaction between the stub and
the skeleton
• A time-event diagram describing the interaction
between the stub and the skeleton

30/10/2024 Satish Srirama 6


The API for the Java RMI
• The Remote Interface
• The Server-side Software
– The Remote Interface Implementation
– Stub and Skeleton Generation
– The Object Server
• The Client-side Software

30/10/2024 Satish Srirama 7


The Remote Interface
• A Java interface contains declarations or
signatures of methods
– Classes that implement the interface must provide
implementations for the methods
• A java remote interface is an interface that
inherits from the java.rmi.Remote interface
– This allows the interface to be implemented using RMI
syntax
• Each method signature in the interface must
throw java.rmi.RemoteException

30/10/2024 Satish Srirama 8


A sample remote interface

• The RemoteException is raised when errors occur during the


processing of a remote method call
– The exception is required to be caught in the method caller’s program
• Causes of such exceptions
– Exceptions that may occur during interprocess communications such
as access failures and connection failures
– Problems unique to remote method invocations, including errors
resulting from the object, the stub, or the skeleton not being found
30/10/2024 Satish Srirama 9
The Server-side software
• A server object provides the methods of the
interface to a distributed object
• Each server object must
– Implement each of the remote methods specified in
the interface
– Register a server object, which contains the method
implementations, with a directory service
• e.g., RMI registry or JNDI
• It is recommended that the two parts be
provided as separate classes

30/10/2024 Satish Srirama 10


The Remote Interface Implementation
• A server class implements the remote
interface

30/10/2024 Satish Srirama 11


The Object Server
• The object server class is a class whose code
instantiates and exports an object of the remote
interface implementation
• Exporting the remote object is necessary to make
it available to receive incoming calls
• The rebind() method will overwrite any reference
in the registry bound with the given reference
name
– If the overwriting is not desirable, there is also a bind()
method

30/10/2024 Satish Srirama 12


The Object Server - continued

30/10/2024 Satish Srirama 13


The Object Server - continued
• When an object server is executed, the exporting of
the distributed object causes the server process
– To begin to listen and wait for clients to connect and
request the service of the object
• An RMI object server is a concurrent server
– Each request from an object client is serviced using a
separate thread of the server
• Note that if a client process invokes multiple remote
method calls, these calls will be executed concurrently
– Unless provisions are made in the client process to
synchronize the calls

30/10/2024 Satish Srirama 14


Stub and Skeleton Generations
• In RMI, each distributed object requires a proxy
for the object server and the object client
– Known as the object’s skeleton and stub, respectively
• These proxies are generated from the
implementation of a remote interface using the
RMI compiler rmic
– rmic <class name of the remote interface
implementation>
– E.g. rmic ImplementRemoteHello
• This step is no longer necessary from Java
Standard Edition 5.0

30/10/2024 Satish Srirama 15


The RMI Registry
• An RMI registry can be activated by using the
rmiregistry utility which comes with the Java
Software Development Kit (SDK)
– Unix: rmiregistry <port number>
– Windows: start rmiregistry
• The port number is a TCP port number
– If no port number is specified, port number 1099 is
assumed
• The registry will run continuously until it is shut
down (via CTRL-C, for example)
30/10/2024 Satish Srirama 16
The Client-side Software
• The program for the client class is like any
other Java class
• The syntax needed for RMI involves
– Locating the RMI Registry in the server host
– Looking up the remote object reference for the
server object
• The object reference can then be cast to the remote
interface class and the remote methods can be invoked
• It is a common mistake to cast the object retrieved
from the registry to the interface implementation class
or the server object class
30/10/2024 Satish Srirama 17
The Client-side Software - continued
Demo

30/10/2024 Satish Srirama 18


RMI Example 2
• Invoking remote methods with parameters is
also similar to the Example 1
Demo
• Exporting the remote object by inheriting
UnicastRemoteObject

30/10/2024 Satish Srirama 19


Comparison of the RMI and the socket
APIs
• The remote method invocation API is an efficient tool for
building network applications
• It can be used in lieu of the socket API in a network
application
• Some of the tradeoffs between the RMI API and the socket
API are as follows:
– The socket API is closely related to the operating system, and
hence has less execution overhead
• For applications which require high performance, this may be a
consideration
– The RMI API provides the abstraction which eases the task of
software development
• Programs developed with a higher level of abstraction are more
comprehensible and hence easier to debug

30/10/2024 Satish Srirama 20


References & Books
• Chapter 7, M. L. Liu (2004), Distributed
Computing: Principles and Applications, First
Edition, Pearson Publications.
• Some of the slides are adapted from the lecture
materials provided by the reference book
• Getting Started Using Java RMI
https://docs.oracle.com/javase/7/docs/technotes
/guides/rmi/hello/hello-world.html
• RMI (Remote Method Invocation)
https://www.javatpoint.com/RMI
30/10/2024 Satish Srirama 21

You might also like