Presentation is loading. Please wait.

Presentation is loading. Please wait.

January 26, Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java ™ RMI Overview Ann Wollrath Senior Staff Engineer Sun Microsystems,

Similar presentations


Presentation on theme: "January 26, Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java ™ RMI Overview Ann Wollrath Senior Staff Engineer Sun Microsystems,"— Presentation transcript:

1 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java ™ RMI Overview Ann Wollrath Senior Staff Engineer Sun Microsystems, Inc.

2 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Overview Introduction Architecture Example Conclusion

3 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Introduction

4 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Usual RPC Assumptions Multiple machine instruction sets Multiple implementation languages Multiple object models –or no object model at all Protocol agreement has to be up front –perhaps at compile time

5 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java Changes Those Assumptions Java bytecodes give uniform platform Assume that Java is everywhere Environment safe to import code Language-centric approach

6 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java RMI Enables method invocation between objects in different Java VMs Uses pure Java interfaces –no new interface definition language Allows passing Java objects –preserves data encapsulation –supports polymorphism –dynamically loads classes

7 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Advantages of RMI Capitalizes on the Java object model Minimizes complexity Preserves safety of Java runtime Recognizes distribution differences –partial failure –latency –no global knowledge

8 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Remote Objects are Java Objects Remote objects extend Java object model –Remote interfaces to reference objects –All serializable objects can be parameters and return values -Remote object references -Java core class objects (e.g., Hashtable), AWT Objects (e.g., Button), JavaBeans, user defined objects

9 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Remote Objects are Java Objects (cont’d) –Stub objects have the same remote interfaces as the remote object -casting allowed via standard Java cast operators -instanceof to check type of interface –Exceptions to report communication failure

10 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. RMI Application Models Pure RMI solution –Client/server –Peer-to-peer –Agents Three-tier –RMI --> JDBC --> database Connect to legacy systems (via JNI) –RMI --> Java wrapper --> existing system

11 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Distributed Object Applications Typically, these applications need to: –Locate remote objects –Communicate with remote objects –Load class bytecodes for objects that are passed in remote method calls

12 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Locating Remote Objects client server registry RMI

13 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Remote Communication client server registry RMI

14 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Loading Classes client server web server registry URL protocol RMI URL protocol RMI

15 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Architecture

16 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java RMI API java.rmi – client API, naming, exceptions java.rmi.registry –registry interface, factory, lookup java.rmi.server – remote object implementation classes java.rmi.activation –supports activatable remote objects

17 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Components of RMI System RMI runtime –remote references –protocol –transport –class loading and DGC rmiregistry : the remote object registry rmid : the RMI activation daemon rmic : the RMI stub compiler

18 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. RMI Architecture

19 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Method Invocation reference RMI runtime stub caller’s VM remote object’s VM remote object dispatcher

20 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Parameter Passing RMI passes objects using Java Object Serialization –Read/write objects and graphs of objects –Objects must agree to be serializable –Preserves cycles (identity of objects within graph) –Customization on a per-class basis

21 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Class Loading RMI loads classes if not available locally: –Remote stub, parameter, and return value classes –Call stream is annotated with URL for class location –Loaded classes subject to installed security manager

22 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Example

23 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Developing Applications –Define the interfaces to your remote objects –Implement the remote objects and clients –Run rmic on remote implementation classes –Make code network-accessible

24 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Compute Engine Service Remote object to compute arbitrary tasks –Client sends task to compute engine –Compute engine runs task and returns result –RMI loads task code dynamically client Compute engine Compute engine submit task return result

25 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Compute Remote Interface import java.rmi.*; public interface Compute extends Remote { Object executeTask(Task t) throws RemoteException; }

26 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Task Interface import java.io.Serializable; public interface Task extends Serializable { Object execute(); }

27 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Implementation Overview For a peer-to-peer remote object: –Extend UnicastRemoteObject class –Implement methods of remote interface –Create and install a security manager –Create remote object –Register remote object in RMI registry (or other name facility)

28 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Compute Engine Implementation import java.rmi.*; import java.rmi.server.*; public class ComputeEngine extends UnicastRemoteObject implements Compute { public ComputeEngine() throws RemoteException { super(); } public Object executeTask(Task t) { return t.execute(); }

29 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. The main Method public static void main(String[] args) { if (System.getSecurityManager() == null) { System.setSecurityManager( new RMISecurityManager()); } try { Compute engine = new ComputeEngine(); Naming.rebind(“Compute”, engine); System.out.println(“Engine bound”); } catch (Exception e) { System.err.println(“exception: ” + e.getMessage()); e.printStackTrace(); } }

30 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Client Overview Create task to be executed Lookup the compute service by name Send task to compute service Print result

31 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Client’s main Method if (System.getSecurityManager() == null) { System.setSecurityManager( new RMISecurityManager()); } try { String name = “//” + args[0] + “/Compute”; Compute comp = (Compute) Naming.lookup(name); Pi task = new Pi(Integer.parseInt(args[1])); BigDecimal pi = (BigDecimal) comp.executeTask(task)); System.out.println(pi); } catch (Exception e) { System.err.println(“exception: ” + e.getMessage()); e.printStackTrace(); }

32 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved.  Task public class Pi implements Task { private int digits; public Pi(int digits) { this.digits = digits; } public Object execute () { return computePi(digits); } public static BigDecimal computePi( int digits) { // exercise left to reader... } }

33 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Compute Engine: remote communication ComputePi server registry Naming.rebindNaming.lookup comp.executeTask

34 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Compute Engine: class loading ComputePi server registry Naming.rebindNaming.lookup comp.executeTask web server ComputeEngine_Stub Pi ComputeEngine_Stub Compute Task

35 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Conclusion

36 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Future Directions Custom remote reference types Secure reference type Dynamically generated stub classes More performance improvements

37 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. More Information Java RMI home page: –http://java.sun.com/products/jdk/rmi/ Compute engine tutorial: –http://java.sun.com/tutorial/rmi/

38 January 26, 1999--Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved.


Download ppt "January 26, Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java ™ RMI Overview Ann Wollrath Senior Staff Engineer Sun Microsystems,"

Similar presentations


Ads by Google