by dr. jiang b. liu
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 PresentationTRANSCRIPT
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
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.
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)
Java IDL Client Invocation Model
An Object Invocation from a JavaIDL Client
ORB Client Invocation Model
The Structure of Object Request Broker Interfaces
OMG IDL Client Invocation Model
OMG Interface and Implementation Repositories
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)
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
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"; } }
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();} …}
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); … }