rmi-iiop. rmi-iiop combines rmi-style ease of use with corba cross-language interoperability ...

13
LAB#03 RMI-IIOP

Upload: christine-webster

Post on 03-Jan-2016

219 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple

LAB#03RMI-IIOP

Page 2: RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple

RMI-IIOP RMI-IIOP combines RMI-style ease of use with

CORBA cross-language interoperability Java™ Remote Method Invocation (RMI) provides

a simple mechanism for distributed Java programming. RMI over IIOP (RMI-IIOP) uses the Common Object Request Broker Architecture (CORBA) standard Internet Inter-ORB Protocol (IIOP) to extend the base Java RMI to perform communication. This allows direct interaction with any other CORBA Object Request Brokers (ORBs), whether they were implemented in Java or another programming language.

Page 3: RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple

RMI-IIOP is for Java programmers who want to program to the RMI interfaces, but use IIOP as the underlying transport. RMI-IIOP provides interoperability with other CORBA objects implemented in various languages - but only if all the remote interfaces are originally defined as Java RMI interfaces. It is of particular interest to programmers using Enterprise JavaBeans (EJB), since the remote object model for EJBs is RMI-based.

Page 4: RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple

HelloWorld Application using IIOP

Page 5: RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple

HelloInterface.java

import java.rmi.Remote;

public interface HelloInterface extends java.rmi.Remote {

public String sayHello( String from ) throws java.rmi.RemoteException;

}

Page 6: RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple

HelloImpl.javaimport javax.rmi.PortableRemoteObject;

public class HelloImpl extends PortableRemoteObject implements HelloInterface {

public HelloImpl() throws java.rmi.RemoteException {

super(); // invoke rmi linking and remote object initialization

}

public String sayHello( String from ) throws java.rmi.RemoteException {

return "Hello from " + from + "!!" ;

}

}

Page 7: RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple

By extending PortableRemoteObject, the HelloImpl class can be used to create a remote object that uses IIOP-based transport for communication.

Page 8: RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple

HelloServer.javaimport javax.naming.InitialContext;

import javax.naming.Context;

public class HelloServer {

public static void main(String[] args) {

try {

HelloImpl helloRef = new HelloImpl();

Context initialNamingContext = new InitialContext();

initialNamingContext.rebind("HelloService", helloRef );

System.out.println("Hello Server: Ready...");

} catch (Exception e) {

System.out.println("Trouble: " + e);

e.printStackTrace();

}

}

}

Page 9: RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple

HelloClient.java

import java.net.MalformedURLException;

import javax.rmi.*;

Import java.rmi.*;

import java.util.Vector;

import javax.naming.*;

import java.io.*;

public class HelloClient {

public static void main( String args[] ) {

Context ic;

Object objref;

HelloInterface hi;

Page 10: RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple

try {

ic = new InitialContext();

objref = ic.lookup("HelloService");

System.out.println("Client: Obtained a ref. to Hello server.");

hi = (HelloInterface) PortableRemoteObject.narrow(

objref, HelloInterface.class);

System.out.println(hi.sayHello( " MARS " ));

} catch( Exception e ) {

System.err.println( "Exception " + e + "Caught" );

e.printStackTrace( );

return;

}

}

}

Page 11: RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple

Compilation

Compile all classes. javac *.java

Create stubs and skeletonsrmic –iiop HelloImpl

Page 12: RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple

Execute Start Naming Service:

start orbd -ORBInitialPort 1050 Start the server:

start java -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory -Djava.naming.provider.url=iiop://localhost:1050 HelloServer

Run the client application java -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory -Djava.naming.provider.url=iiop://localhost:1050 HelloClient

Page 13: RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple

Task:

Create RMI IIOP application in which take a sentence at runtime on the client and let the server return its reverse.E.g. input : distributed computingoutput: computing distributed.

Deadline : 13th-September-2013