Professional Documents
Culture Documents
Java Rmi Handouts 2
Java Rmi Handouts 2
Object
Execution
Thread
Java
Virtual
Machine
akonstan@cs.columbia.edu
11/7/2002
Alexander V. Konstantinou
//
Document myDoc = ;
Printer printer = ;
Java VM
// magic communication
Printer {
void print(Document d) {
// printer-specific protocol
// e.g. postcript }
}
} }
Document myDoc = ;
Printer printer = ;
printer.print(myDoc);
//
printer.print(myDoc);
11/7/2002
Alexander V. Konstantinou
11/7/2002
Generated
Generated
Stub
Proxy
Java VM
11/7/2002
Client
Object
(e.g. Editor)
void print
() { }
Java VM
Alexander V. Konstantinou
Alexander V. Konstantinou
RMI
server
socket
Java VM
11/7/2002
TCP
TCP
Serialiazed
document
Alexander V. Konstantinou
RMI
socket
call
proxy.print
(doc)
Java VM
6
RMI Features
Mobile behavior
Move interface implementation from client to server,
and server to client
Alexander V. Konstantinou
11/7/2002
RMI Terminology
Alexander V. Konstantinou
Alexander V. Konstantinou
Object Oriented
Language Specific
Java Object Serialization
Any object implementing
serialization as parameter
References to local and
remote objects handled
automatically (deep copy)
Mobile code (Java bytecode)
11/7/2002
Alexander V. Konstantinou
10
Client
Server
Stubs
Skeletons
Remote
Reference
Remote
Reference
Transport
11/7/2002
Alexander V. Konstantinou
11
11/7/2002
Alexander V. Konstantinou
12
java.rmi.server
RemoteObject
Remote
IOException
RemoteImpl.class
RemoteException
rmic
RemoteImpl_Skel.class
11/7/2002
Alexander V. Konstantinou
13
11/7/2002
RemoteImpl_Stub.class
Alexander V. Konstantinou
14
Print
Print
Service
Service
Implem.
JVM
Print
Client
Laptop
Server
bind(dccpr,
"DCC-printer")
11/7/2002
RMI Example
RMI
Registry
JVM
lookup
("DCC-printer")
Alexander V. Konstantinou
15
public LinkedList() {
head = null;
tail = null;
}
public ListNode getHead() {}
public ListNode getTail() {}
public void insert(Object obj)
public void append
(LinkedList list) {}
public boolean isEmpty() {}
public void print() {}
public ListNode
(Object value,
ListNode next) {}
public Object getValue()
public void setValue
(Object value) {}
public ListNode getNext()
public void setNext
(ListNode next) {}
}
}
11/7/2002
Alexander V. Konstantinou
17
11/7/2002
Alexander V. Konstantinou
18
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
// Constructor
public ListPrinterImpl(String name) throws RemoteException {
super();
}
11/7/2002
Alexander V. Konstantinou
19
11/7/2002
Alexander V. Konstantinou
20
import java.util.Date;
import java.rmi.*;
public class Client {
public static void main(String[] args){
LinkedList a = new LinkedList();
a.insert(new Date());
a.insert("Today is");
try {
ListPrinter lpr = (ListPrinter) Naming.lookup
("//" + ListPrinterImpl.serverHost + ":" +
ListPrinterImpl.serverPort + "/myprinter");
lpr.print(a);
} catch(Exception e) {
System.out.println("Client exception: "+e.getMessage());
}
}
}
11/7/2002
Alexander V. Konstantinou
21
11/7/2002
22
$ javac ListPrinterImpl.java
$ javac Client.java
$ rmic ListPrinterImpl
Alexander V. Konstantinou
remote object,
- ListPrinterImpl_Skel.class : server
$ java Client
11/7/2002
Alexander V. Konstantinou
23
11/7/2002
Alexander V. Konstantinou
24
Remote Activation
Registering a remote object with the RMI registry requires
the object to be continually active
JDK 1.2 introduces the RMI daemon (Remote Activation)
Daemon registers information about remote object
implementations that are created on-demand.
11/7/2002
Performance Issues
Alexander V. Konstantinou
26
Concluding Notes
11/7/2002
Alexander V. Konstantinou
27
11/7/2002
How-to Overview
Define remote interface
Write class implementing
remote interface (and
extending
UnicastRemoteObject)
Use rmic to compile
class stub and proxy
Start RMI registry (with
stub & proxy classes in
classpath)
11/7/2002
28
Alexander V. Konstantinou
Alexander V. Konstantinou
29
11/7/2002
Alexander V. Konstantinou
30