IADCS Diploma Course
Distributed Programming with Java




                 U Nyein Oo
                 COO/Director(IT)
 ...
Why Distributed Application?

    Most of development and deployment

    environments are Networked
    Applications des...
Client/Server Systems?

    Client requests resource from Server


    Server accept the client’s request and

    proce...
Three components of CSS

    User Interface Layer( implemented by

    application client like web browser)
    Informati...
IPL at Client Machine

                                                         Server Machine
       Client Machine


   ...
IPL at Server Machine


       Client Machine                          Server Machine


      User                        ...
Different type of Method Invocation

    Distributed Computing Environment(DCE)


    Distributed Components Object

   ...
Distributed Computing
Environment(DCE)

     Industry standard of the OSF(Open Software
 
     Foundation)
     Vendor-ne...
How Distributed Systems work?

    Organized into cell(which is nothing but a

    group of processing resources,services...
The services and Technologies used
within DCE Cell

    Directories Service


    Distributed File Service(DFS)


    Di...
What is a DCOM?

    Distributed Component Object Model


    Product of Microsoft Corporation


    Started with OLE te...
DCOM(cont)

    COM is object oriented whereas DCE is

    procedural oriented
    A model ,programming Language can be
...
DCOM(cont)

    DCOM is distributed COM over multiple

    computers.
    Local Object invokes the methods of Local

   ...
CORBA

    Common Object Request Broker Architecture

    Most popular architecture for building

    distributed object...
Method invocation in CORBA

  Client Host                                        Server Host

           client           ...
Benefits using CORBA

    Open standard and works on all platforms


    Both clients and servers can be distributed


 ...
Why Java Distributed Object Model
Need?

    TCP Socket is big Overhead


    DCE ‘s RPC does not gel with Java OODA.


...
RMI (your best choice for java)

    JavaSoft design for Object oriented

    distributed pure java application.
    RMI ...
RMI(cont;)

    Make differences between DO model and

    Local Java Object model apparent.
    Writing reliable distrib...
RMI Architecture

    JDOM is simply extension of JOM

    Objects interact each other within same JVM

    in Java’s Ob...
Advantages using Remote Interface


      Allows server objects to differentiate between
  
      their local and remote ...
Three tier Architecture of Java RMI

           Client                                          Server
           Object  ...
Inside RMI


          Explain java.rmi packages:
      
           – java.rmi
           – java.rmi.registry
           ...
java.rmi Package

    This package provides the remote interface


    It does not have any methods


    It supports th...
java.rmi.registry Package

    This package provides classes                  and

    interfaces for remote registry



...
java.rmi.server Package

    This package implements remote stubs and skeletons


    It is also used to support RMI comm...
java.rmi.activation Package

        This package is used to activate remote objects, when needed
    

        It consis...
java.rmi.dgc Package

    This package provides classes and

    interfaces that the RMI distributed garbage
    collecto...
Three Tiered Layering of Java RMI




        The client object evokes the methods of stub
    

        The stub uses th...
Implementing RMI

     Implementing RMI involves two                 steps
 
     namely:
      – Implementing RMI on Rem...
Implementing RMI on Remote Host

      Step 1
  

      Create a remote interface:
           This has to be public and m...
Implementing RMI on Remote Host
    (Contd…)

       Step 3
   
       Create stub and skeleton classes using the rmic co...
Implementing RMI on Local Host




        Once RMI is implemented on the remote host, the
    

        remote server is...
Genreation Remote Interface


//remote interface
import java.net.*;
import java.security.*;
import java.rmi.*;
public inte...
Generation Client RMI

import java.rmi.RMISecurityManager;
import java.rmi.Naming;
import java.net.*;
import java.security...
Generation Server RMI

import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.security.*;
im...
Generation Server RMI (cont)

public String getAndSetMessage(String message)throws RemoteException{

        return(quot;M...
Steps to Compilation

    Compilation Remote Interface File

             (same as regular .java file)
    Compilation Re...
Steps to Compilation(cont)

   Starting rmi registry
 

      >start rmiregistry
  Run as follow

   >java –Djava.securi...
Example-2(Remote Interface)

    //Remote Interface
    import java.rmi.*;
    import java.net.*;

    public interface Se...
Client Remote

import java.rmi.*;
import java.net.*;
import java.rmi.server.*;
public class Client1 {
    public static vo...
Server Remote

 import java.rmi.*;
 import java.rmi.server.*;
 import java.rmi.registry.*;
 public class Server1Impl exten...
Server Remote (cont)


 public Server1Impl() throws RemoteException { }

  public void doSomething() throws RemoteExceptio...
Invoke rmi registry & Run Client
Remote




                                                   44
Copyright : MCC   Distri...
Running Remote Server




                                                   45
Copyright : MCC   Distributed Computing wi...
Upcoming SlideShare
Loading in...5
×

Distributed Programming using RMI

2,117

Published on

Published in: Business, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

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

No notes for slide

Distributed Programming using RMI

  1. 1. IADCS Diploma Course Distributed Programming with Java U Nyein Oo COO/Director(IT) Myanma Computer Co., Ltd
  2. 2. Why Distributed Application? Most of development and deployment  environments are Networked Applications design to be distributed  (which is become necessary) Process is distributed across multiple  networked computers Implemented as Client/server Systems.  2 Copyright : MCC Distributed Computing with Jav
  3. 3. Client/Server Systems? Client requests resource from Server  Server accept the client’s request and  process and give result back to client Typically there are three components in  client/server system. 3 Copyright : MCC Distributed Computing with Jav
  4. 4. Three components of CSS User Interface Layer( implemented by  application client like web browser) Information Processing Layer( implemented  by application client/server/server support) Information Storage Layer( implemented by  database server like web server,FTP server) 4 Copyright : MCC Distributed Computing with Jav
  5. 5. IPL at Client Machine Server Machine Client Machine User Information Information Interface Processing Storage Layer Layer Layer (Web (Application (Application Client) Server) Browser) 5 Copyright : MCC Distributed Computing with Jav
  6. 6. IPL at Server Machine Client Machine Server Machine User Information Information Interface Processing Storage Layer Layer Layer (Web (Application (Application Client) Server) Browser) 6 Copyright : MCC Distributed Computing with Jav
  7. 7. Different type of Method Invocation Distributed Computing Environment(DCE)  Distributed Components Object  Model(DCOM) Common Object Request Broker Architecture  (CORBA) Java’s Remote Methods Invocation(RMI)  7 Copyright : MCC Distributed Computing with Jav
  8. 8. Distributed Computing Environment(DCE) Industry standard of the OSF(Open Software  Foundation) Vendor-neutral set of Distributed Computing  Provide security services to protect and  control access to data Run of the major computing platforms and  designed to support distributed application Key Technology for security,www and  Distributed Objec 8 Copyright : MCC Distributed Computing with Jav
  9. 9. How Distributed Systems work? Organized into cell(which is nothing but a  group of processing resources,services and users that support a common function and share a common set of DCE devices) For example …separate department in a  company like(admin,finance..ect) 9 Copyright : MCC Distributed Computing with Jav
  10. 10. The services and Technologies used within DCE Cell Directories Service  Distributed File Service(DFS)  Distributed Time Service(DTS)  Security Service  Remote Procedure Calls(RPC)  DCE Threads  10 Copyright : MCC Distributed Computing with Jav
  11. 11. What is a DCOM? Distributed Component Object Model  Product of Microsoft Corporation  Started with OLE technology that used to  support compound documents.(one that is product of multiple application) COM is solution for OLE and different from  DCE in its design approach. 11 Copyright : MCC Distributed Computing with Jav
  12. 12. DCOM(cont) COM is object oriented whereas DCE is  procedural oriented A model ,programming Language can be  used COM to create distributed application DCOM allows a COM object on one  computer to access methods of another COM object on some other computers. The remote object is accessed the same  manner as the local object. 12 Copyright : MCC Distributed Computing with Jav
  13. 13. DCOM(cont) DCOM is distributed COM over multiple  computers. Local Object invokes the methods of Local  COM library of the remote object it is trying to access. COM library process the functions calls using  COM runtime COM Runtime communicate using Object  RPC The most important feature is application  security is based on Windows NT Policy. 13 Copyright : MCC Distributed Computing with Jav
  14. 14. CORBA Common Object Request Broker Architecture  Most popular architecture for building  distributed object oriented application Is open standard not tied to particular vendor  Objects are accessible via ORBs  The client interface to ORB is written by  IDLKnown as IDL stub The Server interface to ORB is IDL Skeleton  14 Copyright : MCC Distributed Computing with Jav
  15. 15. Method invocation in CORBA Client Host Server Host client Server Object Object IDL IDL Stub Skeleton ORB 15 Copyright : MCC Distributed Computing with Jav
  16. 16. Benefits using CORBA Open standard and works on all platforms  Both clients and servers can be distributed  Language independent  Just have to provide IDL interface to object  An international standard and recognized by  most of software vendors. 16 Copyright : MCC Distributed Computing with Jav
  17. 17. Why Java Distributed Object Model Need? TCP Socket is big Overhead  DCE ‘s RPC does not gel with Java OODA.  DCOM has good performance for Windows  and does not support java object fully. CORBA is excellent but Java programmer  will have to learn IDL to develop DJA. 17 Copyright : MCC Distributed Computing with Jav
  18. 18. RMI (your best choice for java) JavaSoft design for Object oriented  distributed pure java application. RMI also need client stub & server skeleton  Support seamless remote invocation on  objects in different VMs. Support callbacks from server to applets.  Integrated DO model into Java Language  18 Copyright : MCC Distributed Computing with Jav
  19. 19. RMI(cont;) Make differences between DO model and  Local Java Object model apparent. Writing reliable distributed applications as  simple as possible. Preserve the type-safety provided by the  Java Runtime Environment Save Java environment provided by security  managers and class loaders. 19 Copyright : MCC Distributed Computing with Jav
  20. 20. RMI Architecture JDOM is simply extension of JOM  Objects interact each other within same JVM  in Java’s Object Model Objects interact with an object in another  JVM at Java Distributed Object Model Client Object(local object) does not reference  directly on Server Object(remote object) and references a remote interface 20 Copyright : MCC Distributed Computing with Jav
  21. 21. Advantages using Remote Interface Allows server objects to differentiate between  their local and remote interface Present different access modes  No need to have server class file at the  compilation of client objects RMI follow like CORBA except ORB  RMI Setup the Remote Reference Layer  21 Copyright : MCC Distributed Computing with Jav
  22. 22. Three tier Architecture of Java RMI Client Server Object Object Stub Skeleton Remote Reference Layer Remote Reference Layer Transport Layer Transport Layer Lower Layer Protocols Lower Layer Protocols 22 Copyright : MCC Distributed Computing with Jav
  23. 23. Inside RMI Explain java.rmi packages:  – java.rmi – java.rmi.registry – java.rmi.server – java.rmi.activation – java.rmi.dgc Three tiered layering of Java RMI  23 Copyright : MCC Distributed Computing with Jav
  24. 24. java.rmi Package This package provides the remote interface  It does not have any methods  It supports the following classes:  MarshalledObject class – Naming class – RMISecurityManager class – It defines exceptions such as RemoteException  24 Copyright : MCC Distributed Computing with Jav
  25. 25. java.rmi.registry Package This package provides classes and  interfaces for remote registry 25 Copyright : MCC Distributed Computing with Jav
  26. 26. java.rmi.server Package This package implements remote stubs and skeletons  It is also used to support RMI communications  It consists of the following classes:  RemoteObject class – RemoteServer class – RMILoader class – Operation class – LogStream class – 26 Copyright : MCC Distributed Computing with Jav
  27. 27. java.rmi.activation Package This package is used to activate remote objects, when needed  It consists of the following classes:  Activable class – ActivationDesc class – getClassName( )  getCodeSource( )  getData( )  getGroupID( )  getRestartMode( )  ActivationGroup class – 27 Copyright : MCC Distributed Computing with Jav
  28. 28. java.rmi.dgc Package This package provides classes and  interfaces that the RMI distributed garbage collector uses The server side of the distributed garbage  collector uses this package It has two methods, dirty( ) and clean( ),  which indicate that the client has referenced a remote object, and that the remote reference has been completed, respectively 28 Copyright : MCC Distributed Computing with Jav
  29. 29. Three Tiered Layering of Java RMI The client object evokes the methods of stub  The stub uses the remote layer to communicate with the  skeleton The remote layer uses the transport layer to establish the  connection between local and remote server 29 Copyright : MCC Distributed Computing with Jav
  30. 30. Implementing RMI Implementing RMI involves two steps  namely: – Implementing RMI on Remote Host – Implementing RMI on Local Host 30 Copyright : MCC Distributed Computing with Jav
  31. 31. Implementing RMI on Remote Host Step 1  Create a remote interface: This has to be public and must extend the Remote interface – This method must throw RemoteException – Step 2  Create a class that implements the remote interface: This class should create and initialize the remote object – It should implement all the methods defined in the remote – interface There should be a main( ) method that will be executed as a – remote class This main( ) method should also take care of security using the – setSecurityManager( ) method 31 Copyright : MCC Distributed Computing with Jav
  32. 32. Implementing RMI on Remote Host (Contd…) Step 3  Create stub and skeleton classes using the rmic command. Step 4  Copy the remote interface and stub file to the client host. Step 5  Start the Remote Registry Server using the command start rmiregistry. Step 6  Execute the program using the java command to create an object of class. This class registers itself with the remote registry 32 Copyright : MCC Distributed Computing with Jav
  33. 33. Implementing RMI on Local Host Once RMI is implemented on the remote host, the  remote server is up and running Create a client program to remotely invoke the  method of the object, and display the results 33 Copyright : MCC Distributed Computing with Jav
  34. 34. Genreation Remote Interface //remote interface import java.net.*; import java.security.*; import java.rmi.*; public interface MyServer extends java.rmi.Remote{ String getAndSetMessage(String message) throws java.rmi.RemoteException; } 34 Copyright : MCC Distributed Computing with Jav
  35. 35. Generation Client RMI import java.rmi.RMISecurityManager; import java.rmi.Naming; import java.net.*; import java.security.*; public class MyClient{ public static void main(String args[]){ System.setSecurityManager(new RMISecurityManager()); try{ MyServerser=(MyServer)Naming.lookup(quot;//147.81.10.2/ServerTestquot;); String serverString=ser.getAndSetMessage(quot;I amd Trying quot;); System.out.println(quot;reply from the server is quot;+serverString); }catch(Exception e){ System.out.println(e); } } 35 } Copyright : MCC Distributed Computing with Jav
  36. 36. Generation Server RMI import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; import java.security.*; import java.net.*; public class MyServerImpl extends UnicastRemoteObject implements MyServer{ static String hostName=quot;147.81.10.2quot;; String name; public MyServerImpl(String name) throws RemoteException{ super(); this.name=name; } 36 Copyright : MCC Distributed Computing with Jav
  37. 37. Generation Server RMI (cont) public String getAndSetMessage(String message)throws RemoteException{ return(quot;My name is quot;+name+quot;Thanks for messagequot;+message); } public static void main(String args[]){ System.setSecurityManager(new RMISecurityManager()); try{ String objectname=quot;Servertestquot;; MyServerImpl theServer=new MyServerImpl(objectname); Naming.rebind(quot;//quot;+hostName+quot;/quot;+objectname,theServer); System.out.println(quot;I am Registeredquot;); }catch(Exception e) { System.out.println(e); } 37 Copyright : }} MCC Distributed Computing with Jav
  38. 38. Steps to Compilation Compilation Remote Interface File  (same as regular .java file) Compilation Remote Client File  (same as regular .java file) Compilation Remote Server File  I.same as regular .java file II. User rmic compiler to create stub and skeleton class files like c:jdk1.3.1bin>rmic MyServerImpl 38 Copyright : MCC Distributed Computing with Jav
  39. 39. Steps to Compilation(cont) Starting rmi registry  >start rmiregistry  Run as follow >java –Djava.security.policy=policy MyServerIMpl  Edit policy for permission grant 39 Copyright : MCC Distributed Computing with Jav
  40. 40. Example-2(Remote Interface) //Remote Interface import java.rmi.*; import java.net.*; public interface Server1 extends Remote { public void doSomething() throws RemoteException; } 40 Copyright : MCC Distributed Computing with Jav
  41. 41. Client Remote import java.rmi.*; import java.net.*; import java.rmi.server.*; public class Client1 { public static void main(String[] args) { System.setSecurityManager(new RMISecurityManager()); try { Server1 ro = (Server1)Naming.lookup(quot;doSomethingquot;); System.out.println(quot;Location: quot;+System.getProperty(quot;LOCATIONquot;)); ro.doSomething(); } catch (Exception e){ e.printStackTrace(); System.exit(-1); } } 41 Copyright : MCC Distributed Computing with Jav }
  42. 42. Server Remote import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; public class Server1Impl extends java.rmi.server.UnicastRemoteObject implements Server1 { public static void main(String[] args) { System.setSecurityManager(new RMISecurityManager()); try { Server1Impl obj = new Server1Impl(); Naming.rebind(quot;doSomethingquot;, obj); System.out.println(quot;doSomething bound in registryquot;); } catch (Exception e) { e.printStackTrace(); return; } 42 } Copyright : MCC Distributed Computing with Jav
  43. 43. Server Remote (cont) public Server1Impl() throws RemoteException { } public void doSomething() throws RemoteException { System.out.println(quot;This message is printed by the Server1 objectquot;); System.out.println(quot;Location: quot; + System.getProperty(quot;LOCATIONquot;)); } } 43 Copyright : MCC Distributed Computing with Jav
  44. 44. Invoke rmi registry & Run Client Remote 44 Copyright : MCC Distributed Computing with Jav
  45. 45. Running Remote Server 45 Copyright : MCC Distributed Computing with Jav
  1. A particular slide catching your eye?

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

×