2081 6

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]

Advanced Java ProgrammingChapter 8: RMI and CORBAIntroduction to CORBA, RMI vs CORBA, Architecture of CORBA,

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();
    };
};
  • module acts like a Java package (namespace).
  • interface declares the remote methods.
  • in means the parameter is passed from client to server.
  • oneway means the method is asynchronous (no return value, no blocking).
  • string is an IDL primitive type (maps to java.lang.String in 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
  • -fall flag generates both client-side stub and server-side skeleton.
  • -fclient generates only the client stub.
  • -fserver generates only the server skeleton.

Step 3: Files Generated by idlj

After running the command, the following files are generated inside the HelloApp folder:

Generated FilePurpose
_HelloStub.javaClient-side stub - acts as proxy for the client
HelloOperations.javaInterface containing method signatures
Hello.javaJava interface extending CORBA Object
HelloHelper.javaHelper class for narrowing object references
HelloHolder.javaHolder class for out/inout parameters
HelloPOA.javaServer-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.