Vous êtes sur la page 1sur 3

The Java Remote Method Invocation (Java RMI) is a Java API that performs the object-

oriented equivalent of remote procedure calls (RP)! "ith support for direct transfer of
seriali#ed Java classes and distributed $arba$e collection%
The ori$inal implementation depends on Java &irtual Machine (J&M) class
representation mechanisms and it thus onl' supports ma(in$ calls from one J&M to
another% The protocol underl'in$ this Java-onl' implementation is (no"n as Java
Remote Method Protocol (JRMP)%
In order to support code runnin$ in a non-J&M conte)t! a *R+A version "as later
developed%
,sa$e of the term RMI ma' denote solel' the pro$rammin$ interface or ma' si$nif' both
the API and JRMP! "hereas the term RMI-II*P (read- RMI over II*P) denotes the RMI
interface dele$atin$ most of the functionalit' to the supportin$ *R+A
implementation%.enerali#ed code/edit0
The pro$rammers of the ori$inal RMI API $enerali#ed the code some"hat to support
different implementations! such as a 1TTP transport% Additionall'! the abilit' to pass
ar$uments 2b' value2 "as added to *R+A in order to be compatible "ith the RMI
interface% 3till! the RMI-II*P and JRMP implementations do not have full' identical
interfaces%
RMI functionalit' comes in the pac(a$e java%rmi! "hile most of 3un4s implementation is
located in the sun%rmi pac(a$e% 5ote that "ith Java versions before Java 6%7 developers
had to compile RMI stubs in a separate compilation step usin$ rmic% &ersion 6%7 of Java
and be'ond no lon$er require this step%
Jini version/edit0
Jini offers a more advanced version of RMI in Java% It functions similarl' but provides
more advanced searchin$ capabilities and mechanisms for distributed object
applications%/80import java%rmi%5amin$9
import java%rmi%Remote:)ception9
import java%rmi%server%,nicastRemote*bject9
import java%rmi%re$istr'%;9
public class Rmi3erver
e)tends ,nicastRemote*bject
implements Rmi3erverIntf <
public static final 3trin$ M:33A.: = 21ello >orld29

public Rmi3erver() thro"s Remote:)ception <
super(7)9 ?? required to avoid the 4rmic4 step! see belo"
@

public 3trin$ $etMessa$e() <
return M:33A.:9
@

public static void main(3trin$ ar$s/0) thro"s :)ception <
3'stem%out%println(2RMI server started2)9

tr' < ??special e)ception handler for re$istr' creation
AocateRe$istr'%createRe$istr'(87BB)9
3'stem%out%println(2java RMI re$istr' created%2)9
@ catch (Remote:)ception e) <
??do nothin$! error means re$istr' alread' e)ists
3'stem%out%println(2java RMI re$istr' alread' e)ists%2)9
@

??Instantiate Rmi3erver
Rmi3erver obj = ne" Rmi3erver()9

?? +ind this object instance to the name 2Rmi3erver2
5amin$%rebind(2??localhost?Rmi3erver2! obj)9
3'stem%out%println(2Peer3erver bound in re$istr'2)9
@
@
Rmi3erverIntf interface C defines the interface that is used b' the client and
implemented b' the server%
import java%rmi%Remote9
import java%rmi%Remote:)ception9

public interface Rmi3erverIntf e)tends Remote <
public 3trin$ $etMessa$e() thro"s Remote:)ception9
@

Vous aimerez peut-être aussi