890 likes | 1.01k Views
RMI Observing the Distributed Pattern . . Adrian German Lecturer, Computer Science Indiana University Bloomington. RMI Observing the Distributed Pattern . . Java. Adrian German
E N D
RMI Observing the Distributed Pattern. Adrian German Lecturer, Computer Science Indiana University Bloomington
RMI Observing the Distributed Pattern. Java Adrian German Lecturer, Computer Science Indiana University Bloomington
broadcast “Hello!”
broadcast( ) “Hello!”
broadcast( ) “Hello!”
“Hello!” “Hello!” “Hello!”
client client
client client client
client client server client
client client server (host) client
client client server (host) client The difference is that the server is listed in the phone book.
client client server (host) client The difference is that the server is listed in the phone book (while a client isn’t).
client client server (host) client How do we implement this?
client client server (host) client
client server (host)
client server (host) class Server { Client[] clients; void broadcast(String message) { ... } int register(Client client) { ... } }
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) { ... } }
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.
client server (host)
server client
server client
server client f
server client f f client.f(...) callsserver.f(...)
server client g f f client.f(...) callsserver.f(...) which in turn calls client.g(...)
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?
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?
(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?
server client value returned fun() add() function call
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)); } }
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?
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.
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 }
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.