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

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Destaque

remote method invocation
remote method invocationremote method invocation
remote method invocationArun Nair
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theoryMukesh Tekwani
 
Distributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIDistributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIelliando 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-8helpsoft01
 
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 computingViet-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 systemskaran2190
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed SystemsRupsee
 
Designing Teams for Emerging Challenges
Designing Teams for Emerging ChallengesDesigning Teams for Emerging Challenges
Designing Teams for Emerging ChallengesAaron Irizarry
 

Destaque (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
 

Semelhante a 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.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. First argument names server as “RmiServer”
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.