Presentation is loading. Please wait.

Presentation is loading. Please wait.

Presentation 11: RMI introduction. Ingeniørhøjskolen i Århus Slide 2 af 20 Goals of this lesson After these 2x35 lessons you will be –Introduced to Java.

Similar presentations


Presentation on theme: "Presentation 11: RMI introduction. Ingeniørhøjskolen i Århus Slide 2 af 20 Goals of this lesson After these 2x35 lessons you will be –Introduced to Java."— Presentation transcript:

1 Presentation 11: RMI introduction

2 Ingeniørhøjskolen i Århus Slide 2 af 20 Goals of this lesson After these 2x35 lessons you will be –Introduced to Java RMI Ready for trying out a simpel ”Hello World” excersice in the LAB –Ready to present RMI’s position in the Middleware technology family on class YOU WILL NOT –Be an RMI expert Later in RMI: –We will look at more advanced issues –Activation, Call-back, RMI on IIOP

3 Ingeniørhøjskolen i Århus Slide 3 af 20 Outline Theory: (35 min.) –Introduction to Java RMI Group work: (15 min.) –Pro’s & con’s of Java RMI vs. SOAP When to use which technology… –Differences and equalities with SOAP & RMI Plenum: (15 min.) –Discussion of group work –Next time: one group will present … so prepare!

4 Ingeniørhøjskolen i Århus Slide 4 af 20 Java RMI In Java 1.0 object communication was confined to objects in one Virtual Machine (VM) Remote Method Invocation (RMI) from Java 1.1 supports communication between different VMs, potentially across the network Provides tight OO integration with Java Work in heterogeneous environment (servers) BUT ONLY with Java (so far) – so no language transparency

5 Ingeniørhøjskolen i Århus Slide 5 af 20 Java RMI features Build on Java’s existing object model -> easy No need for IDL – use Java interfaces Arguments & return values can be all types specializing java.io.Serilizable or java.rmi.Remote Dynamic loading of classes Use of build in Java Security Manager Distributed Garbage Collection Integrates with CORBA (later) BUT NOT IN J2ME!!! (use SOAP)

6 Ingeniørhøjskolen i Århus Slide 6 af 20 Java RMI position Middleware Transaction-Oriented –IBM CICS –BEA Tuxedo –Encina Message-Oriented –IBM MQSeries –DEC Message Queue –NCR TopEnd –(SOAP) RPC Systems –ANSA –Sun ONC –OSF/DCE –(SOAP) Object-Oriented –OMG/CORBA –DCOM –Java/RMI –(SOAP)

7 Ingeniørhøjskolen i Århus Slide 7 af 20 Local Java call vs. Java RMI callCalledCalled Stub CallerCalledCalledCaller Caller Transport Layer (e.g. TCP or UDP) Similar to SOAP and CORBA – using Proxy

8 Ingeniørhøjskolen i Århus Slide 8 af 20 Interface Definition Design Server Stub Generation Client Stub Generation Server Coding Client Coding Server Registration Development Steps – RMI vs SOAP SOAP: WSDL Java2WSDL WSDL2JAVA AXIS SOAP RMI: rmic RMI: JAVA J2SE JDK Start with Server Interface Coding: JAVA Start with Server Interface Coding: JAVA rmiregistry 1 1 2 2 4 4 3 3 5 5

9 Ingeniørhøjskolen i Århus Slide 9 af 20 Team.wsdl included in generates reads WSDL-compiler Teamcl.hh Teamcl.cc Teamsv.cc Teamsv.hh Stub Generation in SOAP

10 Ingeniørhøjskolen i Århus Slide 10 af 20 Team.idl included in generates reads IDL-Compiler Teamcl.hh Teamcl.cc Teamsv.cc Teamsv.hh Stub Generation in CORBA

11 Ingeniørhøjskolen i Århus Slide 11 af 20 package examples.hello; import java.rmi.Remote; import java.rmi.RemoteException; public interface Hello extends Remote { String sayHello() throws RemoteException; void someOther(String param) throws RemoteException; } rmic Compiler HelloImpl_Stub.class HelloImpl_Skeleton.class Stub Generation in Java RMI NOTE: In fact, it is the HelloImpl that is used! NOTE: In fact, it is the HelloImpl that is used! Hello.java Must Extend from Interface Remote Must Extend from Interface Remote From RMI v. 1.2 no skeleton is generated From RMI v. 1.2 no skeleton is generated

12 Ingeniørhøjskolen i Århus Slide 12 af 20 C++ Compiler, Linker Server Client.cc Server.cc C++ Compiler, Linker Client Team.idl included in generates reads IDL-Compiler Teamcl.hh Teamcl.cc Teamsv.cc Teamsv.hh CORBA Client and Server Implementation

13 Ingeniørhøjskolen i Århus Slide 13 af 20 Java compiler - javac Server HelloClient.java HelloImpl.java Java compiler - javac Client Hello.java included in generates reads rmic Compiler RMI Client and Server Implementation HelloImpl_Stub.class HelloImpl_Skeleton.class

14 Ingeniørhøjskolen i Århus Slide 14 af 20 package examples.hello; import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.RMISecurityManager; import java.rmi.server.UnicastRemoteObject; public class HelloImpl extends UnicastRemoteObject implements Hello { public HelloImpl() throws RemoteException { super(); } public String sayHello() { return "Hello World! ; } public static void main(String args[]) { // Create and install a security manager //if (System.getSecurityManager() == null) { // System.setSecurityManager(new RMISecurityManager()); //} try { HelloImpl obj = new HelloImpl(); // Bind this object instance to the name "HelloServer" Naming.rebind("rmi://192.168.1.101/HelloServer", obj); System.out.println("HelloServer bound in registry"); } catch (Exception e) { System.out.println("HelloImpl err: " + e.getMessage()); e.printStackTrace(); } Server object (HelloImpl.java) Security manager needs a security policy – for access control (i.e. file system). Security manager needs a security policy – for access control (i.e. file system). Instantiate a new object and register (bind it) in the ”rmiregistry” Instantiate a new object and register (bind it) in the ”rmiregistry” Implement all methods from interface Hello.java Implement all methods from interface Hello.java Extend UnicastRemote and implemet Hello Interfacet Extend UnicastRemote and implemet Hello Interfacet ”rmiregistry” is a simpel name server with methods to bind objects (bind/rebind) – and Find them again (lookup) –> client ”rmiregistry” is a simpel name server with methods to bind objects (bind/rebind) – and Find them again (lookup) –> client

15 Ingeniørhøjskolen i Århus Slide 15 af 20 package examples.hello; import java.rmi.Naming; import java.rmi.RemoteException; public class HelloClient { public static void main(String args[]) { try { obj = (Hello)Naming.lookup("rmi://192.168.1.101/HelloServer"); String message = obj.sayHello(); System.out.println(message); } catch (Exception e) { System.out.println("HelloApplet exception: " + e.getMessage()); e.printStackTrace(); } ”lookup” the HelloServer – and call Method sayHello() on Stub ”lookup” the HelloServer – and call Method sayHello() on Stub Client object (HelloClient.java) Remember – that the stub and skeleton classes get generated by the ”rmic” compiler Remember – that the stub and skeleton classes get generated by the ”rmic” compiler AND THAT’S IT!

16 Ingeniørhøjskolen i Århus Slide 16 af 20 Architecture ServerClient Stub Registry Interfaces Skeleton Activation Interfaces RMI Runtime (rmid,rmiregistry) coded manually rmic generated bind lookup

17 Ingeniørhøjskolen i Århus Slide 17 af 20 Things to remember No attributes in Java Interfaces (as opposed to CORBA IDL) -> RMI does not support attributes Attributes must be represented as set and get operations by the designer

18 Ingeniørhøjskolen i Århus Slide 18 af 20 Things to remember II Parameter passing different than normal Java in single VM Atomic types are passed by value Remote objects are passed by reference Non-Remote objects are passed by value! And of course – if an object is not on the client – the ByteCode gets transferred (the class incl. implementation)

19 Ingeniørhøjskolen i Århus Slide 19 af 20 Key Points True and beautiful OO Middleware Easy to learn – for Java developers No need for a separate IDL (use Java Interfaces) Distributed Garbage Collection ByteCode transfers automatically Works in heterogene environment – but only with Java No build in services (except for the registry) Depends on other API’s – JavaSpaces, JINI, JDBC, EJB, JDO etc. – integrated into a framework (ROAD JAVA from MÆRSK DATA)

20 Ingeniørhøjskolen i Århus Slide 20 af 20 Introduction complete – now Group Work Group work: (15 min.) –Pro’s & con’s of Java RMI vs. SOAP When to use which technology… –Differences and equalities with SOAP Reflection in plenum: (15 min.) –Discussion of group work –Next time: one random group will present … so prepare! Presentation next time –Use book and articles as source of knowledge –Use figures from teachers former presentations


Download ppt "Presentation 11: RMI introduction. Ingeniørhøjskolen i Århus Slide 2 af 20 Goals of this lesson After these 2x35 lessons you will be –Introduced to Java."

Similar presentations


Ads by Google