Introduction to Remote Method Invocation (RMI)

Share Embed Donate


Short Description

Presenter(s): Chris Matthews Date: Jan 9, 2002 Location: Chattanooga Java Users Group Site: www.cjug.net LinkedIn: w...

Description

Introduction to Remote Method Invocation (RMI) G Christopher Matthews

 Notices • The The fol follo lowi wing ng term termss are are copy copyri righ ghts ts or  trademarks in US and/or other countries. - Java - Sun Microsystems

Introduction to Java RMI • What is Java RMI ? • Features of Java RMI ? • Who would use Java RMI ? • How do I use Java RMI ? • Additional Re Resources . • Questions ?

What is Java RMI ? • Java Java Remo Remote te Meth Method od Invo Invoca cati tion on (RMI (RMI)) is is a distributive system programming interface introduced in JDK 1.1

Features of Java RMI • Obje Object ct Par Param amet eter er Pas Passi sing ng via via Ser Seria iali liza zati tion on • Built in in Se Security Mo Model • Plat Platfo form rm Inde Indepe pend nden ence ce (W (Wri rite te Once Once Run Run Anywhere 100% Pure Java) • Cli Client ent/Ser /Serve verr arch archiitect tectur uree • Supp Suppor ortt inc inclu lude ded d in in JDK JDK with with no exte extern rnal al dependencies • Tran Transp spor ortt lay layer er is TCP/ TCP/IP IP base based d

Features of Java RMI (continued) • Dist Distri ribu buti tive ve Gar Garba bage ge Col Colllect ector  • Lega Legacy cy conn connec ecti tion on can can be be sup suppo port rted ed via via Corba IIOP, Java Native Interface (JNI), JDBC, J2EE Services like (JNDI, JMS) or  JDO.

Who Would Use Java RMI ? • Anyo Anyone ne want wantin ing g to to use use the the ben benef efit itss of of Jav Javaa to do distributive computing development on the network   – Develo Developers pers wanting wanting to to externa externaliz lizee their their local local classes to network computing environment  – Develop Developers ers writi writing ng distri distributi butive ve computi computing ng applications or parallel processing applications  – Server Server develo developers pers wanting wanting bett better er intera interacti ctivity vity clients and/or other servers, like EJBs.

How Do I Use Java RMI ? • The Jav Java RMI arc archit hitecture • Components of Java RMI • Java Java Inte Interf rfac aces es and and how how they they rela relate te to RMI RMI • RMI and Ja Java Se Serialization • Buil Buildi ding ng an RMI RMI Sam Sampl plee Cli Clien ent/ t/Se Serv rver  er  Application • Dist Distri ribu buti tive ve gar garba bage ge col colle lect ctio ion n

Architecture Overview

RMI Layers • Stubs/Skele eleton In Interfac face • Remo Remote te Refe Refere renc ncee Lay Layer (RRL (RRL)) • Java Java Rem Remote ote Met Metho hod d Pro Proto toco coll (JR (JRMP MP)) • Transpo sport La Layer (T (TCP/IP)

Java Interfaces • Inte Interf rfac aces es are are nat nativ ivee to to the the Java Java Lang Langua uage ge • Inte Interf rfac aces es allo allow w exte extern rnal aliz izat atio ion n of meth method odss without exposing the code • Java Java RMI RMI uti utili lize zess int inter erfa face cess for for expo exposi sing ng distributed methods to clients

Serialization of Objects • Seri Serial aliz izat atio ion n is is part part of the the Jav Javaa Lan Langu guag agee • RMI RMI use usess the the powe powerr of of ser seria iali liza zati tion on pass pass objects by value. It “flattens” the object into a byte stream to transmit between the client/server. • Loca Locall obje object ctss pass passed ed as para parame mete ters rs or  returned from methods are done by copy and not by reference.

Serialization of Objects (continued) • Remo Remote te obje object ctss are are pass passed ed by refe refere renc ncee and and the remote reference layer manages the liveliness of the objects

Create a RMI Application • How How do I buil build d an an appl appliicat cation ion ?

Relationship of Layers

Interface Definitions • Defi Defini ning ng the the rem remote ote inte interf rfac acee • Mana Managi ging ng exce except ptio ions ns on the the inte interf rfac acee • See LoanCalc.java for interface definitions.

Interface Implementation • Addi Adding ng the the imp imple leme ment ntat atio ion n code code to to supp suppor ortt the remote interface • Extend the UnicastRemoteObject class • Man Managi aging rem remot otee ex excepti ptions • See LoanCalcImpl.java for interface implementation

Stubs & Skeleton Generation • Use the rmic compiler to compile and generate the stubs & skeletons form LoanCalcImpl.java • See LoanCalcImpl_Stub.class and  LoanCalcImpl_Skel.class as generated files • Use the –keepgenerated flag on the rmic compiler  to generate the .java files LoanCalcImpl_Stub.java and LoanCalcImpl_Skel.java

Creating the Server  • Extending th the RMI RMI Inte nterf rfaace • Regi Regist ster erin ing g a secu securi rity ty mana manage gerr ffor or the the server  • Crea Creati ting ng an inst instan ance ce of the the RMI RMI regi regist stry ry • Bind Bindin ing g a name name to a rem remot otee obj objec ectt for  for  registry lookup by the client. • See CalcServer.java for more details.

Creating The Client • Regi Regissteri tering ng a Secur ecurit ity y Mana Manage ger  r   – Applicati Applications ons require require registrati registration on of of a security security manager  manager   – Applets Applets have build build in security security registrati registration on via the  browser or applet viewer.

• Name lo looku okup of of re remote ob object • Exec Execut utee rou routi tine ness on on the the remo remote te serv server er usin using g defined externalized interfaces • See CalcClient.java for the client code

Building the RMI Sample • Comp Compil ilee inte interf rfac acee impl implem emen enta tati tion on cla class ss  –  javac LoanCalcImpl.java

• Crea Create te stub stubs/ s/sk skel elet eton onss usi using ng the the implementation class  –  rmic LoanCalcImpl.java

• Comp Compil ilee cli clien entt and and serv server er clas classe sess  –  javac CalcClient.java  –  javac CalcServer.java

Starting the RMI Sample • Starting the registry • Starting the server  • Starting th the cl client

RMI Registry • RMI RMI Reg Regis istr try y prov provid ides es name name look lookup up for  for  clients to resolve the server’s remote objects • Two Two way wayss to to sta start rt the RMI RMI Reg Regis istr try y – Command Lin Linee • rmiregistry (optional port:Default is 1099)

 – Dynami Dynamical cally ly with with stati staticc method method • LocateRegistry.createRegistry( port )

Starting the Server  • Starts th the RM RMI Se Server   –  java CalcServer 

Starting the Client • Star Startt the the clie client nt,, pass passin ing g it it the the URL URL nam namee of  of  the server along with the remote object to reference  –  java CalcClient //www.server.com/objectname //www.server.com/objectname

Distributive Garbage Collector  • RMI RMI run runti time me garb garbag agee col colle lect ctor or mana manage gess liveliness of the remote object. When the object becomes “out of scope” the server’s distributive garbage collector flags the object.

RMI Conclusion • It is simp simple le to deve develo lop p dis distr trib ibut utiv ivee computing applications • RMI RMI is is des desig igne ned d to to be be a nat natur ural al inte interf rfac acee for  for  writing distributive computing applications in Java using existing features of the language • It is a cro cross ss plat platfo form rm solu soluti tion on for  for  distributive computing development

Advanced Topics on RMI • Exte Extern rnal aliz izat atio ion n of Obj Objec ects ts wit witho hout ut a reg regis istr try y • Closed vs vs. Op Open RM RMI sy systems • Security in RMI • Dist Distri ribu buti tive ve Garb Garbag agee Col Colle lect ctor or in Deta Detail il • RMI Transaction Log • II IIOP OP ins instead tead of JRMP RMP for for RMI RMI Pro Proto toco coll • Persistent References • Other RMI Enhancements

Additional References • RMI – Javasoft  –  http://www.javasoft.com

• Orielly - Java Ne Network Pr Programming,  – ISB ISBN 1-56 1-5659 5922-22 2277-1 1

• RMI/IIOP JavaWorld  –  http://www.javaworld.com

• IIOP – Object Ma Management Gr Group (O (OMG) CORBA  – http http:/ ://w /www ww.o .omg mg.o .org rg

Questions ?

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF