Your SlideShare is downloading. ×
0
Java RMI, 17 November 2011
 Methods can be called by another JVM on a  different host Interface is remote if it extends Remote Remote object imple...
    Primitive types are passed by value    Objects (that are not remote)      They are serialized and then passed by va...
    Obtain a reference for the remote object    URL for the remote object is specified as      rmi://host:port/namePemr...
public class HiDunia {  public String sayHalo() {    return "Halo dunia!";  }    public static void main (String args[]) {...
public class Halo {  public String sayHalo() {    return "Hello, world!";  }}public class HaloDunia {  public static void ...
    Satu address space      Code segment      Data segment      Stack segmentPemrograman Terdistribusi   Sistem Terdis...
    Proses berbeda      class Halo      class HaloDunia      mungkin berjalan di node yang sama      atau node berbed...
    Mendefinisikan remote interface    Mengimplementasikan interface (server)      Buat dan ekspor remote object      ...
import java.rmi.Remote;import java.rmi.RemoteException;public interface Hello extends Remote {    String sayHello() throws...
import     java.rmi.Remote;import     java.rmi.registry.Registry;import     java.rmi.registry.LocateRegistry;import     ja...
public static void main(String args[]) {         try {             Server obj = new Server();             Hello stub = (He...
import java.rmi.registry.LocateRegistry;import java.rmi.registry.Registry;public class Client {    private Client() {}    ...
javac –d destDir Server.javajavac –d destDir Client.javastart rmiregistryjava –Djava.rmi.server.codebase=file:destDir/ Ser...
    Default pada port 1099    start rmiregistry 2011    Registry reg =     LocateRegistry.getRegistry(2011);Pemrograman...
    Implementasikan sebuah aplikasi kalkulator     sederhana dengan RMI      Client menerima ekspresi matematika (+, x, ...
    Kerangka program Client      Baca ekspresi matematika      Tokenize, untuk mendapatkan ekspresi       matematik yan...
    Program Server      Implementasikan method-method untuk operasi         dasar matematika        int perkalian(int a...
    Waktu pengerjaan      Dua pekan (30 November 2011, pukul 12.00 WIB)      By e-mail barliant@gmail.com      Subject...
 Java RMI Hello World,  http://download.oracle.com/javase/6/docs/tec  hnotes/guides/rmi/hello/hello-world.html Vijay Gar...
Kamis, 17 November 2011
Upcoming SlideShare
Loading in...5
×

IKH331-07-java-rmi

602

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
602
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "IKH331-07-java-rmi"

  1. 1. Java RMI, 17 November 2011
  2. 2.  Methods can be called by another JVM on a different host Interface is remote if it extends Remote Remote object implements a remote interface and extends UnicastRemoteObjectPemrograman Terdistribusi Sistem Terdistribusi (IKH331) 2
  3. 3.  Primitive types are passed by value Objects (that are not remote)  They are serialized and then passed by value.  At the other end the objects are deserialized  Any references inside the object are also serialized Remote Objects  Passed as remote references (stubs)Pemrograman Terdistribusi Sistem Terdistribusi (IKH331) 3
  4. 4.  Obtain a reference for the remote object URL for the remote object is specified as  rmi://host:port/namePemrograman Terdistribusi Sistem Terdistribusi (IKH331) 4
  5. 5. public class HiDunia { public String sayHalo() { return "Halo dunia!"; } public static void main (String args[]) { String response = this.sayHalo(); System.out.println(response); }}Pemrograman Terdistribusi Sistem Terdistribusi (IKH331) 5
  6. 6. public class Halo { public String sayHalo() { return "Hello, world!"; }}public class HaloDunia { public static void main (String args[]) { Halo kelas = new Halo(); String response = kelas.sayHalo(); System.out.println(response); }}Pemrograman Terdistribusi Sistem Terdistribusi (IKH331) 6
  7. 7.  Satu address space  Code segment  Data segment  Stack segmentPemrograman Terdistribusi Sistem Terdistribusi (IKH331) 7
  8. 8.  Proses berbeda  class Halo  class HaloDunia  mungkin berjalan di node yang sama  atau node berbeda Different address space stub method Remote objectPemrograman Terdistribusi Sistem Terdistribusi (IKH331) 8
  9. 9.  Mendefinisikan remote interface Mengimplementasikan interface (server)  Buat dan ekspor remote object  Registrasi remote object dengan Java RMI registry Mengimplementasikan client Jalankan server Jalankan clientPemrograman Terdistribusi Sistem Terdistribusi (IKH331) 9
  10. 10. import java.rmi.Remote;import java.rmi.RemoteException;public interface Hello extends Remote { String sayHello() throws RemoteException;}Pemrograman Terdistribusi Sistem Terdistribusi (IKH331) 10
  11. 11. import java.rmi.Remote;import java.rmi.registry.Registry;import java.rmi.registry.LocateRegistry;import java.rmi.RemoteException;import java.rmi.server.UnicastRemoteObject;public class Server implements Hello { public Server() {} public String sayHello() { return "Hello, world!"; }Pemrograman Terdistribusi Sistem Terdistribusi (IKH331) 11
  12. 12. public static void main(String args[]) { try { Server obj = new Server(); Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0); // Bind the remote objects stub in the registry Registry registry = LocateRegistry.getRegistry(); registry.bind("Hello", stub); System.err.println("Server ready"); } catch (Exception e) { System.err.println("Server exception: " + e.toString()); e.printStackTrace(); } }}Pemrograman Terdistribusi Sistem Terdistribusi (IKH331) 12
  13. 13. import java.rmi.registry.LocateRegistry;import java.rmi.registry.Registry;public class Client { private Client() {} public static void main(String[] args) { String host = (args.length < 1) ? null : args[0]; try { Registry registry = LocateRegistry.getRegistry(host); Hello stub = (Hello) registry.lookup("Hello"); String response = stub.sayHello(); System.out.println("response: " + response); } catch (Exception e) { System.err.println("Client exception: " + e.toString()); e.printStackTrace(); } }}Pemrograman Terdistribusi Sistem Terdistribusi (IKH331) 13
  14. 14. javac –d destDir Server.javajavac –d destDir Client.javastart rmiregistryjava –Djava.rmi.server.codebase=file:destDir/ Serverjava –Djava.rmi.server.codebase=file:destDir/ ClientPemrograman Terdistribusi Sistem Terdistribusi (IKH331) 14
  15. 15.  Default pada port 1099 start rmiregistry 2011 Registry reg = LocateRegistry.getRegistry(2011);Pemrograman Terdistribusi Sistem Terdistribusi (IKH331) 15
  16. 16.  Implementasikan sebuah aplikasi kalkulator sederhana dengan RMI  Client menerima ekspresi matematika (+, x, /, -)  Server mengimplementasikan method-method yang sesuai Parsing ekspresi matematika dengan StringTokenizer  untuk menentukan method apa yang dipanggilPemrograman Terdistribusi Sistem Terdistribusi (IKH331) 16
  17. 17.  Kerangka program Client  Baca ekspresi matematika  Tokenize, untuk mendapatkan ekspresi matematik yang digunakan  Jika operatornya +, panggil method RMI penjumlahan()  Jika operatornya x, panggil method RMI perkalian()  dstPemrograman Terdistribusi Sistem Terdistribusi (IKH331) 17
  18. 18.  Program Server  Implementasikan method-method untuk operasi dasar matematika  int perkalian(int a, int b);  int pembagian(int a, int b);  int penjumlahan(int a, int b);  int pengurangan(int a, int b);Pemrograman Terdistribusi Sistem Terdistribusi (IKH331) 18
  19. 19.  Waktu pengerjaan  Dua pekan (30 November 2011, pukul 12.00 WIB)  By e-mail barliant@gmail.com  Subject "IKH331 RMI" Bonus  Evaluasi ekspresi yang lebih kompleks  3+4x2  (3 + 4) x 2  Pengumpulan sebelum tenggat waktuPemrograman Terdistribusi Sistem Terdistribusi (IKH331) 19
  20. 20.  Java RMI Hello World, http://download.oracle.com/javase/6/docs/tec hnotes/guides/rmi/hello/hello-world.html Vijay Garg, "Concurrent and Distributed Programming in Java" Source code http://users.ece.utexas.edu/~garg/jbk.html http://tjerdastangkas.blogspot.com/search/la bel/ikh331Pemrograman Terdistribusi Sistem Terdistribusi (IKH331) 20
  21. 21. Kamis, 17 November 2011
  1. A particular slide catching your eye?

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

×