presentation 18: rmi introduction
DESCRIPTION
Presentation 18: RMI introduction. Goals of this lesson. After this 35 min. lesson and next weeks group-work you will be : Introduced to Java RMI Ready for trying out a simpel ”Hello World” excercise in the LAB if you please - PowerPoint PPT PresentationTRANSCRIPT
Presentation 18:RMI introduction
Ingeniørhøjskolen i ÅrhusSlide 2 af 18
Goals of this lesson
• After this 35 min. lesson and next weeks group-work you will be:– Introduced to Java RMI
• Ready for trying out a simpel ”Hello World” excercise in the LAB if you please
– 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, Callbacks, RMI over IIOP, tunneling
Ingeniørhøjskolen i ÅrhusSlide 3 af 18
Outline
• Theory: (35 min.) – Introduction to Java RMI
• Group work (next week): (35 min.)– Pro’s & con’s of Java RMI vs. SOAP
• When to use which technology…
– Differences and equalities with SOAP & RMI
• Plenum: (next week): (35 min.)– Discussion of group work– One group will present … so prepare!
Ingeniørhøjskolen i ÅrhusSlide 4 af 18
Java RMI
• In Java 1.0 object communication was confined to objects in one Virtual Machine (VM)
• Sun Microsystems thus decided to introduce inter VM communication
• 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
Ingeniørhøjskolen i ÅrhusSlide 5 af 18
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.Serializable 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)
– J2ME CDC has an RMI profile!
Ingeniørhøjskolen i ÅrhusSlide 6 af 18
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)
Ingeniørhøjskolen i ÅrhusSlide 7 af 18
Wire Protocol
• Java RMI wire protocol: – JRMP (Java Remote Method Protocol) OR– IIOP (Internet Inter-ORB Protocol) for CORBA
connectivity– Both build on top of TCP/IP– JRMP more advanced than IIOP
• Other Java RMI specification implementors– Historic: BEA Weblogic, Object Voyager, NinjaRMI– Object Voyager’s was JRMP compatible– Others were not– IIOP compatibility can not be guaranteed
Ingeniørhøjskolen i ÅrhusSlide 8 af 18
Local Java call vs. Java RMI call
CalledCalledCalledCalled
StubStub
StubStubStubStub
CallerCaller
CalledCalledCalledCalled
CallerCallerCallerCaller
Transport Layer (e.g. TCP or UDP)Transport Layer (e.g. TCP or UDP)Transport Layer (e.g. TCP or UDP)Transport Layer (e.g. TCP or UDP)
Similar to SOAP and CORBA – using Proxy
Ingeniørhøjskolen i ÅrhusSlide 9 af 18
InterfaceDefinition
Design
Server StubGeneration
Client StubGeneration
ServerCoding
ClientCoding
ServerRegistration
Development Steps – RMI & CORBA & SOAP
SOAP: WSDLSOAP: WSDLJava2WSDLJava2WSDL
WSDL2JAVAWSDL2JAVA
AXISSOAPAXISSOAP
RMI: JAVARMI: JAVA
J2SE JDKJ2SE JDK
Start with Server Interface Coding: JAVA
Start with Server Interface Coding: JAVA
rmiregistryrmiregistry
CORBACORBA
CORBA: IDLCORBA: IDL
CORBA: IDLCCORBA: IDLC
ORBORB
RMI: JAVA interfaceRMI: JAVA interface
C++, Java …C++, Java …
C++, Java …C++, Java …
RMI: rmicRMI: rmic
Ingeniørhøjskolen i ÅrhusSlide 10 af 18
Team.wsdlTeam.wsdl
included ingeneratesreads
WSDL-compiler
Teamcl.hh
Teamcl.cc Teamsv.cc
Teamsv.hh
Stub Generation in SOAP & CORBA
Team.idlTeam.idl
Ingeniørhøjskolen i ÅrhusSlide 11 af 18
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 theHelloImpl that is used!NOTE: In fact, it is theHelloImpl that is used!Hello.javaHello.java
Must Extend fromInterface RemoteMust Extend fromInterface Remote
From RMI v. 1.2 no skeleton is generatedFrom RMI v. 1.2 no
skeleton is generated
From Java v. 1.5 no rmic comp is neededFrom Java v. 1.5 no rmic comp is needed
Ingeniørhøjskolen i ÅrhusSlide 12 af 18
Java compiler - javac
Server
HelloClient.javaHelloClient.javaHelloImpl.javaHelloImpl.java
Java compiler - javacJava compiler - javac
Client
Hello.javaHello.java
included ingeneratesreads
rmic Compiler
RMI Client and Server Implementation
HelloImpl_Stub.classHelloImpl_Stub.class HelloImpl_Skeleton.classHelloImpl_Skeleton.class
Ingeniørhøjskolen i ÅrhusSlide 13 af 18
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 methodsfrom interface Hello.javaImplement all methods
from interface Hello.java
Extend UnicastRemoteand implemet Hello Interfacet
Extend UnicastRemoteand 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
Ingeniørhøjskolen i ÅrhusSlide 14 af 18
package examples.hello;
import java.rmi.Naming;import java.rmi.RemoteException;
public class HelloClient {
public static void main(String args[]) { try { Hello 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 stuband skeleton classes get generated
by the ”rmic” compiler
Remember – that the stuband skeleton classes get generated
by the ”rmic” compiler
AND THAT’S IT!AND THAT’S IT!
Ingeniørhøjskolen i ÅrhusSlide 15 af 18
Architecture
ServerClient
Stub RegistryInterfaces
Skeleton ActivationInterfaces
RMI Runtime (rmid,rmiregistry)
coded manuallycoded manually
rmic generatedrmic generated rmic generatedrmic generated
bindbindlookuplookup
Ingeniørhøjskolen i ÅrhusSlide 16 af 18
Things to remember
• No attributes in Java Interfaces -> RMI does not support attributes
• Attributes must be represented as set and get operations by the designer
Ingeniørhøjskolen i ÅrhusSlide 17 af 18
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!• Reflexive: can return references to other objects• And of course – if an object is not on the client –
the ByteCode gets transferred (the class incl. implementation) – if a codebase is defined
Ingeniørhøjskolen i ÅrhusSlide 18 af 18
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 (if codebase is defined)• Works in heterogene environments – 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• Not ”firewall friendly”