JAVA REMOTE METHOD INVOCATION
(RMI)
Mohammad Masudur Rahman
mor543@mail.usask.ca
Department of Computer Science
University...
2
TUTORIAL CONTENTS
Java Remote Method Invocation
 Historical Background
 Related Terminologies
 RMI System Architecture
...
JAVA REMOTE METHOD INVOCATION

Fig: Distributed Object Technology

4
JAVA REMOTE METHOD INVOCATION
RMI Server, client, interface, stubs, skeletons
 RMI Registry
 Object version of RPC
 Met...
HISTORICAL BACKGROUND
Abstraction: Low
level

Java
Sockets
by SUN

Abstraction:
Procedure level

Java RPC
by SUN
Abstracti...
RELATED TERMINOLOGIES
RPC (Remote Procedure Call)
 XDR (External Data Representation)
 CORBA (Common Object Request Brok...
RMI SYSTEM ARCHITECTURE
Lets divide into two perspectives:
 Layered Structure
 Working Principles

8
RMI LAYERED STRUCTURE

Fig: RMI Layered Structure

9
RMI LAYERED STRUCTURE
Application layer: Server, Client
 Interface: Client stub, Server skeleton
 Remote Reference layer...
RMI WORKING PRINCIPLES

Fig: RMI Working principles

11
READY TO DEVELOP ONE?

12
A SIMPLE RMI APPLICATION

1

SERVER
oWriting an Interface
o Implementing an
Interface
o Binding Interface

CLIENT
o Writin...
SERVICE INTERFACE: AN AGREEMENT
BETWEEN SERVER & CLIENT


Factorial Operation



Check Prime Operation



Square Operat...
SERVER APPLICATION: WRITING A SERVICE
INTERFACE

15

Fig: MathService Interface
SERVER APPLICATION: IMPLEMENTING THE
SERVICE INTERFACE

16

Fig: MathServiceProvider implements MathService Interface
SERVER APPLICATION: INSTANTIATING &
BINDING THE SERVICE

17

Fig: Instantiating and Binding MathService Interface
A SIMPLE RMI APPLICATION

1

SERVER
oWriting an Interface
o Implementing an
Interface
o Binding Interface

CLIENT
o Writin...
CLIENT APPLICATION: SERVICE LOOKUP

Fig: Client locating MathService service
19
CLIENT APPLICATION: ACCESSING SERVICE

Fig: Client accessing MathService service

20
A SIMPLE RMI APPLICATION

1

SERVER
oWriting an Interface
o Implementing an
Interface
o Binding Interface

CLIENT
o Writin...
SERVER DEPLOYMENT: START RMI
REGISTRY


To start RMI registry on windows



To start RMI registry on Unix

22
SERVER DEPLOYMENT: COMPILE THE
SERVER


Compile both MathService interface and
MathServiceProvider class

23
SERVER DEPLOYMENT: CREATE SERVER
STUB


Create the server stub that will handle client call

24
SECURITY DEPLOYMENT: CREATE SECURITY
POLICY FILE (BOTH CLIENT & SERVER)
Create a security policy file called no.policy wit...
START THE SERVER


Execute the command to run server

26
SERVER RUNNING

27
START THE CLIENT


Execute the command to run client

28
CLIENT INTERFACE

29
ADVANCED CONCEPTS
Java Object Serialization
 Parameter Marshalling & Demarshalling
 Object Activation


30
STRENGTH OF JAVA RMI
Object Oriented: Can pass complex object rather
than only primitive types
 Mobile Behavior: Change o...
STRENGTH OF JAVA RMI
Connects to Legacy Systems: JNI & JDBC
facilitate access.
 Write Once, Run Anywhere: 100% portable, ...
WEAKNESS OF JAVA RMI
Tied to Java System: Purely Java-centric
technology, does not have good support for legacy
system wri...
CASE STUDY: JAVA RMI

VS.

CORBA

34
CASE STUDY: JAVA RMI
Language Dependence:
 RMI service interface is in
Java
 CORBA service interface is
platform indepen...
CASE STUDY: JAVA RMI
Ease of Use:
 RMI is easy to master for
experienced programmers.
 CORBA is a rich, extensive
family...
JAVA RMI CUSTOMERS
IBM
 Swiss Federal Supreme Court
 CEAS Consulting
 Avitek
 Different Chat service Company
 More ca...
CORBA CUSTOMERS
USA AG
 Cisco Systems
 American Airlines
 BHP Information Technology
 More can be found here:
http://w...
CASE STUDY: JAVA RMI

VS.

CORBA

Results of case study:
o
o

No one is better than other necessarily
Applicability of one...
CONCLUSION
Distributed Object Technology
 Object level abstraction
 Object version of Java RPC
 Java centric Technology...
THANK YOU !!! QUESTIONS PLEASE?

41
REFERENCES
[1].Advantages of java RMI
http://www.oracle.com/technetwork/java/javase/tech/index-jsp-138781.html
[2] Java RM...
Upcoming SlideShare
Loading in...5
×

Java RMI Presentation

2,136

Published on

A simplified tutorial for Java RMI

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,136
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
140
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Hello everybody, welcome to my presentation.This is Mohammad Masudur Rahman.Today, I am going to talk about a very interesting topic about distributed computing called Remote Method Invocation.Hope you will enjoy the topic.
  • RMI is copyrighted by Sun Micro systemCurrently SUN is taken by Oracle, so, now this technology belongs to Oracle corporation.
  • In my presentation, I am going to cover the following topics I am not going to read it out, but we will try to go step by step.
  • Before discussing about Java RMI,the very first thing I would like to focus.What is a distributed object technology (DOT)?Also, what is the difference between web application and web service?So, concept is pretty simple like this diagram. When a machine can access the functionality of an object situated in a remote machine and exploit the computation power of the remote machine, then we can call it as a distributed object technology (DOT)Java RMI is a perfect example of distributed object technology. Other similar types of technology is CORBA, SOAP etc.
  • As mentioned, Java RMI is a distributed object based technology that means it provides object level abstraction to the developer.For example, the developer needs to access some functionality of a remote object, Java RMI manages to allow the developers to call that remote object from his program just like a local class object. This was a cool thing when the concept was first started by Sun Microsystems and whole features were packaged as a Java Library with SDK.It is also considered as an object version of Java RPC which provides procedure level abstraction to the developer.Java RMI is basically a Java based technology and any machine containing JVM can host a distributed object server or client. However, it involves several components like service interface, RMI registry, skeleton, stubs etc which will discuss in the later slides.The are also some advanced features related to RMI like object serialization, parameter marshalling on which we will try to provide some overview.
  • Lets take a look into the technology hierarchy.The primary communication technology is Socket in Java : abstraction is low level, that means developer needs to think about more details about the technology rather than his application which is time-consuming.The next level is RPC, which provides method level abstraction, that means to call a remote method, you have to provide the method name and parameters though some RPC Client to get access to the functionality; that means, still you need to care about method name, type and # of parameters which may not be comfortable for all.The next level is object level technology which provides object level abstraction. Other parallel object technology is CORBA by OMG and SOAP by Microsoft.CORBA is C++ in server, but the service interface is implemented in IDL (Interface definition language) which is platform independent, so, any client can communicate with it. IDL creates different service interfaces for different clients.SOAP is mainly intended for web service architecture. Any client having access to WSDL file can actually access the service.
  • XDR = External data representation, a data format for network transmission, developed by Sun Microsystems, 1980 Encoding > XDR >Decoding of data.Base unit is 4 bytes.CORBA= Common Object Request Broker Architecture, client and server both communicate with the ORB (Object Request Broker) to get and provide service.IIOP = ORB protocol over the Internet which started on 1994 to provide a greater degree of interoperability.Java IDL = Provides Java interface definition to different other languages.RMI IIOP=Java RMI over IIOP, that means RMI uses IIOP to exploit the CORBA features like OMG IDL or non-java platform access.
  • Lets focus on RMI architecture. The discussion will be two-folds:Layered based architectureWorking principles based
  • Here, we can see a list of layers in the RMI protocol.In the application layer, there are client and server who are the end-consumer and end-producer of the service. They communicate with intermediate layer called stub-skeleton layer.In stub-skeleton layer, stub is related to client application which actually transmits the request to the next level. The skeleton is a component which is associated with server and is responsible to make the actual request to the server.Remote reference layer contains the RMI registry and it works like a ORB in CORBA, that means, it handles the request and response between client and server. Once the client gets the remote object reference from the RMI registry, it can make request and this layer transmits that request to the appropriate server. Again, when server responds, it also sends back the response to the client. It also manages other advanced tasks like object activation , object serialization management, distributed garbage collection etc.Transport layer handles network communication between client and server.
  • We have discussed these already.
  • Now comes the working principles.We can see the following steps:Client requests for the remote object reference to naming serviceOnce the naming service locates the server host, RMI registry provides a stub (proxy) of remote object.Client can make call using the stubBasically, the request from the stub is sent to the server skeleton which makes the actual request to the remote object.Similarly, the server response is sent back through skeleton and stub to the client.
  • Now, we will show how to develop a simple RMI application.
  • There are 3 major steps for this development.Service contract establishment and server application developmentClient application developmentDeployment of service
  • First comes the service contract.Suppose, the client and server are agreed upon this contract that there will be 3 operations:Factorial operationPrime check operationSquare operationI kept the examples simple for easy understanding.
  • And here is the complete interface. We developed it using Java interface. We named it MathService.
  • Here, the serverapplication implements the service interface.
  • This code binds the MathService to the RMI registry so that client app can get the reference of the serviceAnd consume the service.Interestingly, client can actually access the reference of interface MathService to make call, however, the respond is provided by the object implementing the service.
  • Now comes the client application development.
  • Here, we can see, client accesses the Naming. lookup() method to get the reference of the remote object.
  • Once it gets the reference, client can call the method just like it is calling a local object method.This is the strength of Java RMI technology.
  • Now comes the deployment.
  • We need to start the RMI registry service to deploy the remote object; server object.
  • Here we are compiling both service and server object.
  • Then we are creating skeleton of server object. This step is deprecated from JDK 1.5 as JDK automatically creates it.The developer does not need to do it manually now.
  • Now comes the crucial part on which often most of time we get stuck.That is the security policy of Java RMI.The default security does not support the RMI call, so, we need to set custom permission for the call to the security manager.This phase is required for both the client and server.Basically, we have to create a <any name>.policy file with this content. Here, we allowed all types of call associated with Java RMI;That is why it contains AllPermission.
  • This is how the server object should be deployed.
  • This is how we did.
  • This is how the client needs to be run for RMI service access. Please note that we have to specify the host name.
  • This is how we did for the client. However, we also developed the Java object serialization by this time.
  • There are advance stuffs which I would like to provide some overview.Java Object serialization: It involves converting the object into a sequence of byte streams where there needs a swapping of java object between client and the server. Basically, if client or server uses a user-defined class as parameters, then they need the object serialization.Parameter Marshalling is a type of serialization for parameters handled by the stub-skeleton layer. Demarshalling refers to de-serialization.Object Activation: In some scenarios, server may not be running always, then object reference layer activates the target remote object (server) to enable it to respond to the client’s request. Common for infrequent RMI call.The detail discussion of those topics is beyond this tutorial, because each of them will be a single tutorial.
  • These are strengths of Java RMI.-Object oriented, object level abstraction.-Mobile behavior: that means the roles between client and server can be exchanged easily.-It supports the design pattern-sate and secure like the Java technology.
  • -It can support the legacy system.-Write once, run everywhere-Distributed garbage collection, like the one provide by Java.-facilitates the parallel computing.-Widely supported by different versions of JDK, as it was from the beginning, JDK 1.1
  • It also got some weaknesses.-Tied to Java system, that means it a Java only technology, cant communicate well with the non-java platform.-Due to byte code step, the computation is slower.-Additional complexity for security which many developers didn’t like.-Extra step with rmic compilation
  • Now, we will do a comparative study between RMI and its parallel technologyCORBA
  • We will choose several perspective to compare between these two technologies:Language dependence: Java is tied to Java, that means client server and interface all are in java, but its not the case in CORBA. The core/server of CORBA in C++, but the IDL provides language specific service interface, so that any client can call the server. This makes CORBA platform language independent service.Mobile behavior: Java RMI can show it as the roles between client and server can be easily exchanged; not possible for CORBAPerformance Issue: For byte code step, Java RMI fall backs in heavy computation. On the other hand, C++ of CORBA is compiling language and performs faster
  • There are more:4. Ease of use: RMI is easy to use, but CORBA is complex and may not easy for all.5. Maturity: CORBA is a matured technology and already lots of applications are using this technology, whereas RMI is less matured compared to it.
  • Java RMI has got several big customers due to its remarking features.
  • CORBA is a well established technology and started earlier than RMI. It got huge audience. Please check the link for details.Few are shown here.
  • So>None is better than otherYou need to choose based on the scope and type of the technical requirements.For example, if you need low overhead, easy to use technique and platform independence is not a requirement, then you can choose RMIFor opposite reasons, you can choose CORBA, but beware of the expertise of the developers
  • So, we have got couple of conclusions to make.Discuss on your own.
  • Java RMI Presentation

    1. 1. JAVA REMOTE METHOD INVOCATION (RMI) Mohammad Masudur Rahman mor543@mail.usask.ca Department of Computer Science University of Saskatchewan Saskatoon, SK, S7N5C9 Date: April 09, 2013
    2. 2. 2
    3. 3. TUTORIAL CONTENTS Java Remote Method Invocation  Historical Background  Related Terminologies  RMI System Architecture   Layered Structures  Working Principles  A Simple RMI Application  Server, Client, Interface, Stubs  Security, Deployment, Invocation Strength & Weakness of RMI  RMI vs. CORBA Case Study  3
    4. 4. JAVA REMOTE METHOD INVOCATION Fig: Distributed Object Technology 4
    5. 5. JAVA REMOTE METHOD INVOCATION RMI Server, client, interface, stubs, skeletons  RMI Registry  Object version of RPC  Method Invocation between JVMs  Java RMI API  JRMP (Java Remote Method Protocol)  Java object serialization  Parameter Marshalling  5
    6. 6. HISTORICAL BACKGROUND Abstraction: Low level Java Sockets by SUN Abstraction: Procedure level Java RPC by SUN Abstraction: Object level CORBA by OMG Java RMI by SUN SOAP by Microsoft 6
    7. 7. RELATED TERMINOLOGIES RPC (Remote Procedure Call)  XDR (External Data Representation)  CORBA (Common Object Request Broker Architecture)  IIOP (Internet Inter-ORB Protocol)  Java IDL (Interface Definition Language)  RMI-IIOP  SOAP (Simple Object Access Protocol)  7
    8. 8. RMI SYSTEM ARCHITECTURE Lets divide into two perspectives:  Layered Structure  Working Principles 8
    9. 9. RMI LAYERED STRUCTURE Fig: RMI Layered Structure 9
    10. 10. RMI LAYERED STRUCTURE Application layer: Server, Client  Interface: Client stub, Server skeleton  Remote Reference layer: RMI registry  Transport layer: HTTP  10
    11. 11. RMI WORKING PRINCIPLES Fig: RMI Working principles 11
    12. 12. READY TO DEVELOP ONE? 12
    13. 13. A SIMPLE RMI APPLICATION 1 SERVER oWriting an Interface o Implementing an Interface o Binding Interface CLIENT o Writing a Client DEPLOYMENT o Manage Security Settings o Running Server & Client 2 3 13
    14. 14. SERVICE INTERFACE: AN AGREEMENT BETWEEN SERVER & CLIENT  Factorial Operation  Check Prime Operation  Square Operation 14
    15. 15. SERVER APPLICATION: WRITING A SERVICE INTERFACE 15 Fig: MathService Interface
    16. 16. SERVER APPLICATION: IMPLEMENTING THE SERVICE INTERFACE 16 Fig: MathServiceProvider implements MathService Interface
    17. 17. SERVER APPLICATION: INSTANTIATING & BINDING THE SERVICE 17 Fig: Instantiating and Binding MathService Interface
    18. 18. A SIMPLE RMI APPLICATION 1 SERVER oWriting an Interface o Implementing an Interface o Binding Interface CLIENT o Writing a Client DEPLOYMENT o Manage Security Settings o Running Server & Client 2 3 18
    19. 19. CLIENT APPLICATION: SERVICE LOOKUP Fig: Client locating MathService service 19
    20. 20. CLIENT APPLICATION: ACCESSING SERVICE Fig: Client accessing MathService service 20
    21. 21. A SIMPLE RMI APPLICATION 1 SERVER oWriting an Interface o Implementing an Interface o Binding Interface CLIENT o Writing a Client DEPLOYMENT o Manage Security Settings o Running Server & Client 2 3 21
    22. 22. SERVER DEPLOYMENT: START RMI REGISTRY  To start RMI registry on windows  To start RMI registry on Unix 22
    23. 23. SERVER DEPLOYMENT: COMPILE THE SERVER  Compile both MathService interface and MathServiceProvider class 23
    24. 24. SERVER DEPLOYMENT: CREATE SERVER STUB  Create the server stub that will handle client call 24
    25. 25. SECURITY DEPLOYMENT: CREATE SECURITY POLICY FILE (BOTH CLIENT & SERVER) Create a security policy file called no.policy with the following content and add it to CLASSPATH  This step implies for both server and client  25
    26. 26. START THE SERVER  Execute the command to run server 26
    27. 27. SERVER RUNNING 27
    28. 28. START THE CLIENT  Execute the command to run client 28
    29. 29. CLIENT INTERFACE 29
    30. 30. ADVANCED CONCEPTS Java Object Serialization  Parameter Marshalling & Demarshalling  Object Activation  30
    31. 31. STRENGTH OF JAVA RMI Object Oriented: Can pass complex object rather than only primitive types  Mobile Behavior: Change of roles between client and server easily  Design Patterns: Encourages OO design patterns as objects are transferred  Safe & Secure: The security settings of Java framework used  Easy to Write /Easy to Use: Requires very little coding to access service  31
    32. 32. STRENGTH OF JAVA RMI Connects to Legacy Systems: JNI & JDBC facilitate access.  Write Once, Run Anywhere: 100% portable, run on any machine having JVM  Distributed Garbage Collection: Same principle like memory garbage collection  Parallel Computing: Through multi-threading RMI server can serve numerous clients  Distributed Computing Solutions: Available from JDK 1.1, can communicate between all versions of JDKs  32
    33. 33. WEAKNESS OF JAVA RMI Tied to Java System: Purely Java-centric technology, does not have good support for legacy system written in C, C++, Ada etc.  Performance Issue : Only good for large-grain computation  Security Restrictions & Complexities: Threats during downloading objects from server, malicious client request, added security complexity in policy file.  Overhead: Extra usage of rmic tool.  33
    34. 34. CASE STUDY: JAVA RMI VS. CORBA 34
    35. 35. CASE STUDY: JAVA RMI Language Dependence:  RMI service interface is in Java  CORBA service interface is platform independent VS. CORBA Mobile Behavior  Server and client can change roles in RMI  Not feasible in CORBA Performance Issue:  RMI needs extra overhead for conversion from byte code to machine code CORBA performs better for massive computation like fluid mechanics 35
    36. 36. CASE STUDY: JAVA RMI Ease of Use:  RMI is easy to master for experienced programmers.  CORBA is a rich, extensive family of standards, hard to master VS. CORBA Maturity of Technology  RMI is less matured  CORBA is more matured and already has many implementations running 36
    37. 37. JAVA RMI CUSTOMERS IBM  Swiss Federal Supreme Court  CEAS Consulting  Avitek  Different Chat service Company  More can be found here: http://www.cs.mun.ca/~paul8/jdk1.2beta3/docs/guid e/rmi/examples.html  37
    38. 38. CORBA CUSTOMERS USA AG  Cisco Systems  American Airlines  BHP Information Technology  More can be found here: http://www.corba.org/success.htm  38
    39. 39. CASE STUDY: JAVA RMI VS. CORBA Results of case study: o o No one is better than other necessarily Applicability of one on another depends on  Purpose of the application  Experience of the designer and developer  Necessity of interoperability with non-java systems. 39
    40. 40. CONCLUSION Distributed Object Technology  Object level abstraction  Object version of Java RPC  Java centric Technology  Comparable to CORBA, SOAP  Provides non-java support with the help IDL, IIOP and CORBA  Lightweight and Easy to use  Object serialization  Concurrent support for clients  40
    41. 41. THANK YOU !!! QUESTIONS PLEASE? 41
    42. 42. REFERENCES [1].Advantages of java RMI http://www.oracle.com/technetwork/java/javase/tech/index-jsp-138781.html [2] Java RMI architecture. http://www.cs.mun.ca/michael/java/jdk1.1-beta2docs/guide/rmi/rmi-arch.doc.html [3] Introduction to java RMI http://www.javacoffeebreak.com/articles/javarmi/javarmi.html. [4] Java RMI: Remote method invocation. http://www1.cs.columbia.edu/dcc/nestor/presentations/java-rmi/java-rmihandouts.pdf [5] Disadvantages of RMI. http://www.coderanch.com/t/180297/javadeveloperSCJD/certification/RMI-Advantages-Disadvantages. [6] Background of java rmi. http://docs.oracle.com/javase/1.5.0/docs/guide/rmi/spec/rmi-intro2.html. [7] How RMI works. http://www.sce.carleton.ca/netmanage/simulator/rmi/RMIExplanation.htm Please contact mor543@mail.usask.ca to get more. 42
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×