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

Slides:



Advertisements
Similar presentations
15-May-15 RMI Remote Method Invocation. 2 “The network is the computer” Consider the following program organization: If the network is the computer, we.
Advertisements

Remote Method Invocation in Java Bennie Lewis EEL 6897.
Advanced Programming Rabie A. Ramadan Lecture 4. A Simple Use of Java Remote Method Invocation (RMI) 2.
Java Remote Method Invocation (RMI) In Java we implement object systems: O1O2 O3 thread 1thread 2 execution scheme JVM 1JVM 2 distribution scheme.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Remote Method Invocation
Remote Object Invocation Tran, Van Hoai Department of Systems & Networking Faculty of Computer Science & Engineering HCMC University of Technology.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
DISTRIBUTED FILE SYSTEM USING RMI
EEC-681/781 Distributed Computing Systems Lecture 5 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
CSE331: Introduction to Networks and Security Lecture 11 Fall 2002.
Introduction to Remote Method Invocation (RMI)
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
How Does Remote Method Invocation Work? –Systems that use RMI for communication typically are divided into two categories: clients and servers. A server.
Java RMI RMI = Remote Method Invocation. Allows Java programs to invoke methods of remote objects. Only between Java programs. Several versions (JDK-1.1,
Internet Software Development Remote Method Invocation Paul Krause.
1 Java Programming II Java Network II (Distributed Objects in Java)
CS 584 Lecture 18 l Assignment » Glenda assignment extended to the Java RMI Deadline » No Java RMI Assignment l Test » Friday, Saturday, Monday.
Architecture of Software Systems RMI and Distributed Components Martin Rehák.
15 - RMI. Java RMI Architecture Example Deployment RMI is a part of J2SE (standard edition), but is used by J2EE) A J2EE server is not nessesary for using.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
Distributed Real- Time in the RTSJ Andrew Borg. Presentation RMI – A brief introduction The RTSJ – A (very) brief introduction The DRTSJ – The 3 Levels.
In the name of Allah The Proxy Pattern Elham moazzen.
1 Java RMI G53ACC Chris Greenhalgh. 2 Contents l Java RMI overview l A Java RMI example –Overview –Walk-through l Implementation notes –Argument passing.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
RMI RMI is the java API that facilitate distributed computing by allowing remote method calls. A remote method call represents a method invocation between.
RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple.
Remote Method Invocation onlineTraining/rmi/RMI.html.
RMI Continued IS Outline  Review of RMI  Programming example.
RMI remote method invocation. Traditional network programming The client program sends data to the server in some intermediary format and the server has.
RMI Remote Method Invocation Distributed Object-based System and RPC Together 2-Jun-16.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 22.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
The Net Worth of an Object-Oriented Pattern Practical Implications of the Java RMI Adrian German Lecturer, Computer Science Department Indiana University.
Li Tak Sing COMPS311F. RMI callbacks In previous example, only the client can initiate a communication with the server. The server can only response to.
Virtual Real-time 3D Object Sharing for Supporting Distance Education and Training Hiroko Suzuki Faculty of Computer and Information Science, Hosei University,
Proxy.
Java Remote Method Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
1 Java Remote Method Invocation java.rmi.* java.rmi.registry.* java.rmi.server.*
Concurrent Computing CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
DISTRIBUTED OBJECTS AND REMOTE INVOCATION 1. 2 Topics  Middleware  Remote Method Invocation  Remote Procedure Call.
 Java RMI Distributed Systems IT332. Outline  Introduction to RMI  RMI Architecture  RMI Programming and a Sample Example:  Server-Side RMI programming.
RMI Example. Compilation: /home2/fccheng/temp/RMI2> javac MyObject.java /home2/fccheng/temp/RMI2> javac RemoteServer.java /home2/fccheng/temp/RMI2> javac.
Florida State UniversityCOP Advanced Unix Programming Remote Method Invocation /rmi/index.html.
Remote Method Invocation A Client Server Approach.
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
Remote Method Invocation RMI architecture stubs and skeletons for remote services RMI server and client in Java Creating an RMI Application step-by- step.
Java RMI. RMI Any object whose methods can be invoked from another Java VM is called a remote object.
1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Netprog Java RMI1 Remote Method Invocation.
Using RMI The Example of A Remote Calculator 1. Parts of A Working RMI System A working RMI system is composed of several parts. –Interface definitions.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Distributed and Parallel Processing George Wells.
Principles of Software Development
The Net Worth of an Object-Oriented Pattern
Java Remote Method Invocation (RMI)
Remote Method Invocation
Remote Method Invocation
Java RMI (more) CS-328 Internet Programming.
Chapter 40 Remote Method Invocation
class PrintOnetoTen { public static void main(String args[]) {
Using RMI -The Example of A Remote Calculator
CS 584 Lecture 18 Assignment Glenda assignment extended to the Java RMI Deadline No Java RMI Assignment Test Friday, Saturday, Monday.
Java Remote Method Invocation
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

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

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

join

registered

join

registered

join

registered

broadcast

“Hello!”

broadcast( ) “Hello!”

broadcast( ) “Hello!”

client

server

client server (host)

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

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

client server (host) How do we implement this?

client server (host)

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)

client server

client

server client f

server client f f client.f(...) calls server.f(...)

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

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

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

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

even simpler

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

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

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

function call server add() client fun() value returned 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.

function call server add() client fun() value returned 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 }

function call server add() client fun() value returned 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.

function call server add() client fun() value returned 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.

function call server add() client fun() value returned 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.

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

class Server { int add(int a, int b) { return a + b; }

public class ServerImplementation extends NetworkPeer implements Server { public static void main(String[] args) { String portNumber = args[0], ownName = args[1]; ServerImplementation here = new ServerImplementation(); here.startAsNetworkServer(ownName, Integer.parseInt(portNumber)); } public void startAsClientOf(java.rmi.Remote peer) { } public void startAsServer() { } public int add(int a, int b) throws java.rmi.RemoteException { System.out.println("I am adding for the audience..."); return a + b; } public interface Server extends java.rmi.Remote { public int add(int a, int b) throws java.rmi.RemoteException; } function call server add() client fun() value returned class ServerImplementation extends NetworkPeer implements Server { public int add(int a, int b) throws java.rmi.RemoteException { return a + b; } public void startAsServer() { } public void startAsClientOf(java.rmi.Remote peer) { } public static void main(String[] args) { String portNumber = args[0], ownName = args[1]; ServerImplementation here = new ServerImplementation(); here.startAsNetworkServer(ownName, Integer.parseInt(portNumber)); } public interface Server extends java.rmi.Remote { public int add(int a, int b) throws java.rmi.RemoteException; }

class Client { void fun(Server server) { System.out.println(server.add(1, 2)); }

public class ClientImplementation extends NetworkPeer { public void startAsClientOf(java.rmi.Remote peer) throws java.rmi.RemoteException { this.fun((Server) peer); } void fun(Server server) throws java.rmi.RemoteException { System.out.println(server.add(2, 3)); } public static void main(String[] args) throws Exception { String ownName = args[0], serverHostName = args[1], serverPortNumber = args[2], serverName = args[3]; ClientImplementation client = new ClientImplementation(); client.startAsNetworkClientOf(serverHostName, Integer.parseInt(serverPortNumber), serverName); } public void startAsServer() { } }

class LocalProgram { public static void main(String[] args) { Server a = new Server(); Client b = new Client(); b.fun(a); }

class LocalSetup { public static void main(String[] args) throws java.rmi.RemoteException { ServerImplementation server = new ServerImplementation(); server.startAsServer(); ClientImplementation client = new ClientImplementation(); client.startAsClientOf(server); } class LocalProgram { public static void main(String[] args) { Server a = new Server(); Client b = new Client(); b.fun(a); }

class LocalSetup { public static void main(String[] args) throws java.rmi.RemoteException { ServerImplementation server = new ServerImplementation(); server.startAsServer(); ClientImplementation client = new ClientImplementation(); client.startAsClientOf(server); } class LocalProgram { public static void main(String[] args) { Server a = new Server(); Client b = new Client(); b.fun(a); }

class LocalSetup { public static void main(String[] args) throws java.rmi.RemoteException { ServerImplementation server = new ServerImplementation(); server.startAsServer(); ClientImplementation client = new ClientImplementation(); client.startAsClientOf(server); }

class LocalSetup { public static void main(String[] args) throws java.rmi.RemoteException { ServerImplementation server = new ServerImplementation(); server.startAsServer(); ClientImplementation client = new ClientImplementation(); client.startAsClientOf(server); }

class LocalSetup { public static void main(String[] args) throws java.rmi.RemoteException { ServerImplementation server = new ServerImplementation(); server.startAsServer(); ClientImplementation client = new ClientImplementation(); client.startAsClientOf(server); } LocalSetup

class LocalSetup { public static void main(String[] args) throws java.rmi.RemoteException { ServerImplementation server = new ServerImplementation(); server.startAsServer(); ClientImplementation client = new ClientImplementation(); client.startAsClientOf(server); } LocalSetup Server

class LocalSetup { public static void main(String[] args) throws java.rmi.RemoteException { ServerImplementation server = new ServerImplementation(); server.startAsServer(); ClientImplementation client = new ClientImplementation(); client.startAsClientOf(server); } LocalSetup Client Server

class LocalSetup { public static void main(String[] args) throws java.rmi.RemoteException { ServerImplementation server = new ServerImplementation(); server.startAsServer(); ClientImplementation client = new ClientImplementation(); client.startAsClientOf(server); } LocalSetup Client Server

class LocalSetup { public static void main(String[] args) throws java.rmi.RemoteException { ServerImplementation server = new ServerImplementation(); server.startAsServer(); ClientImplementation client = new ClientImplementation(); client.startAsClientOf(server); } LocalSetup Client Server

class LocalSetup { public static void main(String[] args) throws java.rmi.RemoteException { ServerImplementation server = new ServerImplementation(); server.startAsServer(); ClientImplementation client = new ClientImplementation(); client.startAsClientOf(server); } LocalSetup Client Server

class LocalSetup { public static void main(String[] args) throws java.rmi.RemoteException { ServerImplementation server = new ServerImplementation(); server.startAsServer(); ClientImplementation client = new ClientImplementation(); client.startAsClientOf(server); } LocalSetup Client Server

class LocalSetup { public static void main(String[] args) throws java.rmi.RemoteException { ServerImplementation server = new ServerImplementation(); server.startAsServer(); ClientImplementation client = new ClientImplementation(); client.startAsClientOf(server); } LocalSetup Client Server

class LocalSetup { public static void main(String[] args) throws java.rmi.RemoteException { ServerImplementation server = new ServerImplementation(); server.startAsServer(); ClientImplementation client = new ClientImplementation(); client.startAsClientOf(server); } LocalSetup Client Server So although there is no network there is already a change of attitude.

public 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 startAsNetworkClientOf(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 void startAsNetworkServer(String name, int port) { System.setSecurityManager(new java.rmi.RMISecurityManager()); try { this.exportMethods(); java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.createRegistry(port); registry.bind(name, this); this.startAsServer(); // see below... System.out.println("Server is ready... "); } catch (Exception e) { System.out.println("Server error: " + e + "... "); } public abstract void startAsServer(); }

public 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 startAsNetworkClientOf(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 void startAsNetworkServer(String name, int port) { System.setSecurityManager(new java.rmi.RMISecurityManager()); try { this.exportMethods(); java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.createRegistry(port); registry.bind(name, this); this.startAsServer(); // see below... System.out.println("Server is ready... "); } catch (Exception e) { System.out.println("Server error: " + e + "... "); } public abstract void startAsServer(); }

public abstract class NetworkPeer implements java.rmi.Remote { public void exportMethods() throws java.rmi.RemoteException {... } public java.rmi.Remote locatePeer(String peerHost, int peerPort, String peerName) throws Exception { return java.rmi.Naming.lookup("rmi://" + peerHost + ":" + peerPort + "/" + peerName); } public void startAsNetworkClientOf(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 void startAsNetworkServer(String name, int port) { System.setSecurityManager(new java.rmi.RMISecurityManager()); try { this.exportMethods(); java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.createRegistry(port); registry.bind(name, this); this.startAsServer(); // see below... System.out.println("Server is ready... "); } catch (Exception e) { System.out.println("Server error: " + e + "... "); } public abstract void startAsServer(); }

public abstract class NetworkPeer implements java.rmi.Remote { public void exportMethods() throws java.rmi.RemoteException {... } public java.rmi.Remote locatePeer(... peerHost,... peerPort,... peerName)... {... } public void startAsNetworkClientOf(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 void startAsNetworkServer(String name, int port) { System.setSecurityManager(new java.rmi.RMISecurityManager()); try { this.exportMethods(); java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.createRegistry(port); registry.bind(name, this); this.startAsServer(); // see below... System.out.println("Server is ready... "); } catch (Exception e) { System.out.println("Server error: " + e + "... "); } public abstract void startAsServer(); }

public abstract class NetworkPeer implements java.rmi.Remote { public void exportMethods() throws java.rmi.RemoteException {... } public java.rmi.Remote locatePeer(... peerHost,... peerPort,... peerName)... {... } public void startAsNetworkClientOf(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 void startAsNetworkServer(String name, int port) { System.setSecurityManager(new java.rmi.RMISecurityManager()); try { this.exportMethods(); java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.createRegistry(port); registry.bind(name, this); this.startAsServer(); // see below... System.out.println("Server is ready... "); } catch (Exception e) { System.out.println("Server error: " + e + "... "); } public abstract void startAsServer(); }

public abstract class NetworkPeer implements java.rmi.Remote { public void exportMethods() throws java.rmi.RemoteException {... } public java.rmi.Remote locatePeer(... peerHost,... peerPort,... peerName)... {... } public void startAsNetworkClientOf(... peerHost,... peerPort,... peerName)... {... } public abstract void startAsClientOf(java.rmi.Remote peer) throws java.rmi.RemoteException; public void startAsNetworkServer(String name, int port) { System.setSecurityManager(new java.rmi.RMISecurityManager()); try { this.exportMethods(); java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.createRegistry(port); registry.bind(name, this); this.startAsServer(); // see below... System.out.println("Server is ready... "); } catch (Exception e) { System.out.println("Server error: " + e + "... "); } public abstract void startAsServer(); }

public abstract class NetworkPeer implements java.rmi.Remote { public void exportMethods() throws java.rmi.RemoteException {... } public java.rmi.Remote locatePeer(... peerHost,... peerPort,... peerName)... {... } public void startAsNetworkClientOf(... peerHost,... peerPort,... peerName)... {... } public abstract void startAsClientOf(java.rmi.Remote peer) throws java.rmi.RemoteException; public void startAsNetworkServer(String name, int port) { System.setSecurityManager(new java.rmi.RMISecurityManager()); try { this.exportMethods(); java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.createRegistry(port); registry.bind(name, this); this.startAsServer(); // see below... System.out.println("Server is ready... "); } catch (Exception e) { System.out.println("Server error: " + e + "... "); } public abstract void startAsServer(); }

public abstract class NetworkPeer implements java.rmi.Remote { public void exportMethods() throws java.rmi.RemoteException {... } public java.rmi.Remote locatePeer(... peerHost,... peerPort,... peerName)... {... } public void startAsNetworkClientOf(... peerHost,... peerPort,... peerName)... {... } public abstract void startAsClientOf(java.rmi.Remote peer) throws java.rmi.RemoteException; public void startAsNetworkServer(String name, int port) { System.setSecurityManager(new java.rmi.RMISecurityManager()); try { this.exportMethods(); java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.createRegistry(port); registry.bind(name, this); this.startAsServer(); // see below... System.out.println("Server is ready... "); } catch (Exception e) { System.out.println("Server error: " + e + "... "); } public abstract void startAsServer(); }

tucotuco.cs.indiana.edu% pwd /nfs/paca/san/r1a0l1/dgerman/october-21 tucotuco.cs.indiana.edu% ls -ld *.java -rw-r--r-- 1 dgerman faculty 761 Oct 21 00:59 ClientImplementation.java -rw-r--r-- 1 dgerman faculty 293 Oct 21 00:57 LocalSetup.java -rw-r--r-- 1 dgerman faculty 1524 Oct 21 00:54 NetworkPeer.java -rw-r--r-- 1 dgerman faculty 117 Oct 21 00:59 Server.java -rw-r--r-- 1 dgerman faculty 551 Oct 21 01:06 ServerImplementation.java tucotuco.cs.indiana.edu% javac *.java tucotuco.cs.indiana.edu% rmic NetworkPeer tucotuco.cs.indiana.edu% rmic ServerImplementation tucotuco.cs.indiana.edu% java ServerImplementation Dirac burrowww.cs.indiana.edu% pwd /nfs/paca/san/r1a0l1/dgerman/october-21 burrowww.cs.indiana.edu% ls -ld * -rw-r--r-- 1 dgerman faculty 975 Oct 21 01:34 ClientImplementation.class -rw-r--r-- 1 dgerman faculty 761 Oct 21 00:59 ClientImplementation.java -rw-r--r-- 1 dgerman faculty 498 Oct 21 01:34 LocalSetup.class -rw-r--r-- 1 dgerman faculty 293 Oct 21 00:57 LocalSetup.java -rw-r--r-- 1 dgerman faculty 1938 Oct 21 01:34 NetworkPeer.class -rw-r--r-- 1 dgerman faculty 1524 Oct 21 00:54 NetworkPeer.java -rw-r--r-- 1 dgerman faculty 908 Oct 21 01:34 NetworkPeer_Skel.class -rw-r--r-- 1 dgerman faculty 482 Oct 21 01:34 NetworkPeer_Stub.class -rw-r--r-- 1 dgerman faculty 191 Oct 21 01:34 Server.class -rw-r--r-- 1 dgerman faculty 117 Oct 21 00:59 Server.java -rw-r--r-- 1 dgerman faculty 886 Oct 21 01:34 ServerImplementation.class -rw-r--r-- 1 dgerman faculty 551 Oct 21 01:06 ServerImplementation.java -rw-r--r-- 1 dgerman faculty 1611 Oct 21 01:34 ServerImplementation_Skel.class -rw-r--r-- 1 dgerman faculty 3134 Oct 21 01:34 ServerImplementation_Stub.class burrowww.cs.indiana.edu% java ClientImplementation Larry tucotuco.cs.indiana.edu Dirac burrowww.cs.indiana.edu% java LocalSetup I am adding for the audience... 5 burrowww.cs.indiana.edu% java ServerImplementation Dirac Server is ready... I am adding for the audience... tucotuco.cs.indiana.edu% java ClientImplementation Larry burrowww.cs.indiana.edu Dirac

More sophisticated example:

In this last example topology was more general. Clients were also acting as servers. The only difference is that they still need a moderator to start participating.

Conclusions 1. The NetworkPeer abstraction successfully summarizes the "RMI recipe". 2. The LocalSetup program allows for the local development and testing. 3. The use of this pattern is similar to the use of the MVC pattern. 4. Clients need to be implemented as Threads. Their synchronization rules must be as simple as possible. As "decentralized" as possible, so as to not assume the existence of the OS. 5. Using the programmer's API the application can run both ways. 6. This approach is good when few developers and use of Java is preferred. 7. Further work will address the question: does an extremely unreliable network breaks any of the above? Unreliable means: lost references, exceptions are actually the rule, etc.