SlideShare a Scribd company logo
Introduction To RMI By Swarup Kulkarni (MCA-II, VIT, Pune)
Remote Method Invocation RMI - Remote Method Invocation Allows to invoke a method of a Java object that executes on another machine. Important feature, because it allows  to build distributed applications. Lets discus a simple Client/Server application using RMI. The server receives a request from client and processes it In this req. two numbers are specified Server add these numbers and returns it 3/11/2009 2 RMI - Swarup Kulkarni
Step 1: Enter and Compile the Source Code We use four source files - First source file: RmiDemoIntf.java Defines remote interface, a remote method, All remote interfaces must inherit Remote interface Remote interface is a part of java.rmi.remote Defines no members , purpose is to indicate that interface uses remote methods. All remote methods can throw RemoteException 3/11/2009 3 RMI - Swarup Kulkarni
Step 1: (Continued..) The first source file - Code: RmiDemoIntf.java import java.rmi.*; public interface RmiDemoIntf extends Remote { 	double add(double d1, double d2) throws RemoteException; } 3/11/2009 4 RMI - Swarup Kulkarni
Step 1: (Continued..) The second source file: RmiDemoImpl.java Implements Remote interface implementation of the add( ) method is straightforward All remote objects must extend UnicastRemoteObject UnicastRemoteObject provides functionality that is needed to make objects available from remote machines 3/11/2009 5 RMI - Swarup Kulkarni
Step 1: (Continued..) The second source file - Code: RmiDemoImpl.java import java.rmi.*; import java.rmi.server.*; public class RmiDemoImpl extends UnicastRemoteObject 					       implements RmiDemoIntf{ public double add(double d1, double d2) throws 					RemoteException { return d1 + d2; } } 3/11/2009 6 RMI - Swarup Kulkarni
Step 1: (Continued..) The third source file: RmiServer.java Contains main program for the server machine This modifies the RMI registry of the machine using rebind() method of Naming class(found in java.rmi) Naming.rebind() ,[object Object]
First argument names server as “RmiServer”
Second argument is reference to object of  RmiDemoImpl3/11/2009 7 RMI - Swarup Kulkarni
Step 1: (Continued..) The third source file - Code: RmiServer.java import java.net.*; import java.rmi.*; public class RmiServer{ public static void main(String args[]) { try { RmiDemoImpl obj_RmiDemoImpl = new RmiDemoImpl(); Naming.rebind(“RmiServer", obj_RmiDemoImpl); } catch(Exception e) { System.out.println("Exception: " + e); } } } 3/11/2009 8 RMI - Swarup Kulkarni
Step 1: (Continued..) The forth source file: RmiClient.java Implements client side of this distributed application. Requires thee main things – IP address or name of server, and the two numbers to be added. We create a string that follows URL syntax. The URL includes IP or Name of the server and the string “RmiServer”. The program invokes lookup() method from Naming class which accepts rmi URL as argument and returns a reference of object of RmiDemoIntf . Now all the remote method invocations can be directed to this object. 3/11/2009 9 RMI - Swarup Kulkarni
Step 1: (Continued..) The forth source file - Code: RmiClient.java import java.rmi.*; public class RmiClient { public static void main(String args[]) { try { double d1 = 24.73; double d2 = 11.12; String RmiDemoURL = "rmi://" + “127.0.0.1” + "/RmiServer"; //127.0.0.1 is loopback address replace it with server IP/name RmiDemoIntf obj = 	(RmiDemoIntf)Naming.lookup(RmiDemoURL); 3/11/2009 10 RMI - Swarup Kulkarni
Step 1: (Continued..) RmiClient.java(Contd..) System.out.println("The first number is: " + d1); System.out.println("The second number is: " + d2); System.out.println("The sum is: " + RmiDemoIntf.add(d1, d2)); 	     }//end of try 	     catch(Exception e) { 	System.out.println("Exception: " + e); 	}//end of catch 	}//end of main }//end of class 3/11/2009 11 RMI - Swarup Kulkarni
Step 2: Generate Stubs and Skeletons Before using  client and  server we have to generate stub and skeleton. Stub resides on client machine. Remote method calls initiated by client are directed to stub. A remote method can have simple arguments or objects as arguments. Objects may have reference to other objects, to send whole information to server the objects in arguments must be serialized. Skeletons are not required by Java 2.(Needed for compatibility with java1.1) Skeleton resides on sever machine, when it receives request, it performs deserialization and invokes appropriate method. In case of response to client, the process works reverse. 3/11/2009 12 RMI - Swarup Kulkarni
Step 2: (Continued..) How to generate stub and Skeleton? Use a tool called RMI Compiler, which is invoked from command line: 		rmic RmiDemoImpl; This command generates two new files: RmiDemoImpl_Skel.class (skeleton) and RmiDemoImpl_Stub.class (stub). Before using rmic make sure that CLASSPATH is set to include current directories. rmic  by default generates stub as well as skeleton, we have option to suppress it. 3/11/2009 13 RMI - Swarup Kulkarni
Step 3: Install Files on Client and Server Copy  RmiDemo.class, RmiDemoImpl_Stub.class, and RmiDemoImpl.class on the client machine. Copy RmiDemontf.class, RmiDemoImpl.class, RmiDemompl_Skel.class, RmiDemompl_Stub.class, and RmiDemo.class on the server machine. 3/11/2009 14 RMI - Swarup Kulkarni
Step 4: Start the RMI Registry on the Server The Java 2 SDK provides a program called rmiregistry, which executes on server. The rmiregistry maps names to object reference. First, check that the CLASSPATH environment variable includes the directory in which your files are located and start RMI Registry: 			start rmiregistry When this command runs, it creates a new window. Leave that window open until the experimentation finishes. 3/11/2009 15 RMI - Swarup Kulkarni

More Related Content

What's hot

Remote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVARemote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVA
Prankit Mishra
 
Rmi ppt
Rmi pptRmi ppt
Java rmi tutorial
Java rmi tutorialJava rmi tutorial
Java rmi tutorial
HarikaReddy115
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
ashishspace
 
Rmi
RmiRmi
RMI
RMIRMI
Rmi
RmiRmi
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
Dew Shishir
 
Java RMI Presentation
Java RMI PresentationJava RMI Presentation
Java RMI Presentation
Masud Rahman
 
Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)
Nilesh Valva
 
Java remote method invocation
Java remote method invocationJava remote method invocation
Java remote method invocation
Van Dawn
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
Jalpesh Vasa
 
Java RMI
Java RMIJava RMI
Java RMI
Prajakta Nimje
 
Java RMI Detailed Tutorial
Java RMI Detailed TutorialJava RMI Detailed Tutorial
Java RMI Detailed Tutorial
Masud Rahman
 
Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)
eLink Business Innovations
 
Java rmi
Java rmiJava rmi
Java rmi
Fazlur Rahman
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
backdoor
 
Rmi ppt-2003
Rmi ppt-2003Rmi ppt-2003
Rmi ppt-2003
kalaranjani1990
 
remote method invocation
remote method invocationremote method invocation
remote method invocation
Ravi Theja
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
sakthibalabalamuruga
 

What's hot (20)

Remote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVARemote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVA
 
Rmi ppt
Rmi pptRmi ppt
Rmi ppt
 
Java rmi tutorial
Java rmi tutorialJava rmi tutorial
Java rmi tutorial
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Rmi
RmiRmi
Rmi
 
RMI
RMIRMI
RMI
 
Rmi
RmiRmi
Rmi
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
 
Java RMI Presentation
Java RMI PresentationJava RMI Presentation
Java RMI Presentation
 
Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)
 
Java remote method invocation
Java remote method invocationJava remote method invocation
Java remote method invocation
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
 
Java RMI
Java RMIJava RMI
Java RMI
 
Java RMI Detailed Tutorial
Java RMI Detailed TutorialJava RMI Detailed Tutorial
Java RMI Detailed Tutorial
 
Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)
 
Java rmi
Java rmiJava rmi
Java rmi
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
 
Rmi ppt-2003
Rmi ppt-2003Rmi ppt-2003
Rmi ppt-2003
 
remote method invocation
remote method invocationremote method invocation
remote method invocation
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
 

Viewers also liked

Java RMI
Java RMIJava RMI
Java RMI
Ankit Desai
 
Ravi Tuppad
Ravi TuppadRavi Tuppad
Ravi Tuppad
Raviraj Tuppad
 
Basic java
Basic java Basic java
Basic java
Raghu nath
 
remote method invocation
remote method invocationremote method invocation
remote method invocation
Arun Nair
 
Networking
NetworkingNetworking
Networking
Ravi Kant Sahu
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theory
Mukesh Tekwani
 
Jdbc 1
Jdbc 1Jdbc 1
Distributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIDistributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMI
elliando dias
 
Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8
Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8
Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8
helpsoft01
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
Manjunatha RK
 
Java servlets
Java servletsJava servlets
Java servlets
Mukesh Tekwani
 
Overview of big data in cloud computing
Overview of big data in cloud computingOverview of big data in cloud computing
Overview of big data in cloud computing
Viet-Trung TRAN
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
Peter R. Egli
 
Unit 1 architecture of distributed systems
Unit 1 architecture of distributed systemsUnit 1 architecture of distributed systems
Unit 1 architecture of distributed systems
karan2190
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
Rupsee
 
Designing Teams for Emerging Challenges
Designing Teams for Emerging ChallengesDesigning Teams for Emerging Challenges
Designing Teams for Emerging Challenges
Aaron Irizarry
 

Viewers also liked (16)

Java RMI
Java RMIJava RMI
Java RMI
 
Ravi Tuppad
Ravi TuppadRavi Tuppad
Ravi Tuppad
 
Basic java
Basic java Basic java
Basic java
 
remote method invocation
remote method invocationremote method invocation
remote method invocation
 
Networking
NetworkingNetworking
Networking
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theory
 
Jdbc 1
Jdbc 1Jdbc 1
Jdbc 1
 
Distributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIDistributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMI
 
Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8
Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8
Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
Java servlets
Java servletsJava servlets
Java servlets
 
Overview of big data in cloud computing
Overview of big data in cloud computingOverview of big data in cloud computing
Overview of big data in cloud computing
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
 
Unit 1 architecture of distributed systems
Unit 1 architecture of distributed systemsUnit 1 architecture of distributed systems
Unit 1 architecture of distributed systems
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
 
Designing Teams for Emerging Challenges
Designing Teams for Emerging ChallengesDesigning Teams for Emerging Challenges
Designing Teams for Emerging Challenges
 

Similar to Introduction To Rmi

Rmi
RmiRmi
ADB Lab Manual.docx
ADB Lab Manual.docxADB Lab Manual.docx
ADB Lab Manual.docx
SaiKumarPrajapathi
 
17rmi
17rmi17rmi
17rmi
Adil Jafri
 
Remote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programmingRemote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programming
Gera Paulos
 
Rmi
RmiRmi
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
Sonali Parab
 
Rmi
RmiRmi
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
kamal kotecha
 
Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVA
elliando dias
 
Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMI
backdoor
 
Call Back
Call BackCall Back
Call Back
leminhvuong
 
Call Back
Call BackCall Back
Call Back
phanleson
 
Call Back
Call BackCall Back
Call Back
leminhvuong
 
Call Back
Call BackCall Back
Call Back
leminhvuong
 
Module 1 Introduction
Module 1   IntroductionModule 1   Introduction
Module 1 Introduction
leminhvuong
 
Rmi3
Rmi3Rmi3
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
Thesis Scientist Private Limited
 
Rmi
RmiRmi
DS
DSDS
Java RMI
Java RMIJava RMI
Java RMI
Sunil OS
 

Similar to Introduction To Rmi (20)

Rmi
RmiRmi
Rmi
 
ADB Lab Manual.docx
ADB Lab Manual.docxADB Lab Manual.docx
ADB Lab Manual.docx
 
17rmi
17rmi17rmi
17rmi
 
Remote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programmingRemote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programming
 
Rmi
RmiRmi
Rmi
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Rmi
RmiRmi
Rmi
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 
Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVA
 
Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMI
 
Call Back
Call BackCall Back
Call Back
 
Call Back
Call BackCall Back
Call Back
 
Call Back
Call BackCall Back
Call Back
 
Call Back
Call BackCall Back
Call Back
 
Module 1 Introduction
Module 1   IntroductionModule 1   Introduction
Module 1 Introduction
 
Rmi3
Rmi3Rmi3
Rmi3
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 
Rmi
RmiRmi
Rmi
 
DS
DSDS
DS
 
Java RMI
Java RMIJava RMI
Java RMI
 

Introduction To Rmi

  • 1. Introduction To RMI By Swarup Kulkarni (MCA-II, VIT, Pune)
  • 2. Remote Method Invocation RMI - Remote Method Invocation Allows to invoke a method of a Java object that executes on another machine. Important feature, because it allows to build distributed applications. Lets discus a simple Client/Server application using RMI. The server receives a request from client and processes it In this req. two numbers are specified Server add these numbers and returns it 3/11/2009 2 RMI - Swarup Kulkarni
  • 3. Step 1: Enter and Compile the Source Code We use four source files - First source file: RmiDemoIntf.java Defines remote interface, a remote method, All remote interfaces must inherit Remote interface Remote interface is a part of java.rmi.remote Defines no members , purpose is to indicate that interface uses remote methods. All remote methods can throw RemoteException 3/11/2009 3 RMI - Swarup Kulkarni
  • 4. Step 1: (Continued..) The first source file - Code: RmiDemoIntf.java import java.rmi.*; public interface RmiDemoIntf extends Remote { double add(double d1, double d2) throws RemoteException; } 3/11/2009 4 RMI - Swarup Kulkarni
  • 5. Step 1: (Continued..) The second source file: RmiDemoImpl.java Implements Remote interface implementation of the add( ) method is straightforward All remote objects must extend UnicastRemoteObject UnicastRemoteObject provides functionality that is needed to make objects available from remote machines 3/11/2009 5 RMI - Swarup Kulkarni
  • 6. Step 1: (Continued..) The second source file - Code: RmiDemoImpl.java import java.rmi.*; import java.rmi.server.*; public class RmiDemoImpl extends UnicastRemoteObject implements RmiDemoIntf{ public double add(double d1, double d2) throws RemoteException { return d1 + d2; } } 3/11/2009 6 RMI - Swarup Kulkarni
  • 7.
  • 8. First argument names server as “RmiServer”
  • 9. Second argument is reference to object of RmiDemoImpl3/11/2009 7 RMI - Swarup Kulkarni
  • 10. Step 1: (Continued..) The third source file - Code: RmiServer.java import java.net.*; import java.rmi.*; public class RmiServer{ public static void main(String args[]) { try { RmiDemoImpl obj_RmiDemoImpl = new RmiDemoImpl(); Naming.rebind(“RmiServer", obj_RmiDemoImpl); } catch(Exception e) { System.out.println("Exception: " + e); } } } 3/11/2009 8 RMI - Swarup Kulkarni
  • 11. Step 1: (Continued..) The forth source file: RmiClient.java Implements client side of this distributed application. Requires thee main things – IP address or name of server, and the two numbers to be added. We create a string that follows URL syntax. The URL includes IP or Name of the server and the string “RmiServer”. The program invokes lookup() method from Naming class which accepts rmi URL as argument and returns a reference of object of RmiDemoIntf . Now all the remote method invocations can be directed to this object. 3/11/2009 9 RMI - Swarup Kulkarni
  • 12. Step 1: (Continued..) The forth source file - Code: RmiClient.java import java.rmi.*; public class RmiClient { public static void main(String args[]) { try { double d1 = 24.73; double d2 = 11.12; String RmiDemoURL = "rmi://" + “127.0.0.1” + "/RmiServer"; //127.0.0.1 is loopback address replace it with server IP/name RmiDemoIntf obj = (RmiDemoIntf)Naming.lookup(RmiDemoURL); 3/11/2009 10 RMI - Swarup Kulkarni
  • 13. Step 1: (Continued..) RmiClient.java(Contd..) System.out.println("The first number is: " + d1); System.out.println("The second number is: " + d2); System.out.println("The sum is: " + RmiDemoIntf.add(d1, d2)); }//end of try catch(Exception e) { System.out.println("Exception: " + e); }//end of catch }//end of main }//end of class 3/11/2009 11 RMI - Swarup Kulkarni
  • 14. Step 2: Generate Stubs and Skeletons Before using client and server we have to generate stub and skeleton. Stub resides on client machine. Remote method calls initiated by client are directed to stub. A remote method can have simple arguments or objects as arguments. Objects may have reference to other objects, to send whole information to server the objects in arguments must be serialized. Skeletons are not required by Java 2.(Needed for compatibility with java1.1) Skeleton resides on sever machine, when it receives request, it performs deserialization and invokes appropriate method. In case of response to client, the process works reverse. 3/11/2009 12 RMI - Swarup Kulkarni
  • 15. Step 2: (Continued..) How to generate stub and Skeleton? Use a tool called RMI Compiler, which is invoked from command line: rmic RmiDemoImpl; This command generates two new files: RmiDemoImpl_Skel.class (skeleton) and RmiDemoImpl_Stub.class (stub). Before using rmic make sure that CLASSPATH is set to include current directories. rmic by default generates stub as well as skeleton, we have option to suppress it. 3/11/2009 13 RMI - Swarup Kulkarni
  • 16. Step 3: Install Files on Client and Server Copy RmiDemo.class, RmiDemoImpl_Stub.class, and RmiDemoImpl.class on the client machine. Copy RmiDemontf.class, RmiDemoImpl.class, RmiDemompl_Skel.class, RmiDemompl_Stub.class, and RmiDemo.class on the server machine. 3/11/2009 14 RMI - Swarup Kulkarni
  • 17. Step 4: Start the RMI Registry on the Server The Java 2 SDK provides a program called rmiregistry, which executes on server. The rmiregistry maps names to object reference. First, check that the CLASSPATH environment variable includes the directory in which your files are located and start RMI Registry: start rmiregistry When this command runs, it creates a new window. Leave that window open until the experimentation finishes. 3/11/2009 15 RMI - Swarup Kulkarni
  • 18. Step 5: The Experiment The server code is started from the command line, as shown here: java RmiServer Recall that the RmiServer code instantiates RmiDemoImpl and registers that object with the name “RmiServer”. The client code is started from command line as shown here: java RmiClient Output of progarm: The first number is: 24.73 The second number is: 11.12 The sum is: 35.85 3/11/2009 16 RMI - Swarup Kulkarni
  • 19. 3/11/2009 17 RMI - Swarup Kulkarni Thank You