introduction to remote method invocation (rmi)

30
Introduction to Remote Method Invocation (RMI) G Christopher Matthews

Upload: chattanooga-java-users-group

Post on 13-Nov-2014

1.483 views

Category:

Documents


2 download

DESCRIPTION

Presenter(s): Chris MatthewsDate: Jan 9, 2002Location: Chattanooga Java Users Group Site: www.cjug.netLinkedIn: www.linkedin.com/groups?gid=1167347Presentation------------Session Outline:- Overview of RMI- Features of RMI- Layers in RMI- Creating an application- Conclusion Biography---------Chris is President of eLink Business Innovations, Inc a software and services company focusing on security, payment, and R&D solutions for customers and venture capitalist community. http://www.elink.bzPrior to founding eLink, Chris was an Associate VP for Citigroup where he was responsible as Chief Architect of Electronic Bill Presentment and Payment (EBPP) Division and Senior Architect for Citibank's North American Credit Cards Division. His career spans leading companies like Checkfree Corporation and IBM Corporation where he worked almost ten years designing and developing next generation operating systems. Some additional projects include MPEG4 advanced compression, EBPP, Workplace OS, OS/2 Warp, JavaOS for Business, International Payment Processors, and many others. Chris is also the president of Chattanooga Technology Council and Chattanooga Java Users Group

TRANSCRIPT

Page 1: Introduction to Remote Method Invocation (RMI)

Introduction to Remote Method Invocation (RMI)

G Christopher Matthews

Page 2: Introduction to Remote Method Invocation (RMI)

Notices

• The following terms are copyrights or trademarks in US and/or other countries.- Java- Sun Microsystems

Page 3: Introduction to Remote Method Invocation (RMI)

Introduction to Java RMI

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

Page 4: Introduction to Remote Method Invocation (RMI)

What is Java RMI ?

• Java Remote Method Invocation (RMI) is a distributive system programming interface introduced in JDK 1.1

Page 5: Introduction to Remote Method Invocation (RMI)

Features of Java RMI

• Object Parameter Passing via Serialization• Built in Security Model• Platform Independence (Write Once Run

Anywhere 100% Pure Java)• Client/Server architecture• Support included in JDK with no external

dependencies• Transport layer is TCP/IP based

Page 6: Introduction to Remote Method Invocation (RMI)

Features of Java RMI (continued)

• Distributive Garbage Collector• Legacy connection can be supported via

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

Page 7: Introduction to Remote Method Invocation (RMI)

Who Would Use Java RMI ?

• Anyone wanting to use the benefits of Java to do distributive computing development on the network– Developers wanting to externalize their local

classes to network computing environment– Developers writing distributive computing

applications or parallel processing applications– Server developers wanting better interactivity

clients and/or other servers, like EJBs.

Page 8: Introduction to Remote Method Invocation (RMI)

How Do I Use Java RMI ?

• The Java RMI architecture• Components of Java RMI• Java Interfaces and how they relate to RMI• RMI and Java Serialization• Building an RMI Sample Client/Server

Application• Distributive garbage collection

Page 9: Introduction to Remote Method Invocation (RMI)

Architecture Overview

Page 10: Introduction to Remote Method Invocation (RMI)

RMI Layers

• Stubs/Skeleton Interface• Remote Reference Layer (RRL)• Java Remote Method Protocol (JRMP)• Transport Layer (TCP/IP)

Page 11: Introduction to Remote Method Invocation (RMI)

Java Interfaces

• Interfaces are native to the Java Language• Interfaces allow externalization of methods

without exposing the code• Java RMI utilizes interfaces for exposing

distributed methods to clients

Page 12: Introduction to Remote Method Invocation (RMI)

Serialization of Objects

• Serialization is part of the Java Language• RMI uses the power of serialization pass

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

• Local objects passed as parameters or returned from methods are done by copy and not by reference.

Page 13: Introduction to Remote Method Invocation (RMI)

Serialization of Objects (continued)

• Remote objects are passed by reference and the remote reference layer manages the liveliness of the objects

Page 14: Introduction to Remote Method Invocation (RMI)

Create a RMI Application

• How do I build an application ?

Page 15: Introduction to Remote Method Invocation (RMI)

Relationship of Layers

Page 16: Introduction to Remote Method Invocation (RMI)

Interface Definitions

• Defining the remote interface• Managing exceptions on the interface• See LoanCalc.java for interface definitions.

Page 17: Introduction to Remote Method Invocation (RMI)

Interface Implementation

• Adding the implementation code to support the remote interface

• Extend the UnicastRemoteObject class• Managing remote exceptions• See LoanCalcImpl.java for interface

implementation

Page 18: Introduction to Remote Method Invocation (RMI)

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.javaand LoanCalcImpl_Skel.java

Page 19: Introduction to Remote Method Invocation (RMI)

Creating the Server

• Extending the RMI Interface• Registering a security manager for the

server• Creating an instance of the RMI registry• Binding a name to a remote object for

registry lookup by the client.• See CalcServer.java for more details.

Page 20: Introduction to Remote Method Invocation (RMI)

Creating The Client

• Registering a Security Manager– Applications require registration of a security manager– Applets have build in security registration via the

browser or applet viewer.

• Name lookup of remote object• Execute routines on the remote server using

defined externalized interfaces• See CalcClient.java for the client code

Page 21: Introduction to Remote Method Invocation (RMI)

Building the RMI Sample

• Compile interface implementation class– javac LoanCalcImpl.java

• Create stubs/skeletons using the implementation class– rmic LoanCalcImpl.java

• Compile client and server classes– javac CalcClient.java– javac CalcServer.java

Page 22: Introduction to Remote Method Invocation (RMI)

Starting the RMI Sample

• Starting the registry• Starting the server• Starting the client

Page 23: Introduction to Remote Method Invocation (RMI)

RMI Registry

• RMI Registry provides name lookup for clients to resolve the server’s remote objects

• Two ways to start the RMI Registry– Command Line

• rmiregistry (optional port:Default is 1099) – Dynamically with static method

• LocateRegistry.createRegistry( port )

Page 24: Introduction to Remote Method Invocation (RMI)

Starting the Server

• Starts the RMI Server– java CalcServer

Page 25: Introduction to Remote Method Invocation (RMI)

Starting the Client

• Start the client, passing it the URL name of the server along with the remote object to reference– java CalcClient //www.server.com/objectname

Page 26: Introduction to Remote Method Invocation (RMI)

Distributive Garbage Collector

• RMI runtime garbage collector manages liveliness of the remote object. When the object becomes “out of scope” the server’s distributive garbage collector flags the object.

Page 27: Introduction to Remote Method Invocation (RMI)

RMI Conclusion

• It is simple to develop distributive computing applications

• RMI is designed to be a natural interface for writing distributive computing applications in Java using existing features of the language

• It is a cross platform solution for distributive computing development

Page 28: Introduction to Remote Method Invocation (RMI)

Advanced Topics on RMI

• Externalization of Objects without a registry• Closed vs. Open RMI systems• Security in RMI• Distributive Garbage Collector in Detail• RMI Transaction Log• IIOP instead of JRMP for RMI Protocol• Persistent References• Other RMI Enhancements

Page 29: Introduction to Remote Method Invocation (RMI)

Additional References

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

• Orielly - Java Network Programming,– ISBN 1-56592-227-1

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

• IIOP – Object Management Group (OMG) CORBA– http://www.omg.org

Page 30: Introduction to Remote Method Invocation (RMI)

Questions ?