• No results found

Introduction to Remote Method Invocation (RMI)

N/A
N/A
Protected

Academic year: 2021

Share "Introduction to Remote Method Invocation (RMI)"

Copied!
30
0
0

Loading.... (view fulltext now)

Full text

(1)

Introduction to Remote Method

Introduction to Remote Method

Invocation (RMI)

Invocation (RMI)

G Christopher Matthews G Christopher Matthews

(2)

 Notices

 Notices

•• ThThe fe folollolowiwing ng tetermrms as are re cocopypyririghghts ts or or  trademarks in US and/or other countries. trademarks in US and/or other countries.

-- JJaavvaa

(3)

Introduction to Java RMI

Introduction to Java RMI

•• WWhhaat t iis s JJaavva a RRMMI I ??

•• FFeeaattuurrees s oof f JJaavva a RRMMI I ??

•• WWhho o wwoouulld d uusse e JJaavva a RRMMI I ?? •• HHoow w ddo o I I uusse e JJaavva a RRMMI I ?? •• AAddddiittiioonnaal Rl Reessoouurrccees .s .

(4)

What is Java RMI ?

What is Java RMI ?

•• JaJava va ReRemomote te MeMeththod od InInvovocacatition on (R(RMIMI) i) is as a distributive system programming interface distributive system programming interface introduced in JDK 1.1

(5)

Features of Java RMI

Features of Java RMI

•• ObObjeject Pct Pararamameteter Per Pasassising vng via Sia Sereriaialilizazatitionon •• BBuuiillt it in Sn Seeccuurriitty My Mooddeell

•• PlPlatatfoform rm InIndedepependndenence ce (W(Wririte te OnOnce ce RuRunn Anywhere 100% Pure Java)

Anywhere 100% Pure Java) •• ClCliienentt/S/Serervever r ararchchiitetectctururee

•• SuSupppporort it incncluludeded id in Jn JDK DK wiwith th no no exexteternrnalal dependencies

dependencies

(6)

Features of Java RMI

Features of Java RMI

(continued)(continued)

•• DiDiststriribubutitive Gve Gararbabage Cge Cololllececttor or 

•• LeLegagacy cy coconnnnecectition on cacan bn be se supuppoportrted ed viviaa Corba

Corba IIOP, IIOP, Java Java Native Native Interface Interface (JNI),(JNI), JDBC, J2EE Services like (JNDI, JMS) or  JDBC, J2EE Services like (JNDI, JMS) or  JDO.

(7)

Who Would Use Java RMI ?

Who Would Use Java RMI ?

•• AnAnyoyone ne wawantntining tg to uo use se ththe be benenefefitits os of Jf Javavaa to do distributive computing development to do distributive computing development on the network 

on the network 

 –

 – DevDeveloelopers pers wanwanting tting to exteo externarnalizlize theie their locar locall classes to network computing environment classes to network computing environment  –

 – DevDevelopelopers wers writiriting disng distritributibutive comve computiputingng

applications or parallel processing applications applications or parallel processing applications  –

 – SerServer dever develovelopers pers wanwanting bting bettetter inter interaeractictivityvity clients and/or other servers, like EJBs.

(8)

How Do I Use Java RMI ?

How Do I Use Java RMI ?

•• TThhe e JaJavva a RRMMI I ararcchihitteeccttuurere •• CCoommppoonneenntts s oof f JJaavva a RRMMII

•• JaJava va InInteterfrfacaces es anand hd how ow ththey ey rerelalate te to to RMRMII •• RRMI MI aannd Jd Jaavva Sa Seerriiaalliizzaattiioonn

•• BuBuilildiding ng an an RMRMI SI Samamplple Ce Clilienent/t/SeServrver er  Application

Application

(9)

Architecture Overview

Architecture Overview

(10)

RMI Layers

RMI Layers

•• SSttuubbss//SSkkeleleettoon In Inntteerrfafaccee

•• ReRemomote te ReRefefererencnce e LaLayyer er (R(RRLRL))

•• JaJava va ReRemmotote Me Metethohod Pd Prorototococol (l (JRJRMPMP)) •• TTrraannspspoorrt Lt Laayyeer (r (TTCCPP//IIPP))

(11)

Java Interfaces

Java Interfaces

•• InInteterfrfacaces es arare ne natativive te to to the he JaJava va LaLangnguauagege •• InInteterfrfacaces ales allolow exw exteternrnalalizizatatioion of men of meththododss

without exposing the code without exposing the code

•• JaJava va RMRMI uI utitililizezes is intntererfafaceces fs for or exexpoposisingng distributed methods to clients

(12)

Serialization of Objects

Serialization of Objects

•• SeSeririalalizizatatioion in is pas part rt of tof the Jhe Javava La Lananguguagagee •• RMRMI uI useses ts the he popowewer or of sf sereriaialilizazatition on papassss

objects by value. It “flattens” the object into objects by value. It “flattens” the object into a byte stream to transmit between the

a byte stream to transmit between the client/server.

client/server.

•• LoLocacal l obobjejectcts s papassssed ed as as papararamemeteters rs or or  returned from methods are done by copy returned from methods are done by copy and not by reference.

(13)

Serialization of Objects

Serialization of Objects

(continued)(continued)

•• ReRemomote te obobjejectcts as are re papassssed ed by by rerefefererencnce ae andnd the remote reference layer manages the

the remote reference layer manages the liveliness of the objects

(14)

Create a RMI Application

Create a RMI Application

(15)

Relationship of Layers

(16)

Interface Definitions

Interface Definitions

•• DeDefifinining ng ththe e reremmotote e ininteterfrfacacee

•• MaMananagiging ng exexceceptptioions ns on on ththe e ininteterfrfacacee

(17)

Interface Implementation

Interface Implementation

•• AdAddiding tng the ihe impmplelemementntatatioion con code tde to suo supppporortt the remote interface

the remote interface

•• EExxtteennd d tthhee UnicastRemoteObject classUnicastRemoteObject class •• MaMannagagiinng rg rememotote ee exxcceeptptiioonnss

•• SSeeee LoanCalcImpl.java LoanCalcImpl.java for interfacefor interface implementation

(18)

Stubs & Skeleton Generation

Stubs & Skeleton Generation

•• UUsse e tthhee rmicrmic compiler to compile and generate thecompiler to compile and generate the stubs & skeletons form

stubs & skeletons form LoanCalcImpl.java LoanCalcImpl.java

•• SSeeee LoanCalcImpl_Stub.class LoanCalcImpl_Stub.class andand

 LoanCalcImpl_Skel.class

 LoanCalcImpl_Skel.class as generated filesas generated files

•• UUsse e tthhee –keepgenerated  –keepgenerated flag on theflag on the rmicrmic compiler compiler  to generate the .java files

to generate the .java files LoanCalcImpl_Stub.java LoanCalcImpl_Stub.java

and

(19)

Creating the Server 

Creating the Server 

•• EExxtteennddiinng tg thhe Re RMI MI IIntnteerfrfaaccee

•• ReRegigiststererining a g a sesecucuririty ty mamananageger fr for or ththee server 

server 

•• CrCreaeatiting ng an an ininststanance ce of of ththe Re RMI MI reregigiststryry •• BiBindndining a g a naname me to to a ra rememotote oe objbjecect t fofor r 

registry lookup by the client. registry lookup by the client.

(20)

Creating The Client

Creating The Client

•• ReRegigissteteriring ng a a SSececururitity y MaMananageger r 

 –

 – ApplApplicatiications ons requrequire ire regisregistratitration oon of a f a secusecurity rity manamanager ger   –

 – ApplApplets ets have have builbuild in d in secsecurity urity regisregistratitration on via via thethe  browser or applet viewer.

 browser or applet viewer.

•• NNaamme le loookokuup op of rf reemmootte oe obbjjeecctt

•• ExExececutute re rououtitinenes os on tn the he reremomote te seservrver er ususiningg defined externalized interfaces

defined externalized interfaces

(21)

Building the RMI Sample

Building the RMI Sample

•• CoCompmpilile ine inteterfrfacace ime implplememenentatatition con clalassss

 – 

 – javac LoanCalcImpl.javajavac LoanCalcImpl.java

•• CrCreaeate te ststububs/s/skskeleletetonons us usising ng ththee implementation class

implementation class

 – 

 – rmic LoanCalcImpl.javarmic LoanCalcImpl.java

•• CoCompmpilile ce clilienent at and nd seservrver er clclasassesess

 – 

 – javac CalcClient.javajavac CalcClient.java

 – 

(22)

Starting the RMI Sample

Starting the RMI Sample

•• SSttaarrttiinng g tthhe e rreeggiissttrryy •• SSttaarrttiinng g tthhe e sseerrvveer r  •• SSttaarrttiinng tg thhe ce clliieenntt

(23)

RMI Registry

RMI Registry

•• RMRMI RI Regegisistrtry y prprovovidides es naname me lolookokup up fofor r 

clients to resolve the server’s remote objects clients to resolve the server’s remote objects •• TwTwo wo wayays ts to so statart rt tthe he RMRMI RI Regegisistrtryy

– CCoommmmaannd Ld Lininee

•• rmiregistry (optional port:Default is 1099)rmiregistry (optional port:Default is 1099)  –

 – DynDynamiamicalcally ly witwith sh statitatic c metmethodhod •• LocateRegistry.createRegistry( port )LocateRegistry.createRegistry( port )

(24)

Starting the Server 

Starting the Server 

•• SSttaarrtts ts thhe Re RMMI SI Seerrvveer r 

 – 

(25)

Starting the Client

Starting the Client

•• StStarart tt the he clclieientnt, pa, passssining ig it tt the he URURL nL namame oe of f  the server along with the remote object to the server along with the remote object to reference

reference

 – 

(26)

Distributive Garbage Collector 

Distributive Garbage Collector 

•• RMRMI rI rununtitime me gagarbrbagage ce colollelectctor or mamananagegess liveliness of the remote object. When the liveliness of the remote object. When the object becomes “out of scope” the server’s object becomes “out of scope” the server’s distributive garbage collector flags the

distributive garbage collector flags the object.

(27)

RMI Conclusion

RMI Conclusion

•• It It is is sisimpmple le to to dedevevelolop dp disistrtribibututivivee computing applications

computing applications

•• RMRMI iI is ds desesigignened td to bo be a ne a nataturural al ininteterfrfacace fe for or  writing distributive computing applications writing distributive computing applications in Java using existing features of the

in Java using existing features of the language

language

•• It It iis a cs a croross ss plplatatfoform rm sosolulutition on fofor r 

distributive computing development distributive computing development

(28)

Advanced Topics on RMI

Advanced Topics on RMI

•• ExExteternrnalalizizatatioion of On of Objbjecects wts witithohout a rut a regegisistrtryy •• CClloosseed vd vss. O. Oppeen Rn RMMI sI syysstteemmss

•• SSeeccuurriitty y iin n RRMMII

•• DiDiststriribubutitive ve GaGarbrbagage Ce Colollelectctor or in in DeDetatailil •• RRMMI I TTrraannssaaccttiioon n LLoogg

•• IIIIOP OP ininsstetead ad of of JJRMRMP fP for or RMRMI PI Prorototococoll •• PPeerrssiisstteennt t RReeffeerreenncceess

(29)

Additional References

Additional References

•• RRMMI I –– JJaavvaassoofftt

 – 

 –  http://www.javasoft.comhttp://www.javasoft.com

•• OOrriieelllly -y - JJaavva Na Neettwwoorrk Pk Prrooggrraammmmiinngg,,  –

 – ISISBBN 1-N 1-565659592-2-22227-7-11 •• RRMMII//IIIIOOP P JJaavvaaWWoorrlldd

 – 

 –  http://www.javaworld.comhttp://www.javaworld.com

•• IIIIOOP –P – OObbjjeecct Mt Maannaaggeemmeennt Gt Grroouup (p (OOMMGG)) CORBA

CORBA  –

(30)

Questions ?

References

Related documents