Java RMI: Stanislav Chachkov Lgl-Epfl
Java RMI: 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 Client
Host tata.epfl.ch
Host titi.epfl.ch
NetBank example
Client
Bank Office BankMgr
java.rmi.Remote
java.rmi.server. UnicastRemoteObject
bank.BankMgrImpl
interface
bank.BankMgr
createClient() createAccount(Client)
bank.BankMgrImpl_Stub
Remote Reference
Encapsulates network communication Same interface as Remote object
Object Client Remote Object Stub
f() true
01101
10010
Remote Object
Host tata.epfl.ch
Host titi.epfl.ch
Naming Service
Directory that associates names to remote objects (bind)
Naming X
Y Remote Object A Remote Object B Host titi.epfl.ch Remote Object C
Naming Service
Client use Naming Service to find a particular Server object (lookup)
Object Client
lookup(Y)
Naming X
Y
Z Host titi.epfl.ch
Interface
public interface BankMgr extends Remote{
public createAccount(Client c) throws RemoteException; public createClient(String name) throws RemoteException;
Implementation class
public class BankMgrImpl extends UnicastRemoteObject implements BankMgr{ public BankMgrImpl() throws RemoteException{super();}
public createClient(String a){ code } public createAccount(Client b){ code } }
Stub
A. In JBuilder use JNI/RMI tab in class properties to generate it automatically
B. By hand: use rmic tool: rmic bank.BankMgrImpl
Deployment
On the server host:
1. Launch Naming service
rmiregistry
References
Java Tutorial on RMI:
http://java.sun.com/j2se/1.4/docs/guide/rmi