Professional Documents
Culture Documents
Java RMI: Stanislav Chachkov Lgl-Epfl
Java RMI: Stanislav Chachkov Lgl-Epfl
Java RMI: Stanislav Chachkov Lgl-Epfl
Stanislav Chachkov
LGL-EPFL
What is RMI?
RMI enables the programmer to create distributed Java
applications, in which the methods of remote Java objects can be
invoked from other Java virtual machines, possibly on different
hosts.
A Java program can make a call on a remote object once it obtains
a reference to the remote object, either by looking up the remote
object in the naming service provided by RMI or by receiving the
reference as an argument or a return value. A client can call a
remote object in a server, and that server can also be a client of
other remote objects.
RMI uses object serialization to marshal and unmarshal parameters.
What is RMI?
• Remote Method Invocation
Object network
network Remote
Client method invocation Object
Server
Client
Bank
Office BankMgr
Account
interface java.rmi.server.
java.rmi.Remote UnicastRemoteObject
bank.BankMgrImpl
interface
bank.BankMgr
createClient()
createAccount(Client) bank.BankMgrImpl_Stub
…
Remote Reference
• Encapsulates network communication
• Same interface as Remote object
Object Remote
Client Object Remote
f() 01101 RMI f() Object
Stub Runtime
true 10010 true
Naming
Object “X” Remote
Client lookup(“Y”) Object
“Y” Server
Remote ref. “Z”
to Server
tata.epfl.ch Host titi.epfl.ch
Creating Remote object
1. Create an interface
2. Create the implementation
3. Compile
4. Create the Stub
Interface
public interface BankMgr extends Remote{
public createAccount(Client c)
throws RemoteException;
public BankMgrImpl()
throws RemoteException{super();}
Naming.rebind(
“LGLBank”,
new BankMgrImpl());
Locating (client side)
• Lookup operation return the reference
(stub) on a remote object:
BankMgr bank =
(BankMgr)Naming.lookup(
“//titi.epfl.ch/LGLBank”);
Parameters and Return Values
• Remote objects – by reference
• Serializable objects - by copy
• Others – cannot be passed (exception)
Deployment
• On the server host:
1. Launch Naming service
rmiregistry
2. Launch Server program
java bank.BankMgr
• On the client host(s):
1. Launch the client program
References
• Java Tutorial on RMI:
http://java.sun.com/j2se/1.4/docs/guide/rmi
Book on RMI:
William Grosso “Java RMI”, O’Reilly