RMI - PowerPoint PPT Presentation

About This Presentation
Title:

RMI

Description:

... server's broadcast method in turn, which calls the clients' update. ... turn calls ... The question is: how do we turn this code into a distributed program? ... – PowerPoint PPT presentation

Number of Views:82
Avg rating:3.0/5.0
Slides: 90
Provided by: adrian94
Category:
Tags: rmi | turn

less

Transcript and Presenter's Notes

Title: RMI


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
(No Transcript)
4
(No Transcript)
5
(No Transcript)
6
(No Transcript)
7
(No Transcript)
8
(No Transcript)
9
join
10
registered
11
join
12
registered
13
join
14
registered
15
(No Transcript)
16
broadcast
17
broadcast
Hello!
18
broadcast( )
Hello!
19
broadcast( )
Hello!
20
Hello!
Hello!
Hello!
21
(No Transcript)
22
client
23
client
client
24
client
client
client
25
client
client
server
client
26
client
client
server (host)
client
27
client
client
server (host)
client
The difference is that the server is listed in
the phone book.
28
client
client
server (host)
client
The difference is that the server is listed in
the phone book (while a client isnt).
29
client
client
server (host)
client
How do we implement this?
30
client
client
server (host)
client
31
client
server (host)
32
client
server (host)
class Server Client clients void
broadcast(String message) ... int
register(Client client) ...
33
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) ...
34
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.
35
client
server (host)
36
server
client
37
server
client
38
server
client
f
39
server
client
f
f
client.f(...) calls server.f(...)
40
server
client
g
f
f
client.f(...) calls server.f(...)
which in turn calls client.g(...)
41
server
client
g
f
f
client.f(...) calls server.f(...)
which in turn calls client.g(...)
The question is how do we turn this code into a
distributed program?
42
server
client
g
f
f
client.f(...) calls server.f(...)
which in turn calls client.g(...)
The question is how do we turn this code into a
distributed program?
43
(Hawaii)
server
Internet
client
(Sweden)
g
f
f
Internet
client.f(...) calls server.f(...)
which in turn calls client.g(...)
this local program
The question is how do we turn this code into a
distributed program?
44
even simpler
45
server
client
value returned
fun()
add()
function call
46
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))
47
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?

48
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.
49
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(t
his) 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
50
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(t
his) 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.
51
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(t
his) 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.
52
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(t
his) 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.
53
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))
54
class Server int add(int a, int b)
return a b
55
public class ServerImplementation extends
NetworkPeer implements Server public static
void main(String args) String portNumber
args0, ownName args1
ServerImplementation here new
ServerImplementation() here.startAsNetworkSe
rver(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
server
client
value returned
fun()
add()
function call
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 args0, ownName
args1 ServerImplementation here new
ServerImplementation() here.startAsNetworkS
erver(ownName, Integer.parseInt(portNumber))
public interface Server extends
java.rmi.Remote public int add(int a, int b)
throws java.rmi.RemoteException
56
class Client void fun(Server server)
System.out.println(server.add(1, 2))
57
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 args0,
serverHostName args1,
serverPortNumber args2,
serverName args3 ClientImplementation
client new ClientImplementation()
client.startAsNetworkClientOf(serverHostName,

Integer.parseInt(serverPortNumber),

serverName) public void startAsServer()

58
class LocalProgram public static void
main(String args) Server a new
Server() Client b new Client()
b.fun(a)
59
class LocalSetup public static void
main(String args) throws java.rmi.RemoteExceptio
n ServerImplementation server new
ServerImplementation() server.startAsServer(
) ClientImplementation client new
ClientImplementation() client.startAsClientO
f(server)
class LocalProgram public static void
main(String args) Server a new
Server() Client b new Client()
b.fun(a)
60
class LocalSetup public static void
main(String args) throws java.rmi.RemoteExceptio
n ServerImplementation server new
ServerImplementation() server.startAsServer(
) ClientImplementation client new
ClientImplementation() client.startAsClientO
f(server)
class LocalProgram public static void
main(String args) Server a new
Server() Client b new Client()
b.fun(a)
61
class LocalSetup public static void
main(String args) throws java.rmi.RemoteExceptio
n ServerImplementation server new
ServerImplementation() server.startAsServer(
) ClientImplementation client new
ClientImplementation() client.startAsClientO
f(server)
62
class LocalSetup public static void
main(String args) throws java.rmi.RemoteExceptio
n ServerImplementation server new
ServerImplementation() server.startAsServer(
) ClientImplementation client new
ClientImplementation() client.startAsClientO
f(server)
63
class LocalSetup public static void
main(String args) throws java.rmi.RemoteExceptio
n ServerImplementation server new
ServerImplementation() server.startAsServer(
) ClientImplementation client new
ClientImplementation() client.startAsClientO
f(server)
LocalSetup
64
class LocalSetup public static void
main(String args) throws java.rmi.RemoteExceptio
n ServerImplementation server new
ServerImplementation() server.startAsServer(
) ClientImplementation client new
ClientImplementation() client.startAsClientO
f(server)
LocalSetup
Server
65
class LocalSetup public static void
main(String args) throws java.rmi.RemoteExceptio
n ServerImplementation server new
ServerImplementation() server.startAsServer(
) ClientImplementation client new
ClientImplementation() client.startAsClientO
f(server)
LocalSetup
Client
Server
66
class LocalSetup public static void
main(String args) throws java.rmi.RemoteExceptio
n ServerImplementation server new
ServerImplementation() server.startAsServer(
) ClientImplementation client new
ClientImplementation() client.startAsClientO
f(server)
LocalSetup
Client
Server
67
class LocalSetup public static void
main(String args) throws java.rmi.RemoteExceptio
n ServerImplementation server new
ServerImplementation() server.startAsServer(
) ClientImplementation client new
ClientImplementation() client.startAsClientO
f(server)
LocalSetup
Client
Server
68
class LocalSetup public static void
main(String args) throws java.rmi.RemoteExceptio
n ServerImplementation server new
ServerImplementation() server.startAsServer(
) ClientImplementation client new
ClientImplementation() client.startAsClientO
f(server)
LocalSetup
Client
Server
69
class LocalSetup public static void
main(String args) throws java.rmi.RemoteExceptio
n ServerImplementation server new
ServerImplementation() server.startAsServer(
) ClientImplementation client new
ClientImplementation() client.startAsClientO
f(server)
LocalSetup
Client
Server
70
class LocalSetup public static void
main(String args) throws java.rmi.RemoteExceptio
n ServerImplementation server new
ServerImplementation() server.startAsServer(
) ClientImplementation client new
ClientImplementation() client.startAsClientO
f(server)
LocalSetup
Client
Server
71
class LocalSetup public static void
main(String args) throws java.rmi.RemoteExceptio
n ServerImplementation server new
ServerImplementation() server.startAsServer(
) ClientImplementation client new
ClientImplementation() client.startAsClientO
f(server)
LocalSetup
Client
Server
So although there is no network there is already
a change of attitude.
72
public abstract class NetworkPeer implements
java.rmi.Remote public void
exportMethods() throws java.rmi.RemoteException
java.rmi.server.UnicastRemoteObject.expo
rtObject(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(peer
Host, peerPort, peerName)
this.startAsClientOf(peer) // see below ...
public abstract void startAsClientOf(java.r
mi.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(po
rt) 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()
73
public abstract class NetworkPeer implements
java.rmi.Remote public void
exportMethods() throws java.rmi.RemoteException
java.rmi.server.UnicastRemoteObject.expo
rtObject(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(peer
Host, peerPort, peerName)
this.startAsClientOf(peer) // see below ...
public abstract void startAsClientOf(java.r
mi.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(po
rt) 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()
74
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(peer
Host, peerPort, peerName)
this.startAsClientOf(peer) // see below ...
public abstract void startAsClientOf(java.r
mi.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(po
rt) 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()
75
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(po
rt) 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()
76
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(po
rt) 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()
77
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.r
mi.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(po
rt) 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()
78
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.r
mi.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(po
rt) 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()
79
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.r
mi.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(po
rt) 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()
80
burrowww.cs.indiana.edu java LocalSetup I am
adding for the audience... 5
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 0059 ClientImplementation.java -rw-r--r-- 1
dgerman faculty 293 Oct 21 0057
LocalSetup.java -rw-r--r-- 1 dgerman faculty
1524 Oct 21 0054 NetworkPeer.java -rw-r--r-- 1
dgerman faculty 117 Oct 21 0059
Server.java -rw-r--r-- 1 dgerman faculty 551
Oct 21 0106 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 16450 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
0134 ClientImplementation.class -rw-r--r-- 1
dgerman faculty 761 Oct 21 0059
ClientImplementation.java -rw-r--r-- 1 dgerman
faculty 498 Oct 21 0134 LocalSetup.class -rw-r--
r-- 1 dgerman faculty 293 Oct 21 0057
LocalSetup.java -rw-r--r-- 1 dgerman faculty
1938 Oct 21 0134 NetworkPeer.class -rw-r--r-- 1
dgerman faculty 1524 Oct 21 0054
NetworkPeer.java -rw-r--r-- 1 dgerman faculty
908 Oct 21 0134 NetworkPeer_Skel.class -rw-r--r--
1 dgerman faculty 482 Oct 21 0134
NetworkPeer_Stub.class -rw-r--r-- 1 dgerman
faculty 191 Oct 21 0134 Server.class -rw-r--r--
1 dgerman faculty 117 Oct 21 0059
Server.java -rw-r--r-- 1 dgerman faculty 886
Oct 21 0134 ServerImplementation.class -rw-r--r--
1 dgerman faculty 551 Oct 21 0106
ServerImplementation.java -rw-r--r-- 1 dgerman
faculty 1611 Oct 21 0134 ServerImplementation_Ske
l.class -rw-r--r-- 1 dgerman faculty 3134 Oct 21
0134 ServerImplementation_Stub.class burrowww.cs.
indiana.edu java ClientImplementation Larry
tucotuco.cs.indiana.edu 16450 Dirac
1
burrowww.cs.indiana.edu java ServerImplementation
16450 Dirac Server is ready ... I am adding for
the audience...
2
4
3
tucotuco.cs.indiana.edu java ClientImplementation
Larry burrowww.cs.indiana.edu 16450 Dirac 5
5
81
More sophisticated example
82
More sophisticated example
83
More sophisticated example
84
More sophisticated example
85
More sophisticated example
86
More sophisticated example
87
More sophisticated example
88
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.
89
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.
Write a Comment
User Comments (0)
About PowerShow.com