• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
RMI Fundamentals
 

RMI Fundamentals

on

  • 1,590 views

 

Statistics

Views

Total Views
1,590
Views on SlideShare
1,588
Embed Views
2

Actions

Likes
2
Downloads
111
Comments
0

1 Embed 2

http://www.slideshare.net 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    RMI Fundamentals RMI Fundamentals Presentation Transcript

    • RMI Fundamentals Chung-Kai Chen -1-
    • What is RMI? • Remote Method Invocation • A way to invoke the methods of a object that resides in a remote site. • Similar with RPC, but incorporating OO concepts. -2-
    • The Primary Goal of RMI • The remote objects is used with just the same syntax and semantics as the local objects! • How do we achieve this goal? -3-
    • public class B { public void method1() { ... } public int method2(double d) { ... } ... } ... ... ... b.method1(); ... ... B b = new B(); ... ... m.k(b); ... ... ... Local Remote -4-
    • The tricks • Use a local object serving as an agent to send our requests to the remote object and receive any results. • Such a object is called stub. • There used to be an object called skeleton residing in the remote side to handle the requests, but is no more needed after Java 1.2. -5-
    • Extract the interface public interface R extends Remote { public void method1() throws RemoteException; public int method2(double d) throws RemoteException; } public class B implements R { public void method1() throws RemoteException { ... } public int method2(double d) throws RemoteException { ... ... } ... ... R r; } ... ... ... try { ... r.method1(); } catch (RemoteException e) { B b = new B(); ... ... } ... ... ... m.k(r); ... ... Local Remote -6-
    • Export the service (1) public interface R extends Remote { public void method1() throws RemoteException; public int method2(double d) throws RemoteException; } public class B extends UnicastRemoteObject implements R { public B() throws RemoteException { super(); } public void method1() throws RemoteException { ... } ... public int method2(double d) ... throws RemoteException { R r; ... ... } ... ... try { } r.method1(); } catch (RemoteException e) { ... ... ... } try { ... B b = new B(); ... } catch (RemoteException e) { m.k(r); ... ... } ... ... ... Local Remote -7-
    • Export the service (2) public interface R extends Remote { public void method1() throws RemoteException; public int method2(double d) throws RemoteException; } public class B implements R { public void method1() throws RemoteException { ... } public int method2(double d) throws RemoteException { ... } ... ... ... } R r; ... ... ... try { ... r.method1(); try { } catch (RemoteException e) { B b = new B(); ... UnicastRemoteObject } .exportObject(b); ... } catch (RemoteException e) { ... ... m.k(r); } ... ... ... ... Local Remote -8-
    • Registration (1) public interface R extends Remote { public void method1() throws RemoteException; public int method2(double d) throws RemoteException; } public class B extends UnicastRemoteObject implements R { public B() throws RemoteException { super(); } public void method1() throws RemoteException { ... } public int method2(double d) throws RemoteException { ... ... } ... ... R r; } ... ... rmiregistry & ... try { ... r.method1(); try { } catch (RemoteException e) { B b = new B(); ... Naming.rebind(quot;rmi://host:port/namequot;, b); } } catch (Exception e) { ... ... ... } m.k(r); ... ... ... ... Local Remote -9-
    • Registration (2) public interface R extends Remote { public void method1() throws RemoteException; public int method2(double d) throws RemoteException; } public class B extends UnicastRemoteObject implements R { public B() throws RemoteException { super(); } public void method1() throws RemoteException { ... } public int method2(double d) throws RemoteException { ... ... } ... ... R r; } ... ... ... try { ... r.method1(); try { } catch (RemoteException e) { B b = new B(); ... Registry rmiR = LocateRegistry.createRegistry(1099); } rmiR.rebind(quot;rmi://host:port/namequot;, b); ... } catch (Exception e) { ... ... m.k(r); } ... ... ... ... Local Remote -10-
    • Get the stub (1) public interface R extends Remote { public void method1() throws RemoteException; public int method2(double d) throws RemoteException; } public class B extends UnicastRemoteObject implements R { public B() throws RemoteException { super(); } public void method1() throws RemoteException { ... } public int method2(double d) throws RemoteException { ... ... } ... ... R r; } try { r = (R) (Naming.lookup( rmiregistry & ... quot;rmi://host:port/namequot;)); ... r.method1(); try { } catch (Exception e) { B b = new B(); ... Naming.rebind(quot;rmi://host:port/namequot;, b); } } catch (Exception e) { ... ... ... } m.k(r); ... ... ... ... Local Remote -11-
    • Get the stub (2) public interface R extends Remote { public void method1() throws RemoteException; public int method2(double d) throws RemoteException; } public class B extends UnicastRemoteObject implements R { public B() throws RemoteException { super(); } public void method1() throws RemoteException { ... } public int method2(double d) throws RemoteException { ... ... } ... ... R r; } try { Registry rmiR = ... LocateRegistry. ... getRegistry(1099); try { r = (R) (rmiR.lookup( B b = new B(); quot;rmi://host:port/name)); Registry rmiR = LocateRegistry.createRegistry(1099); r.method1(); rmiR.rebind(quot;rmi://host:port/namequot;, b); } catch (Exception e) { } catch (Exception e) { ... ... } } ... ... ... ... m.k(r); ... ... Local Remote -12-
    • Generate the Stub public interface R extends Remote { public void method1() throws RemoteException; public int method2(double d) throws RemoteException; } public class B extends UnicastRemoteObject implements R { public B() throws RemoteException { super(); rmic } B_stub.class public void method1() throws RemoteException { ... } public int method2(double d) throws RemoteException { ... ... } ... ... R r; } try { Registry rmiR = ... LocateRegistry. ... getRegistry(1099); try { r = (R) (rmiR.lookup( B b = new B(); quot;rmi://host:port/name)); Registry rmiR = LocateRegistry.createRegistry(1099); r.method1(); rmiR.rebind(quot;rmi://host:port/namequot;, b); } catch (Exception e) { } catch (Exception e) { ... ... } } ... ... ... ... m.k(r); ... ... Local Remote -13-
    • More about this scheme • The stub takes care of the marshelling of parameters and the unmarshelling of returned results, so as the opposite side. • How data is passed around? – Primitive data – Objects • Object serialization • Stubs is also objects and can be passed as well. • Where is the class? -14-
    • Issues on RMI • Create an object remotely? – Remote Object Activation • Garbage collection? – Distributed Garbage Collection • Portings of RMI? – various way to substitute the transport layer with others • Optimization of RMI? – lots of researches – KaRMI -15-
    • Recommanded Readings • http://java.sun.com/docs/books/tutorial/rmi /index.html • http://developer.java.sun.com/developer/on lineTraining/rmi/RMI.html • http://java.sun.com/j2se/1.4.1/docs/guide/r mi/index.html -16-