1
CMSC 433 – Programming Language Technologies and Paradigms
Java RMI
2
Distributed Computing
- Programs that cooperate and communicate
- ver a network
Distributed Computing Programs that cooperate and communicate over - - PDF document
CMSC 433 Programming Language Technologies and Paradigms Java RMI Distributed Computing Programs that cooperate and communicate over a network E-mail Web server and web client SETI @Home 2 1 Distributed Computing
2
3
4
5
6
// runs on one mach. class ChatServerImpl implements ChatServer ... { public void say(String s) { System.out.println(s); } ... } class Chatter { // runs on another mach. public static void main(String args[]) { ChatServer c = // get remote object; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.print(“> “); c.say(br.readLine()); } } }
7 8
9
10
11
12
13
14
15
16
– The value zero specifies the use of an anonymous port. Might use a different port to avoid firewalled ports – Use anonymous ports for your project
17 18
19
20
interface Server extends Remote { Connection logon(String name, Client c) throws RemoteException; public Map<String,Client> getUsers() throws RemoteException; }
21
interface Connection extends Remote { /** Say to everyone */ void say(String msg) throws RemoteException; / ** Say to one person */ void say(String who, String msg) throws RemoteException; String [] getUsers() throws RemoteException; void logoff() throws RemoteException; }
22
interface Client extends Remote { void said(String who, String msg) throws RemoteException; void usersChanged(String [] who) throws RemoteException; }
23
24
25
26
lookup returns stub
27
28
String “Bill” Stub for c Method: logon
… marshalled args to server process
29
String “Bill” Stub for c Method: logon
… from client process
unmarshalled arguments
30
call logon …
… create new Connection object
31
… return this as the result
Stub for conn Return value:
… to client process
32
Stub for conn Return value:
… from server process
unmarshalled return value
33
System.setSecurityManager( new RMISecurityManager());
34
grant { permission java.net.SocketPermission “*: 1024-65535”, “connect,accept”; permission java.net.SocketPermission “*:80”, “connect”; };