Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President &...

45
Using RMI–IIOP in the Using RMI–IIOP in the Development of Distributed Development of Distributed Applications Applications Dr. P.G.Sarang, President & CEO, [email protected] ABCOM Information Systems Private. Limited., Mumbai, India Ms Nita P. Sarang, Consultant, [email protected] CMC Limited, Mumbai, India

Transcript of Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President &...

Page 1: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

Using RMI–IIOP in the Using RMI–IIOP in the Development of Distributed Development of Distributed

ApplicationsApplicationsDr. P.G.Sarang, President & CEO, [email protected]

ABCOM Information Systems Private. Limited., Mumbai, India

Ms Nita P. Sarang, Consultant, [email protected]

CMC Limited, Mumbai, India

Page 2: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

2

RMIRMI

Remote Method InvocationSun’s programming model for

distributed objectsJava-based

Page 3: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

3

RMI – merits/demeritsRMI – merits/demerits

Advantages – Ease of programming – No complicated Interface Definition Language

(IDL) to learn

Disadvantages – Uses Proprietary Protocol

• Java Remote Method Protocol (JRMP)

– No cross-language support

Page 4: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

4

IIOPIIOP

Internet Inter-Operable ProtocolOMG’s programming model for

distributed objectsLanguage neutral

Page 5: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

5

IIOP – merits/demeritsIIOP – merits/demerits

Advantages– Interoperability

• Between different ORB vendors• Between different languages

Disadvantages– Need to learn Interface Definition Language

(IDL)– Complex Programming

Page 6: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

6

RMI/IIOP SuitabilityRMI/IIOP Suitability

A pure RMI Java solution is suitable for new developments

For legacy applications, a CORBA wrapper is required for protecting existing investments

Page 7: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

How do we achieve How do we achieve best best

of both worlds?of both worlds?

RMI-IIOP Marriage

Page 8: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

8

ProposalProposal

A new protocol will confuse the userRMI-IIOP Merger should protect

investment in existing binariesReverse Mappings of RMI Interfaces

to CORBA IDLOMG is required to support Object

by Value (OBV)

Page 9: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

9

RequirementsRequirements

Existing RMI Clients and Servers both need upgrade to support IIOP

Page 10: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

10

RMI-IIOP ScenarioRMI-IIOP Scenario

RMI-IIOPClient

CORBAClient

CORBAServer

IIOP

IIOP

Page 11: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

How do we convert How do we convert RMIRMI Application Application

to to RMI-IIOPRMI-IIOP Application? Application?

Page 12: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

12

Converting RMI to RMI-IIOPConverting RMI to RMI-IIOP

Use PortableRemoteObject class instead of UnicastRemoteObject

Use Java Naming & Directory Interface (JNDI) instead of RMIRegistry

Use narrow method instead of Java Casts

Page 13: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

13

ToolsTools

New rmic compiler– Converts Java Interfaces to IDL– Generates IIOP Stubs and tie classes

New idlj compiler– Maps IDL to Java– Generates IIOP Stubs and tie classes

Page 14: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

14

MigrationMigration

Converting existing RMI applications to RMI-IIOP applications.

Using Java-IDL to develop RMI-IIOP applications

Converting existing RMI Interfaces to CORBA IDL

Page 15: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

Migration – Case 1

Existing RMI to RMI-IIOP

Page 16: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

16

RMI to RMI-IIOPRMI to RMI-IIOP

IIOP

RMI Java Client

RMI JavaServer

tie class

rmic -iiopComplier

stub class

RMIImplementation

Page 17: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

17

RMI to RMI-IIOPRMI to RMI-IIOP

1. Converting Server Extend your implementation class from

PortableRemoteObject rather than UnicastRemoteObject:

Use JNDI naming service rather than rmiregistry.

2. Converting Client Use JNDI naming service to locate object Use PortableRemoteObject.narrow() method

rather than Java type cast.

Page 18: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

18

Converting Server - Step 1Converting Server - Step 1

Use PortableRemoteObject rather than UnicastRemoteObject

import javax.rmi.PortableRemoteObject;…public class ComputeImpl extends

PortableRemoteObject implements Compute {

…}

Page 19: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

19

Converting Server - Step 2Converting Server - Step 2

Use JNDIimport javax.naming.*;…ReplaceNaming.rebind("//localhost/ComputeServer", obj);withjava.util.Properties env = System.getProperties();env.put ("java.naming.factory.initial",

"com.sun.jndi.cosnaming.CNCtxFactory");env.put ("java.naming.provider.url",

"iiop://localhost:900");Context ic = new InitialContext(env);ic.rebind ("//localhost/ComputeServer", obj);

Page 20: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

20

Converting Client - Step 1Converting Client - Step 1

Use JNDIReplace

Object obj = Naming.lookup ("ComputeServer");

With

java.util.Properties env = System.getProperties();

env.put ("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");

env.put ("java.naming.provider.url", "iiop://localhost:900");

Context ic = new InitialContext(env);

Object obj = ic.lookup ("//localhost/ComputeServer");

Page 21: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

21

Converting Client - Step 2Converting Client - Step 2

Replace java typecast with a call to narrow methodReplace

Compute TaxObj = (Compute)obj;

With

Compute TaxObj = (Compute)PortableRemoteObject.narrow (obj, Compute.class);

Page 22: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

22

CompilingCompiling

Compile Java Source Filesjavac –d . *.java

Generate Stub and Tie Classesrmic –iiop <ImplClass>

Example:

rmic –iiop –d . com.abcom.tax.ComputeImpl

Page 23: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

23

Running – Step 1Running – Step 1

Use JNDI Name Server rather than rmiregistry

Start the JNDI Name Server with following command

start tnameserv (on Windows)

tnameserv & (on unix)

Page 24: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

24

Running – Step 2Running – Step 2

Start the Serverjava <RemoteServer>

Example:

java com.abcom.tax.ComputeImpl

Start the clientJava <RemoteClient>

Example:

java Client

Page 25: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

Migration – Case 2

IDL to RMI-IIOP

Page 26: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

26

StepsSteps

Write Java IDLUse idlj compiler – Generates Java Mappings– Generates stubs and skeletons

Implement ServerRun Server and register with JNDI

serviceDevelop Client and test

Page 27: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

27

ExampleExample

Sample Java IDLmodule abcom{

interface tax {

float CalculateTax(in float Amount);

};

};

idlj –fall sample.idl

Page 28: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

28

Generated FilesGenerated Files

Compiler generates following files in abcom Java package– _taxImplBase.java– _taxStub.java– tax.java– taxHelper.java– taxHolder.java– taxOperations.java

Page 29: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

Migration – Case 3

Existing

Java Interfaces to IDL

Page 30: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

30

RMI to IDLRMI to IDL

Use rmic to produce idlrmic –idl <ImplClass>

Map the generated idl to the desired language and provide implementation.

Page 31: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

31

RMI to IDLRMI to IDL

RMIInterface

Impl. class

rmic -idl IDL IDL to C++

C++ CORBAServer

rmic -iiop RMI-IIOPClient

IIOP

Page 32: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

32

Sample Java Remote InterfaceSample Java Remote Interface

package com.abcom.tax;

import java.rmi.Remote;import java.rmi.RemoteException;

public interface Compute extends Remote {float SalesTax (float Amount) throws RemoteException;

}

Page 33: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

33

Generated IDLGenerated IDL

#include "orb.idl"…module com {

module abcom {module tax { interface Compute { float SalesTax(in float arg0 );

};…};

};};

Page 34: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

34

LimitationsLimitations

RMI supports passing objects by value in both parameters and method return types

CORBA 2.3 specification now supports Object by Value (OBV)

CORBA inout, out parameters not supported

Page 35: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

35

OBV – Parameter ObjectsOBV – Parameter Objects

Examplepublic class Server extends PortableRemoteObject implements Compute {…public void printInvoice(Invoice inv)throws RemoteException {

…}

} rmic –idl Server

Page 36: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

36

Parameter Objects – Generated Parameter Objects – Generated FilesFiles

Following IDL files are generated– Compute.idl– Invoice.idl

Page 37: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

37

Parameter Objects – Parameter Objects – Compute.idlCompute.idl

valuetype Invoice;

interface Compute {

void printInvoice(in ::Invoice arg0 );

};

Page 38: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

38

Parameter Objects – Invoice.idlParameter Objects – Invoice.idl

valuetype Invoice { private long quantity;

private long totalAmt;

private ::CORBA::WStringValue itemDesc;

factory create( );

};

Page 39: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

39

OBV – Returning objectsOBV – Returning objects

Examplepublic class Server extends PortableRemoteObject implements Compute {…public Invoice computeInvoice()throws

RemoteException {…

}} rmic –idl Server

Page 40: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

40

Return Objects – Generated Return Objects – Generated FilesFiles

Following IDL files are generated.– Compute.idl– Invoice.idl

Page 41: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

41

Return Objects – Compute.idlReturn Objects – Compute.idl

valuetype Invoice;

interface Compute {

::Invoice computeInvoice( );

};

Invoice.idl is same as in previous case

Page 42: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

42

OBV – Dynamic DownloadingOBV – Dynamic Downloading

Remote classes for parameter objects can be dynamically downloaded using RMI class loading mechanism– Requires setting of java.rmi.server.codebase

environment variable

Page 43: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

O'Reilly Conference on Java - Enterprise Java

Using RMI-IIOP in the Development of Distributed Applications

43

Support for Objects by ValueSupport for Objects by Value

Supported in CORBA 2.3 specification

Initial support by Java IDL ORBSupport now added by Major ORB

vendorsSupport defined for Java and C++

Page 44: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

ConclusionsConclusions

Page 45: Using RMI–IIOP in the Development of Distributed Applications Dr. P.G.Sarang, President & CEO,sarang@abcom.com ABCOM Information Systems Private. Limited.,

Thank YouThank You