SlideShare une entreprise Scribd logo
1  sur  42
Distributed System:

Remote Method Invocation
PRESENTED BY:SONALI PARAB, 32
Introduction:


The Java Remote Method Invocation Application Programming
Interface (API), or Java RMI, is a JAVA API that performs the objectoriented equivalent of Remote Procedure Calls (RPC), with support for
direct transfer of serialized Java objects and distributed garbage
collection.



The original implementation depends on Java Virtual Machine (JVM)
class representation mechanisms and it thus only supports making calls
from one JVM to another. The protocol underlying this Java-only
implementation is known as Java Remote Method Protocols (JRMP).



In order to support code running
a COBRA version was later developed.

in

a

non-JVM

context,
What is Remote Method Invocation?
A

mechanism that allows object to interact which are

locate in different computer in different network.
 A package

for writing, executing java program.

 Provides

framework for developing & running

servers.
 A true

distributed computing application interface for

Java, written to provide easy access to objects
existing on remote virtual machines.
 Helps

provide access to objects existing on remote

virtual machines.
 Handles

marshalling, transportation, and garbage

collection of the remote objects. Became part of the
JDK with version 1.1.
Restrictions on Remote Method
Invocation?
►

Strictly Java. Cannot use with other code outside
Java

 Cannot

guarantee that a client will always use the

same thread in consecutive calls. Meaning you need
to write a mechanism for identifying the client
yourself
WHAT IS JAVA RMI?
•

JAVA RMI hides all the aspects of d.s & provides a uniform way
by which object can be access.

•

Java Remote Method Invocation (Java RMI) enables the
programmer to create distributed Java technology-based to Java
technology-based applications, in which the methods of remote
Java objects can be invoked from other Java virtual machines,
possibly on different hosts.

•

RMI uses object serialization to marshal and unmarshal
parameters and does not truncate types, supporting true object-
WHAT IS JAVA RMI?
•

Java RMI is included with Java SE and is available as
a separate download for Java ME.

•

Eg: RMIServer.java provide methods string gets(),void
gets(s).



client may use 2 methods for retrieving & storing a
string in s.



client may modify & inspect local state of server object.
Implemented of RMI in three layers:
•A stub program in the client side of the client/server
relationship, and a corresponding skeleton at the server end.
The stub appears to the calling program to be the program
being called for a service. (Sun uses the term proxy as a
synonym for stub.)
•A Remote Reference Layer that can behave differently
depending on the parameters passed by the calling program.
For example, this layer can determine whether the request is
to call a single remote service or multiple remote programs as
Implemented of RMI in three layers:
•A Transport Connection Layer, which sets up and manages
the request. A single request travels down through the layers
on one computer and up through the layers at the other end.
RMI is supplied as part of Sun Microsystem's Java
Development Kit (JDK).
DIAGRAMATIC REPRESENTATION OF
LAYERS OF RMI:
ARCHITECTURE OF RMI:
JAVA RMI ENVIRONMENT:
WORKING OF RMI:

Java1.1 Remote Method Invocation allows you to
send a message to some objects living on another
machine and get a result as if the object lived on your
local machine.
Let we see how to create our own RMI objects.
1.

REMOTE INTERFACES:

When you create a remote object, you mask the
underlying implementation by passing around an
interface.
 When you create a remote interface, you must
follow these guidelines:
1. The remote interface must be public.
2. The remote interface must extend the
interface java.rmi.Remote




3. Each method in the remote interface must
declare
java.rmi.RemoteException
in
its throws clause, in addition to any applicationspecific exceptions.

4. A remote object passed as an argument or return
value must be declared as the remote interface, not
the implementation class.
 Examples:InterCCRead.java InterCCWrite.java.
2.IMPLEMENTING THE REMOTE INTERFACE:
•

•

•

•

The
server
must
contain
a
class
that
extends UnicastRemoteObject and implements the remote
interface.
This class may also have additional methods, but only the
methods in the remote interface will be available to the
client, of course, since the client will get only a handle to
the interface, not the actual class that implements it.
You must explicitly define the constructor for the remote
object, even if you are only defining a default constructor
that just calls the base-class constructor.
Examples:
3.SET UP THE REGISTRY:
•

In the server codes, you see a call to the static
method Naming.bind().

•

However, this call requires that the registry be running as a separate
process on the computer.

•

The bind() command becomes:
Naming.bind("//machine_name/TheServer", service_name);
Naming.bind("TheServer", service_name);

•

The important thing is that it's a unique name in the registry that the
client knows to look for to procure the remote object. If the name is
already in the registry, you'll get an AlreadyBoundException.

•

To prevent this, you can always use rebind() either adds a new
entry or replaces the one that's already there.
4.CREATE THE STUBS AND THE SKELETONS:
• You must create the stubs and the skeletons that provide the network

connection operations and allow you to pretend that the remote object
is just another local object on your machine.
• You invoke the rmic tool on your compiled code, and it creates the
necessary
files.
Note:The rmic tool is particular about packages and classpaths.
You don't have to be in the directory containing TheServer.class when
you execute this command, but the results will be placed in the current
directory.
• When rmic runs successfully, you'll have two new classes in the
directory:
IMPLEMENTATION MODEL OF JAVA RMI
USING STUBS AND SKELETON:
5.USING THE REMOTE OBJECT:
•

The whole point of RMI is to make the use of remote objects very
simple.

•

The only extra thing you must do in your client program is to look
up and fetch the remote interface from the server.

•

From then on, it's just regular java programming: sending messages
to objects.

•

Example:
TheClient.java
PROGRAMMING A CLIENT:
•
•
•
1.

Having described how to define Remote and Serializable classes, we now
discuss how to program the Client and Server.
The Client itself is just a Java program.
The name of a remote object includes the following information:
The Internet name (or address) of the machine that is running the Object
Registry with which the remote object is being registered. If the Object Registry
is running on the same machine as the one that is making the request, then the
name of the machine can be omitted.

2.

The port to which the Object Registry is listening. If the Object Registry is
listening to the default port, 1099, then this does not have to be included in the
name.

3.

The local name of the remote object within the Object Registry.
Here is the example Client program:
/** * Client program for the "Hello, world!" example.
* @param argv The command line arguments which are ignored. */
public static void main (String[] argv)
{
try {
HelloInterface hello = (HelloInterface) Naming.lookup
("//ortles.ccs.neu.edu/Hello");
System.out.println (hello.say());
}
catch (Exception e)
{
System.out.println ("HelloClient exception: " + e);
}
}
•

The Naming.lookup method obtains an object handle from the
Object Registry running on ortles.ccs.neu.edu and listening to the
default port.

•

The remote method invocation in the example Client is hello.say().
It returns a String which is then printed
PROGRAMMING A SERVER:
The Server itself is just a Java program.
Here is the example Server:
/** * Server program for the "Hello, world!" example.

@param argv The command line arguments which are ignored. */
public static void main (String[] argv)
{ try {
Naming.rebind ("Hello", new Hello ("Hello, world!"));

System.out.println ("Hello Server is ready.");
} catch (Exception e)
{

System.out.println ("Hello Server failed: " + e);
} }
PROGRAMMING A SERVER:
The rmiregistry Object Registry only accepts requests to
bind and unbind objects running on the same machine, so it is
never necessary to specify the name of the machine when one
is registering an object.
The code for the Server can be placed in any convenient
class. In the example Server, it was placed in a
class HelloServer that contains only the program above.
STARTING A SERVER:
•Before starting the Server, one should first start the Object Registry,
and leave it running in the background.
•One performs this by using the command:
rmiregistry
•

•

The Server should then be started; and, like the Object Registry, left
running in the background.

The example Server is started using the command:
 java HelloServer
RUNNING A CLIENT:
•

The Client is run like any other java program.

•

The example Client is executed using:



java HelloClient
EXAMPLE:
•In the example program, we need a Remote class and its
corresponding Remote interface.
•We call these Hello and HelloInterface, respectively. Here is
the file:-=
HelloInterface.java:
EXAMPLE:
import java.rmi.*;
/**
* Remote Interface for the "Hello, world!" example.
*/
public interface HelloInterface extends Remote
{
/**
* Remotely invocable method.
* @return the message of the remote object, such as "Hello,
world!".
* @exception RemoteException if the remote invocation fails.
*/
public String say() throws RemoteException;
}
Here is the file:=
Hello.java:
import java.rmi.*;
import java.rmi.server.*;
/**
* Remote Class for the "Hello, world!" example.*/
public class Hello extends UnicastRemoteObject implements
HelloInterface
{
private String message;
/**
* Construct a remote object
* @param msg the message of the remote object, such as "Hello,
world!".
* @exception RemoteException if the object handle cannot be
constructed.
public Hello (String msg) throws RemoteException {
message = msg;
}
/**
* Implementation of the remotely invocable method.
* @return the message of the remote object, such as "Hello, world!".
* @exception RemoteException if the remote invocation fails.
*/
public String say() throws RemoteException {
return message;
}
}
•All of the Remote interfaces and classes should be compiled
using javac.
• Once this has been completed, the stubs and skeletons for
the Remote interfaces should be compiled by using
the rmic stub compiler.
•The stub and skeleton of the example Remote interface are
compiled with the command:
rmic Hello.
Enhancements in JavaTM SE
Development Kit (JDK) 6
•

java.rmi.MarshalledObject is now generic.

•

The class MarshalledObject now has a type parameter
representing the type of the contained serialized object:

•

Bug fix: Explicit TCP ports freed after remote objects
unexported

•

Bug fix: Garbage collection of client socket factories

•

Default GC interval lengthed to one hour
ENHANCEMENT & CHANGES IN
PREVIOUS RELEASES:
Dynamic Generation of Stub Classes (since 5.0)
•This release adds support for the dynamic generation of stub classes at
runtime, obviating the need to use the Java Remote Method Invocation
(Java RMI) stub compiler, rmic, to pregenerate stub classes for remote
objects.

•When an application exports a remote object and a pregenerated stub
class for the remote object's class cannot be loaded, the remote object's
stub will be a java.lang.reflect.Proxy instance (whose class is
dynamically
generated)
with
a java.rmi.server.RemoteObjectInvocationHandler as its invocation
ENHANCEMENT & CHANGES IN
PREVIOUS RELEASES:
•An existing application can be deployed to use dynamically
generated stub classes unconditionally (that is, whether or not
pregenerated stub classes exist) by setting the system
property java.rmi.server.ignoreStubClasses to "true".
•If this property is set to "true", pregenerated stub classes are
never used.
SECURITY:
•

One of the most common problems one encounters with RMI is a
failure due to security constraints.

•

One sets the security policy by constructing a SecurityManager
object and calling the setSecurityManager method of the System
class.



For example,

•

RMI will download a Serializable class from another machine only
if there is a security manager and the security manager permits the
downloading of the class from that machine.
SECURITY:
•

The RMISecurityManager class defines an example of a security
manager that normally permits such downloads.



The following code illustrates how to do this:
System.setSecurityManager (new RMISecurityManager()

{

public void checkConnect (String host, int port) {}

public void checkConnect (String host, int port, Object context)
{}});
ENHANCEMENT IN SECURITY:
•Defining and installing a security manager was the original technique
for specifying a security policy in Java.
•Unfortunately, it is very difficult to design such a class so that it does
not leave any security holes.
•For this reason, a new technique was introduced in Java 1.2, which is
backward compatible with the old technique.
• In the default security manager, all check
(except
checkPermission)
are
implemented
by
the checkPermission method.

methods
calling
•

The type of permission being checked is specified by the
parameter
of
type
Permission
passed
to
the checkPermission method.

•

Example,
The
checkConnect
method
calls checkPermission with a SocketPermission object.

•

The default implementation of checkPermission is to call
the checkPermission method of the AccessController class.
This method checks whether the specified permission is
implied by a list of granted permissions.
The Permissions class is used for maintaining lists of
granted permissions and for checking whether a particular

•
•
Q & A?

Contenu connexe

Tendances

Tendances (20)

Java rmi
Java rmiJava rmi
Java rmi
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Java beans
Java beansJava beans
Java beans
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Corba
CorbaCorba
Corba
 
Corba introduction and simple example
Corba introduction and simple example Corba introduction and simple example
Corba introduction and simple example
 
enterprise java bean
enterprise java beanenterprise java bean
enterprise java bean
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Java RMI Presentation
Java RMI PresentationJava RMI Presentation
Java RMI Presentation
 
Serialization & De-serialization in Java
Serialization & De-serialization in JavaSerialization & De-serialization in Java
Serialization & De-serialization in Java
 
Proxy Design Patterns
Proxy Design PatternsProxy Design Patterns
Proxy Design Patterns
 
OOP java
OOP javaOOP java
OOP java
 
Event handling
Event handlingEvent handling
Event handling
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJB
 
Proxy Design Pattern
Proxy Design PatternProxy Design Pattern
Proxy Design Pattern
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
 
EJB .
EJB .EJB .
EJB .
 

En vedette

Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with codekamal kotecha
 
A Short Java RMI Tutorial
A Short Java RMI TutorialA Short Java RMI Tutorial
A Short Java RMI TutorialGuo Albert
 
Distributes objects and Rmi
Distributes objects and RmiDistributes objects and Rmi
Distributes objects and RmiMayank Jain
 
Java RMI Detailed Tutorial
Java RMI Detailed TutorialJava RMI Detailed Tutorial
Java RMI Detailed TutorialMasud Rahman
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMIbackdoor
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocationDew Shishir
 
Java - Remote method invocation
Java - Remote method invocationJava - Remote method invocation
Java - Remote method invocationRiccardo Cardin
 
Munin: A Peer-to-Peer Middleware for Ubiquitous Analytics and Visualization S...
Munin: A Peer-to-Peer Middleware forUbiquitous Analytics and Visualization S...Munin: A Peer-to-Peer Middleware forUbiquitous Analytics and Visualization S...
Munin: A Peer-to-Peer Middleware for Ubiquitous Analytics and Visualization S...Niklas Elmqvist
 
Java remote method invocation
Java remote method invocationJava remote method invocation
Java remote method invocationVan Dawn
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method InvocationSonali Parab
 
Naming And Binding (Distributed computing)
Naming And Binding (Distributed computing)Naming And Binding (Distributed computing)
Naming And Binding (Distributed computing)Sri Prasanna
 

En vedette (20)

Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 
A Short Java RMI Tutorial
A Short Java RMI TutorialA Short Java RMI Tutorial
A Short Java RMI Tutorial
 
Rmi ppt-2003
Rmi ppt-2003Rmi ppt-2003
Rmi ppt-2003
 
Java RMI
Java RMIJava RMI
Java RMI
 
Distributes objects and Rmi
Distributes objects and RmiDistributes objects and Rmi
Distributes objects and Rmi
 
Java RMI Detailed Tutorial
Java RMI Detailed TutorialJava RMI Detailed Tutorial
Java RMI Detailed Tutorial
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
 
Rmi
RmiRmi
Rmi
 
Basic java
Basic java Basic java
Basic java
 
Introduction To Rmi
Introduction To RmiIntroduction To Rmi
Introduction To Rmi
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
 
Java - Remote method invocation
Java - Remote method invocationJava - Remote method invocation
Java - Remote method invocation
 
Munin: A Peer-to-Peer Middleware for Ubiquitous Analytics and Visualization S...
Munin: A Peer-to-Peer Middleware forUbiquitous Analytics and Visualization S...Munin: A Peer-to-Peer Middleware forUbiquitous Analytics and Visualization S...
Munin: A Peer-to-Peer Middleware for Ubiquitous Analytics and Visualization S...
 
Java remote method invocation
Java remote method invocationJava remote method invocation
Java remote method invocation
 
Java rmi
Java rmiJava rmi
Java rmi
 
Ravi Tuppad
Ravi TuppadRavi Tuppad
Ravi Tuppad
 
Rmi architecture
Rmi architectureRmi architecture
Rmi architecture
 
Rmi
RmiRmi
Rmi
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Naming And Binding (Distributed computing)
Naming And Binding (Distributed computing)Naming And Binding (Distributed computing)
Naming And Binding (Distributed computing)
 

Similaire à Remote Method Invocation (Java RMI)

Similaire à Remote Method Invocation (Java RMI) (20)

Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 
Rmi
RmiRmi
Rmi
 
Rmi
RmiRmi
Rmi
 
Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMI
 
Remote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programmingRemote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programming
 
Java RMI
Java RMIJava RMI
Java RMI
 
Rmi
RmiRmi
Rmi
 
Module 3 remote method invocation-2
Module 3   remote method  invocation-2Module 3   remote method  invocation-2
Module 3 remote method invocation-2
 
Oracle docs rmi applications
Oracle docs rmi applicationsOracle docs rmi applications
Oracle docs rmi applications
 
DS
DSDS
DS
 
ADB Lab Manual.docx
ADB Lab Manual.docxADB Lab Manual.docx
ADB Lab Manual.docx
 
Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVA
 
17rmi
17rmi17rmi
17rmi
 
Rmi
RmiRmi
Rmi
 
#4 (Remote Method Invocation)
#4 (Remote Method Invocation)#4 (Remote Method Invocation)
#4 (Remote Method Invocation)
 
Javarmi 130925082348-phpapp01
Javarmi 130925082348-phpapp01Javarmi 130925082348-phpapp01
Javarmi 130925082348-phpapp01
 
Distributed objects
Distributed objectsDistributed objects
Distributed objects
 
Rmi3
Rmi3Rmi3
Rmi3
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
 

Plus de Sonali Parab

Forensic laboratory setup requirements
Forensic laboratory setup requirementsForensic laboratory setup requirements
Forensic laboratory setup requirementsSonali Parab
 
Forensic laboratory setup requirements
Forensic laboratory setup  requirements Forensic laboratory setup  requirements
Forensic laboratory setup requirements Sonali Parab
 
Distributed systems
Distributed systemsDistributed systems
Distributed systemsSonali Parab
 
Advance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In DatabaseAdvance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In DatabaseSonali Parab
 
Cloud and Ubiquitous Computing manual
Cloud and Ubiquitous Computing manual Cloud and Ubiquitous Computing manual
Cloud and Ubiquitous Computing manual Sonali Parab
 
Advance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In DatabaseAdvance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In DatabaseSonali Parab
 
Default and On demand routing - Advance Computer Networks
Default and On demand routing - Advance Computer NetworksDefault and On demand routing - Advance Computer Networks
Default and On demand routing - Advance Computer NetworksSonali Parab
 
Cloud Computing And Virtualization
Cloud Computing And VirtualizationCloud Computing And Virtualization
Cloud Computing And VirtualizationSonali Parab
 
Protocols in Bluetooth
Protocols in BluetoothProtocols in Bluetooth
Protocols in BluetoothSonali Parab
 
Protols used in bluetooth
Protols used in bluetoothProtols used in bluetooth
Protols used in bluetoothSonali Parab
 
Public Cloud Provider
Public Cloud ProviderPublic Cloud Provider
Public Cloud ProviderSonali Parab
 
Public Cloud Provider
Public Cloud ProviderPublic Cloud Provider
Public Cloud ProviderSonali Parab
 

Plus de Sonali Parab (18)

Forensic laboratory setup requirements
Forensic laboratory setup requirementsForensic laboratory setup requirements
Forensic laboratory setup requirements
 
Forensic laboratory setup requirements
Forensic laboratory setup  requirements Forensic laboratory setup  requirements
Forensic laboratory setup requirements
 
Distributed systems
Distributed systemsDistributed systems
Distributed systems
 
Data Mining
Data MiningData Mining
Data Mining
 
Firewalls
FirewallsFirewalls
Firewalls
 
Embedded System
Embedded System Embedded System
Embedded System
 
Advance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In DatabaseAdvance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In Database
 
Cloud and Ubiquitous Computing manual
Cloud and Ubiquitous Computing manual Cloud and Ubiquitous Computing manual
Cloud and Ubiquitous Computing manual
 
Advance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In DatabaseAdvance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In Database
 
Default and On demand routing - Advance Computer Networks
Default and On demand routing - Advance Computer NetworksDefault and On demand routing - Advance Computer Networks
Default and On demand routing - Advance Computer Networks
 
Cloud Computing And Virtualization
Cloud Computing And VirtualizationCloud Computing And Virtualization
Cloud Computing And Virtualization
 
Protocols in Bluetooth
Protocols in BluetoothProtocols in Bluetooth
Protocols in Bluetooth
 
Protols used in bluetooth
Protols used in bluetoothProtols used in bluetooth
Protols used in bluetooth
 
Public Cloud Provider
Public Cloud ProviderPublic Cloud Provider
Public Cloud Provider
 
Public Cloud Provider
Public Cloud ProviderPublic Cloud Provider
Public Cloud Provider
 
Minning www
Minning wwwMinning www
Minning www
 
Agile testing
Agile testingAgile testing
Agile testing
 
Minning WWW
Minning WWWMinning WWW
Minning WWW
 

Dernier

Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfstareducators107
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 

Dernier (20)

Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 

Remote Method Invocation (Java RMI)

  • 1. Distributed System: Remote Method Invocation PRESENTED BY:SONALI PARAB, 32
  • 2. Introduction:  The Java Remote Method Invocation Application Programming Interface (API), or Java RMI, is a JAVA API that performs the objectoriented equivalent of Remote Procedure Calls (RPC), with support for direct transfer of serialized Java objects and distributed garbage collection.  The original implementation depends on Java Virtual Machine (JVM) class representation mechanisms and it thus only supports making calls from one JVM to another. The protocol underlying this Java-only implementation is known as Java Remote Method Protocols (JRMP).  In order to support code running a COBRA version was later developed. in a non-JVM context,
  • 3. What is Remote Method Invocation? A mechanism that allows object to interact which are locate in different computer in different network.  A package for writing, executing java program.  Provides framework for developing & running servers.
  • 4.  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote virtual machines.  Helps provide access to objects existing on remote virtual machines.  Handles marshalling, transportation, and garbage collection of the remote objects. Became part of the JDK with version 1.1.
  • 5. Restrictions on Remote Method Invocation? ► Strictly Java. Cannot use with other code outside Java  Cannot guarantee that a client will always use the same thread in consecutive calls. Meaning you need to write a mechanism for identifying the client yourself
  • 6. WHAT IS JAVA RMI? • JAVA RMI hides all the aspects of d.s & provides a uniform way by which object can be access. • Java Remote Method Invocation (Java RMI) enables the programmer to create distributed Java technology-based to Java technology-based applications, in which the methods of remote Java objects can be invoked from other Java virtual machines, possibly on different hosts. • RMI uses object serialization to marshal and unmarshal parameters and does not truncate types, supporting true object-
  • 7. WHAT IS JAVA RMI? • Java RMI is included with Java SE and is available as a separate download for Java ME. • Eg: RMIServer.java provide methods string gets(),void gets(s).  client may use 2 methods for retrieving & storing a string in s.  client may modify & inspect local state of server object.
  • 8. Implemented of RMI in three layers: •A stub program in the client side of the client/server relationship, and a corresponding skeleton at the server end. The stub appears to the calling program to be the program being called for a service. (Sun uses the term proxy as a synonym for stub.) •A Remote Reference Layer that can behave differently depending on the parameters passed by the calling program. For example, this layer can determine whether the request is to call a single remote service or multiple remote programs as
  • 9. Implemented of RMI in three layers: •A Transport Connection Layer, which sets up and manages the request. A single request travels down through the layers on one computer and up through the layers at the other end. RMI is supplied as part of Sun Microsystem's Java Development Kit (JDK).
  • 13. WORKING OF RMI: Java1.1 Remote Method Invocation allows you to send a message to some objects living on another machine and get a result as if the object lived on your local machine.
  • 14. Let we see how to create our own RMI objects. 1. REMOTE INTERFACES: When you create a remote object, you mask the underlying implementation by passing around an interface.  When you create a remote interface, you must follow these guidelines: 1. The remote interface must be public. 2. The remote interface must extend the interface java.rmi.Remote
  • 15.   3. Each method in the remote interface must declare java.rmi.RemoteException in its throws clause, in addition to any applicationspecific exceptions. 4. A remote object passed as an argument or return value must be declared as the remote interface, not the implementation class.  Examples:InterCCRead.java InterCCWrite.java.
  • 16. 2.IMPLEMENTING THE REMOTE INTERFACE: • • • • The server must contain a class that extends UnicastRemoteObject and implements the remote interface. This class may also have additional methods, but only the methods in the remote interface will be available to the client, of course, since the client will get only a handle to the interface, not the actual class that implements it. You must explicitly define the constructor for the remote object, even if you are only defining a default constructor that just calls the base-class constructor. Examples:
  • 17. 3.SET UP THE REGISTRY: • In the server codes, you see a call to the static method Naming.bind(). • However, this call requires that the registry be running as a separate process on the computer. • The bind() command becomes: Naming.bind("//machine_name/TheServer", service_name); Naming.bind("TheServer", service_name); • The important thing is that it's a unique name in the registry that the client knows to look for to procure the remote object. If the name is already in the registry, you'll get an AlreadyBoundException. • To prevent this, you can always use rebind() either adds a new entry or replaces the one that's already there.
  • 18. 4.CREATE THE STUBS AND THE SKELETONS: • You must create the stubs and the skeletons that provide the network connection operations and allow you to pretend that the remote object is just another local object on your machine. • You invoke the rmic tool on your compiled code, and it creates the necessary files. Note:The rmic tool is particular about packages and classpaths. You don't have to be in the directory containing TheServer.class when you execute this command, but the results will be placed in the current directory. • When rmic runs successfully, you'll have two new classes in the directory:
  • 19. IMPLEMENTATION MODEL OF JAVA RMI USING STUBS AND SKELETON:
  • 20. 5.USING THE REMOTE OBJECT: • The whole point of RMI is to make the use of remote objects very simple. • The only extra thing you must do in your client program is to look up and fetch the remote interface from the server. • From then on, it's just regular java programming: sending messages to objects. • Example: TheClient.java
  • 21. PROGRAMMING A CLIENT: • • • 1. Having described how to define Remote and Serializable classes, we now discuss how to program the Client and Server. The Client itself is just a Java program. The name of a remote object includes the following information: The Internet name (or address) of the machine that is running the Object Registry with which the remote object is being registered. If the Object Registry is running on the same machine as the one that is making the request, then the name of the machine can be omitted. 2. The port to which the Object Registry is listening. If the Object Registry is listening to the default port, 1099, then this does not have to be included in the name. 3. The local name of the remote object within the Object Registry.
  • 22. Here is the example Client program: /** * Client program for the "Hello, world!" example. * @param argv The command line arguments which are ignored. */ public static void main (String[] argv) { try { HelloInterface hello = (HelloInterface) Naming.lookup ("//ortles.ccs.neu.edu/Hello"); System.out.println (hello.say()); } catch (Exception e) { System.out.println ("HelloClient exception: " + e); } }
  • 23. • The Naming.lookup method obtains an object handle from the Object Registry running on ortles.ccs.neu.edu and listening to the default port. • The remote method invocation in the example Client is hello.say(). It returns a String which is then printed
  • 24. PROGRAMMING A SERVER: The Server itself is just a Java program. Here is the example Server: /** * Server program for the "Hello, world!" example. @param argv The command line arguments which are ignored. */ public static void main (String[] argv) { try { Naming.rebind ("Hello", new Hello ("Hello, world!")); System.out.println ("Hello Server is ready."); } catch (Exception e) { System.out.println ("Hello Server failed: " + e); } }
  • 25. PROGRAMMING A SERVER: The rmiregistry Object Registry only accepts requests to bind and unbind objects running on the same machine, so it is never necessary to specify the name of the machine when one is registering an object. The code for the Server can be placed in any convenient class. In the example Server, it was placed in a class HelloServer that contains only the program above.
  • 26. STARTING A SERVER: •Before starting the Server, one should first start the Object Registry, and leave it running in the background. •One performs this by using the command: rmiregistry • • The Server should then be started; and, like the Object Registry, left running in the background. The example Server is started using the command:  java HelloServer
  • 27. RUNNING A CLIENT: • The Client is run like any other java program. • The example Client is executed using:  java HelloClient
  • 28. EXAMPLE: •In the example program, we need a Remote class and its corresponding Remote interface. •We call these Hello and HelloInterface, respectively. Here is the file:-= HelloInterface.java:
  • 29. EXAMPLE: import java.rmi.*; /** * Remote Interface for the "Hello, world!" example. */ public interface HelloInterface extends Remote { /** * Remotely invocable method. * @return the message of the remote object, such as "Hello, world!". * @exception RemoteException if the remote invocation fails. */ public String say() throws RemoteException; }
  • 30. Here is the file:= Hello.java: import java.rmi.*; import java.rmi.server.*; /** * Remote Class for the "Hello, world!" example.*/ public class Hello extends UnicastRemoteObject implements HelloInterface { private String message; /** * Construct a remote object * @param msg the message of the remote object, such as "Hello, world!". * @exception RemoteException if the object handle cannot be constructed.
  • 31. public Hello (String msg) throws RemoteException { message = msg; } /** * Implementation of the remotely invocable method. * @return the message of the remote object, such as "Hello, world!". * @exception RemoteException if the remote invocation fails. */ public String say() throws RemoteException { return message; } }
  • 32. •All of the Remote interfaces and classes should be compiled using javac. • Once this has been completed, the stubs and skeletons for the Remote interfaces should be compiled by using the rmic stub compiler. •The stub and skeleton of the example Remote interface are compiled with the command: rmic Hello.
  • 33. Enhancements in JavaTM SE Development Kit (JDK) 6 • java.rmi.MarshalledObject is now generic. • The class MarshalledObject now has a type parameter representing the type of the contained serialized object: • Bug fix: Explicit TCP ports freed after remote objects unexported • Bug fix: Garbage collection of client socket factories • Default GC interval lengthed to one hour
  • 34. ENHANCEMENT & CHANGES IN PREVIOUS RELEASES: Dynamic Generation of Stub Classes (since 5.0) •This release adds support for the dynamic generation of stub classes at runtime, obviating the need to use the Java Remote Method Invocation (Java RMI) stub compiler, rmic, to pregenerate stub classes for remote objects. •When an application exports a remote object and a pregenerated stub class for the remote object's class cannot be loaded, the remote object's stub will be a java.lang.reflect.Proxy instance (whose class is dynamically generated) with a java.rmi.server.RemoteObjectInvocationHandler as its invocation
  • 35. ENHANCEMENT & CHANGES IN PREVIOUS RELEASES: •An existing application can be deployed to use dynamically generated stub classes unconditionally (that is, whether or not pregenerated stub classes exist) by setting the system property java.rmi.server.ignoreStubClasses to "true". •If this property is set to "true", pregenerated stub classes are never used.
  • 36.
  • 37. SECURITY: • One of the most common problems one encounters with RMI is a failure due to security constraints. • One sets the security policy by constructing a SecurityManager object and calling the setSecurityManager method of the System class.  For example, • RMI will download a Serializable class from another machine only if there is a security manager and the security manager permits the downloading of the class from that machine.
  • 38. SECURITY: • The RMISecurityManager class defines an example of a security manager that normally permits such downloads.  The following code illustrates how to do this: System.setSecurityManager (new RMISecurityManager() { public void checkConnect (String host, int port) {} public void checkConnect (String host, int port, Object context) {}});
  • 39. ENHANCEMENT IN SECURITY: •Defining and installing a security manager was the original technique for specifying a security policy in Java. •Unfortunately, it is very difficult to design such a class so that it does not leave any security holes. •For this reason, a new technique was introduced in Java 1.2, which is backward compatible with the old technique. • In the default security manager, all check (except checkPermission) are implemented by the checkPermission method. methods calling
  • 40. • The type of permission being checked is specified by the parameter of type Permission passed to the checkPermission method. • Example, The checkConnect method calls checkPermission with a SocketPermission object. • The default implementation of checkPermission is to call the checkPermission method of the AccessController class. This method checks whether the specified permission is implied by a list of granted permissions. The Permissions class is used for maintaining lists of granted permissions and for checking whether a particular • •
  • 41.