Write down steps for writing CORBA programs with suitable example.

 WRITING CORBA PROGRAMS

The steps for implementing CORBA programs are discussed below.

1. Write the interface that specifies how the object works using IDL, the interface definition language, for defining CORBA interfaces. IDL is a special language to specify interfaces in a language-neutral form.

2. Using the IDL compiler(s) for the target language(s), generate the needed stub and helper classes.

3. Add the implementation code for the server objects, using the language of your choice. Write a server program that creates and registers the server objects. The most convenient method for registration is to use the CORBA naming service.

4. Write a client program that locates the server objects and invokes services on them.

 5. Compile the implementation code.

6. Start the naming service and the server program on the server and the client program on the client. 


Example

//Need to download idlj-4.2.x.jar and omgapi-4.2.x.jar files

 //put idlj-4.2.x.jar in the current folder 

//put the path omgapi-4.2.x.jar in CLAAPATH variable 


1. Write the IDL file

module EchoApp {

interface Echo {

string echoString();

};

};


2.Generate the stub and skeleton code

Compile the above file as below

E:\CORBA>java -jar idlj-4.2.4.jar -fall Echo.idl

The following files are generated by the idlj program: _EchoStub.java, Echo.java, EchoHelper.java, EchoHolder.java, EchoOperations.java, EchoPOA.java


3. Write the server code

import EchoApp. EchoPOA;

public class EchoServer extends EchoPOA {

@Override

public String echoString() {

return "Hello World!!!!!!!";

}

}

import EchoApp. Echo;

import EchoApp. EchoHelper;

import org.omg.CORBA.ORB;

import org.omg.CosNaming. NameComponent;

import org.omg.CosNaming.NamingContextExt; import org.omg.CosNaming.Naming ContextExtHelper;

import org.omg. PortableServer.POA; import org.omg. PortableServer.POAHelper;

public class Server {

public static void main(String args[]) {

try{

// create and initialize the ORB 

ORB orb = ORB.init(args, null);

// get reference to rootpoa & activate the POAManager

 POA rootpoa = POAHelper.narrow(orb.resolve_initial_references ("Root POA"));

rootpoa.the_POAManager ().activate();

// create servant

EchoServer server = new EchoServer();

// get object reference from the servant

org.omg.CORBA.Object ref = rootpoa.servant_to_reference (server);

Echo href= EchoHelper.narrow(ref);

org.omg.CORBA.Object objRef = orb.resolve_initial references ("NameService");

NamingContextExt ncRef = NamingContextExtHelper.narrow (objRef);

NameComponent path[] = ncRef.to_name( "ECHO-SERVER"); ncRef.rebind (path, href);

System.out.println("Server ready and waiting ...");

// wait for invocations from clients

orb.run();

}

catch (Exception e) {

System.err.println("ERROR:" + e);

}

System.out.println("Exiting ...");

}

}


4. Write the Client Code

import EchoApp. Echo;

import EchoApp. EchoHelper;

import org.omg.CORBA.ORB;

import org.omg.CORBA.ORBPackage.InvalidName;

import org.omg.CosNaming.NamingContextExt;

import org.omg.CosNaming.NamingContextExtHelper; 

import org.omg.CosNaming.NamingContextPackage.Cannot Proceed;

import org.omg.CosNaming.NamingContextPackage. Not Found;

public static void main (String args[]) {

try {

// create and initialize the ORB

 ORB orb = ORB.init(args, null);

org.omg.CORBA.Object objRef = orb.resolve_initial_references ("NameService");

NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

 Echo href= EchoHelper.narrow(ncRef.resolve_str("ECHO SERVER"));

String hello href.echoString();

System.out.println(hello);

}

catch (Exception e) {

System.err.println("ERROR: " + e);

}

}

}


5. Compile the code

- Compile the stub and skeleton from the directory that contains the IDL file. 

E:\CORBA\EchoApp>javac *.java

- Generate a JAR file from the compiled stub and skeleton. 

jar cvf echoapp.jar EchoApp\*.class

- Compile the server and client classes

E:\CORBA>javac Server.java EchoServer.java Client.java


 6. Running the application

 - Start the ORB server

orbd -ORBInitialPort 1050 -ORBInitialHost localhost 

- Start the server application

java Server -ORBInitialPort 1050 -ORBInitialHost localhost

 - Start the client application

java Client -ORBInitialPort 1050 -ORBInitialHost localhost


Comments

Popular posts from this blog

Short note on Uniform Gradient Cash Flow and PERT

Discuss different JavaFX layouts with suitable example.

What is the cloud cube model? Explain in context to the Jericho cloud cube model along with its various dimensions.