Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
23 views

Java RMI: Stanislav Chachkov Lgl-Epfl

Java RMI enables the programmer to create distributed Java applications where 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 by looking it up in the naming service provided by RMI or by receiving the reference as an argument or return value. RMI uses object serialization to marshal and unmarshal parameters when invoking methods on remote objects across a network.

Uploaded by

aryanswengg
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Java RMI: Stanislav Chachkov Lgl-Epfl

Java RMI enables the programmer to create distributed Java applications where 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 by looking it up in the naming service provided by RMI or by receiving the reference as an argument or return value. RMI uses object serialization to marshal and unmarshal parameters when invoking methods on remote objects across a network.

Uploaded by

aryanswengg
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 17

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

network method invocation

Remote Object Server

Host tata.epfl.ch

Host titi.epfl.ch

NetBank example

Client
Bank Office BankMgr

Account Host ecub.ubs.ch Host serv.ubs.ch

Creating a Remote object


interface

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

RMI f() Runtime true

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

Remote Object Server

Remote ref. to Server tata.epfl.ch

Z Host titi.epfl.ch

Creating Remote object


1. 2. 3. 4. Create an interface Create the implementation Compile Create the Stub

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

Binding (server side)


Binding means: register the object in local Naming service:
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, OReilly

You might also like