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

Suppose that a data warehouse for Big-University consists of the following four dimensions: student, course, semester, and instructor, and two measures count and avg_grade. When at the lowest conceptual level (e.g., for a given student, course, semester, and instructor combination), the avg_grade measure stores the actual course grade of the student. At higher conceptual levels, avg_grade stores the average grade for the given combination. a) Draw a snowflake schema diagram for the data warehouse. b) Starting with the base cuboid [student, course, semester, instructor], what specific OLAP operations (e.g., roll-up from semester to year) should one perform in order to list the average grade of CS courses for each BigUniversity student. c) If each dimension has five levels (including all), such as “student < major < status < university < all”, how many cuboids will this cube contain (including the base and apex cuboids)?

Discuss classification or taxonomy of virtualization at different levels.

Pure Versus Partial EC