1 / 89

RMI Observing the Distributed Pattern .

RMI Observing the Distributed Pattern . . Adrian German Lecturer, Computer Science Indiana University Bloomington. RMI Observing the Distributed Pattern . . Java. Adrian German

isi
Télécharger la présentation

RMI Observing the Distributed Pattern .

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RMI Observing the Distributed Pattern. Adrian German Lecturer, Computer Science Indiana University Bloomington

  2. RMI Observing the Distributed Pattern. Java Adrian German Lecturer, Computer Science Indiana University Bloomington

  3. join

  4. registered

  5. join

  6. registered

  7. join

  8. registered

  9. broadcast

  10. broadcast “Hello!”

  11. broadcast( ) “Hello!”

  12. broadcast( ) “Hello!”

  13. “Hello!” “Hello!” “Hello!”

  14. client

  15. client client

  16. client client client

  17. client client server client

  18. client client server (host) client

  19. client client server (host) client The difference is that the server is listed in the phone book.

  20. client client server (host) client The difference is that the server is listed in the phone book (while a client isn’t).

  21. client client server (host) client How do we implement this?

  22. client client server (host) client

  23. client server (host)

  24. client server (host) class Server { Client[] clients; void broadcast(String message) { ... } int register(Client client) { ... } }

  25. client server (host) class Server { Client[] clients; void broadcast(String message) { ... } int register(Client client) { ... } } class Client { void register(int index, Client client) { ... } void update(Message msg) { ... } }

  26. client server (host) class Server { Client[] clients; void broadcast(String message) { ... } int register(Client client) { ... } } class Client { void register(int index, Client client) { ... } void update(Message msg) { ... } } Clients call the server's broadcast method in turn, which calls the clients' update.

  27. client server (host)

  28. server client

  29. server client

  30. server client f

  31. server client f f client.f(...) callsserver.f(...)

  32. server client g f f client.f(...) callsserver.f(...) which in turn calls client.g(...)

  33. server client g f f client.f(...) callsserver.f(...) which in turn calls client.g(...) The question is: how do we turn this code into a distributed program?

  34. server client g f f client.f(...) callsserver.f(...) which in turn calls client.g(...) The question is: how do we turn this code into a distributed program?

  35. (Hawaii) server Internet client (Sweden) g f f Internet client.f(...) callsserver.f(...) which in turn calls client.g(...) this local program The question is: how do we turn this code into a distributed program?

  36. even simpler

  37. server client value returned fun() add() function call

  38. server client value returned fun() add() class LocalProgram { public static void main(String[] args) { Server a = new Server(); Client b = new Client(); b.fun(a); } } function call class Server { int add(int a, int b) { return a + b; } } class Client { void fun(Server server) { System.out.println(server.add(1, 2)); } }

  39. server client value returned fun() add() class LocalProgram { public static void main(String[] args) { Server a = new Server(); Client b = new Client(); b.fun(a); } } function call • Important questions: • who creates the server? • who creates the client? • does the client really initiate anything?

  40. server client value returned fun() add() function call The difference between local and distributed computing is real. Differences are impossible to ignore at least in the following areas: a) latency, b) memory access, c) partial failure, and d) concurrency. ... that is, at least at the present time as well as in the near future.

  41. server client value returned fun() add() function call abstract class NetworkPeer implements java.rmi.Remote { public void exportMethods() throws java.rmi.RemoteException { java.rmi.server.UnicastRemoteObject.exportObject(this); } public java.rmi.Remote locatePeer(String peerHost, int peerPort, String peerName) throws Exception { return java.rmi.Naming.lookup("rmi://" + peerHost + ":" + peerPort + "/" + peerName); } public void startAsNetworkClient(String peerHost, int peerPort, String peerName) throws Exception { this.exportMethods(); java.rmi.Remote peer = this.locatePeer(peerHost, peerPort, peerName); this.startAsClientOf(peer); // see below ... } public abstract void startAsClientOf(java.rmi.Remote peer) throws java.rmi.RemoteException; public abstract void startAsServer(); // ... start as local server }

  42. server client value returned fun() add() function call abstract class NetworkPeer implements java.rmi.Remote { public void exportMethods() throws java.rmi.RemoteException { java.rmi.server.UnicastRemoteObject.exportObject(this); } public java.rmi.Remote locatePeer(String peerHost, int peerPort, String peerName) throws Exception { return java.rmi.Naming.lookup("rmi://" + peerHost + ":" + peerPort + "/" + peerName); } public void startAsNetworkClient(String peerHost, int peerPort, String peerName) throws Exception { this.exportMethods(); java.rmi.Remote peer = this.locatePeer(peerHost, peerPort, peerName); this.startAsClientOf(peer); // see below ... } public abstract void startAsClientOf(java.rmi.Remote peer) throws java.rmi.RemoteException; public abstract void startAsServer(); // ... start as local server } Distributed processing is a world of free agents. The class above is all that an object needs to become a free agent. Any object.

More Related