CSC419 ยท 2081 ยท 5 marks
How do you write an IDL file and generate the stub and skeleton code for CORBA implementation? Explain.
How do you write an IDL file and generate the stub and skeleton code for CORBA implementation? Explain. [5]
Quick answer
CORBA (Common Object Request Broker Architecture) uses Interface Definition Language (IDL) to separate the interface from the implementation. IDL is language-neutral, meaning the same IDL file can be used to generate code in Java, C++, Python, or any other supported language. This is a key advantage of CORBA over RMI, which is Java-specific.
Writing IDL File and Generating Stub/Skeleton Code for CORBA Implementation
What is IDL in CORBA?
Steps to Write an IDL File and Generate Stub/Skeleton
Step 1: Write the IDL File
An IDL file defines the interface (methods/operations) that the remote object will expose. It does not contain any implementation logic.
Syntax/Structure of an IDL file:
module ModuleName {
interface InterfaceName {
returnType methodName(in paramType paramName);
};
};
Example: Hello.idl
module HelloApp {
interface Hello {
string sayHello();
oneway void shutdown();
};
};
moduleacts like a Java package (namespace).interfacedeclares the remote methods.inmeans the parameter is passed from client to server.onewaymeans the method is asynchronous (no return value, no blocking).stringis an IDL primitive type (maps tojava.lang.Stringin Java).
Step 2: Compile the IDL File to Generate Stub and Skeleton
Use the idlj compiler (IDL-to-Java compiler) that comes with the JDK.
Command:
idlj -fall Hello.idl
-fallflag generates both client-side stub and server-side skeleton.-fclientgenerates only the client stub.-fservergenerates only the server skeleton.
Step 3: Files Generated by idlj
After running the command, the following files are generated inside the HelloApp folder:
| Generated File | Purpose |
|---|---|
_HelloStub.java | Client-side stub - acts as proxy for the client |
HelloOperations.java | Interface containing method signatures |
Hello.java | Java interface extending CORBA Object |
HelloHelper.java | Helper class for narrowing object references |
HelloHolder.java | Holder class for out/inout parameters |
HelloPOA.java | Server-side skeleton (Portable Object Adapter) |
Step 4: Implement the Server (using the Skeleton)
import HelloApp.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
public class HelloImpl extends HelloPOA {
public String sayHello() {
return "Hello from CORBA Server!";
}
public void shutdown() {
// shutdown logic
}
}
- The server class extends
HelloPOA(the generated skeleton).
Step 5: Implement the Client (using the Stub)
import HelloApp.*;
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
public class HelloClient {
public static void main(String[] args) throws Exception {
ORB orb = ORB.init(args, null);
// Locate the remote object and invoke method
Hello helloRef = HelloHelper.narrow(
orb.string_to_object("corbaname::localhost#Hello")
);
System.out.println(helloRef.sayHello());
}
}
- The client uses
HelloHelper.narrow()to get a reference to the remote object. - The stub (
_HelloStub) handles all network communication transparently.
Summary Diagram
Hello.idl
|
| idlj -fall Hello.idl
|
+---> _HelloStub.java (Client Stub)
+---> HelloPOA.java (Server Skeleton)
+---> Hello.java, HelloHelper.java, etc.
Client uses Stub --> ORB --> Skeleton --> Server Implementation
Key Points to Remember
- IDL is language-independent; it only defines the interface, not the implementation.
- The stub resides on the client side and acts as a local proxy.
- The skeleton resides on the server side and delegates calls to the actual object.
- CORBA passes objects by reference (unlike RMI which can pass by value or reference).
- The ORB (Object Request Broker) handles all communication between stub and skeleton.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.