by dr. jiang b. liu

11
By Dr. Jiang B. Liu 11. Java IDL and CORBA Generic ORB Core idltojava development tool CORBA Object Service (COS) name service - nameserv Java IDL Hello Example

Upload: odetta

Post on 05-Jan-2016

22 views

Category:

Documents


0 download

DESCRIPTION

Java Computing. By Dr. Jiang B. Liu. 11. Java IDL and CORBA  Generic ORB Core  idltojava development tool  CORBA Object Service (COS) name service - nameserv  Java IDL Hello Example. Java IDL Network Computing. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: By Dr. Jiang B. Liu

By Dr. Jiang B. Liu

11. Java IDL and CORBA

Generic ORB Core

idltojava development tool

CORBA Object Service (COS) name service - nameserv

Java IDL Hello Example

Page 2: By Dr. Jiang B. Liu

Java IDL Network Computing

Java IDL provides connectivity and interoperability to the OMG CORBA standard.

IDL: specifies interfaces for objects (services,components, etc...) available anywhere in a network. The IDL definitions can be compiled with the idltojava stub generator tool to generate Java interface definitions and Java client and server stubs.

IIOP is a CORBA network protocol. Java IDL uses IIOP version 1.0 and it is based on a portable Java ORB core.

Page 3: By Dr. Jiang B. Liu

Network Computing: CORBA

CORBA network component computing model

CORBA

Application/BusinessObjects

CORBAFacilities(Application Frameworks)

CORBAServices(System Frameworks)

CORBA core(Object Management Architecture, IDL, Language Mapping,

and ORB components)CORBA interoperability

(IIOP)

Page 4: By Dr. Jiang B. Liu

Java IDL Client Invocation Model

An Object Invocation from a JavaIDL Client

Page 5: By Dr. Jiang B. Liu

ORB Client Invocation Model

The Structure of Object Request Broker Interfaces

Page 6: By Dr. Jiang B. Liu

OMG IDL Client Invocation Model

OMG Interface and Implementation Repositories

Page 7: By Dr. Jiang B. Liu

Java IDL Example: Hello.idl

Idl file module HelloApp {

interface hello {string sayHello();}; };

Generate Java stubsidltojava -fno-cpp -fclient -fserver -fverbose hello.idl(Generate the following interfaces/classes in the HelloApp

directory hello.java - interface (client/server)helloHolder.java - Holder class for

each interface providing out/inout parameter passing modes. (not used in this example) helloHelper.java - Helper class for for each interface providing static methods such as read, write, insert, extract, id. (client) _helloImplBase - Implementation base (server) -helloStub - Stub (client/server)

Page 8: By Dr. Jiang B. Liu

Java IDL Example: Hello.idl

Start CORBA Object Service (COS) name servicenameserv -ORBInitialPort 1050

Compile and run Hello server object javac helloServer.java helloServant.java HelloApp\_helloImplBase.java HelloApp\_helloStub.java HelloApp\hello.java

java helloServer -ORBInitialPort 1050

Compile and run Hello client object javac helloClient.java HelloApp\helloHelper.java HelloApp\_helloStub.java HelloApp\hello.java

java helloClient -ORBInitialPort 1050

Page 9: By Dr. Jiang B. Liu

Java IDL Example: Hello.idl

import HelloApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*;

class helloServant extends _helloImplBase { public String sayHello() { return "\nHello world !!\n"; } }

Page 10: By Dr. Jiang B. Liu

public class helloServer { public static void main(String args[]) { try{ // create and initialize the ORB ORB orb = ORB.init(args, null); // create servant and register it with the ORB helloServant helloRef = new helloServant(); orb.connect(helloRef); // get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContext ncRef = NamingContextHelper.narrow(objRef); // bind the Object Reference in Naming NameComponent nc = new NameComponent("Hello", ""); NameComponent path[] = {nc}; ncRef.rebind(path, helloRef); // wait for invocations from clients java.lang.Object sync = new java.lang.Object(); synchronized (sync) {sync.wait();} …}

Page 11: By Dr. Jiang B. Liu

public class helloClient { public static void main(String args[]){ try{// create and initialize the ORB ORB orb = ORB.init(args, null); // get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContext ncRef = NamingContextHelper.narrow(objRef); // resolve the Object Reference in Naming NameComponent nc = new NameComponent("Hello", ""); NameComponent path[] = {nc}; hello helloRef = helloHelper.narrow(ncRef.resolve(path)); // call the hello server object and print results String hello = helloRef.sayHello(); System.out.println(hello); … }