Coding a CORBA Server that creates Stringified Servants
Gopalan Suresh Raj

Note
To work with any of these samples, you will need the following:
.........................................JDK 1.2 (Java 2)
.........................................
The idltojava compiler

To invoke an operation on a CORBA object, a client application needs a reference to the server object. You can get such references in a number of ways, such as calling ORB.resolve_initial_references() or using another CORBA object (like the name service). Often, however, there is no naming service available in the distributed environment. In that situation, CORBA clients use a stringified object reference to find their first object.

The Steps involved in developing a CORBA Server that uses Stringification are:

  1. Define your Interface as an IDL file
  2. Compile the IDL and generate the stubs and skeletons
  3. Develop the servant class by writing an implementation for your interface
  4. Develop the CORBA Server application
  5. Compile the files and run the CORBA Server

1. Define your Interface as an IDL file
Define a module called Interest with an interface called Rates. Place this in a file called Interest.idl.

Interest.idl
module Interest {
  interface Rates {
    float getPremiumChecking();
    float getPremiumSavings();
    float getEconomyChecking();
    float getEconomySavings();
  };
};
 

2. Compile the IDL file and generate stubs and skeletons
When compiled with the idltojava compiler, the stubs and skeletons are placed in a package named after our module - Interest

E:\MyProjects\corba\Stringification>
E:\MyProjects\corba\Stringification>idltojava -fno-cpp Interest.idl

E:\MyProjects\corba\Stringification>

3. Develop the servant class by writing an implementation for our interface
Notice that we extend InterestRates. This class which we use as the parent is generated for us and is placed in the generated Interest package.

InterestRates.java
/**
 * InterestRates.java, stringified object reference version
 */

import org.omg.CORBA.*;
     // All CORBA applications need these classes.
import Interest.*;      
   // The package containing our stubs

public class InterestRates extends _RatesImplBase {
  private static final float _premiumChecking = 0.55f;
  private static final float _premiumSavings  = 2.10f;
  private static final float _economyChecking = 0.20f;
  private static final float _economySavings  = 1.50f;
 
  public float getPremiumChecking() { return _premiumChecking; }
  public float getPremiumSavings()  { return _premiumSavings; }
  public float getEconomyChecking() { return _economyChecking; }
  public float getEconomySavings()  { return _economySavings; }
}

4. Develop the CORBA server application

Server.java
/**
 * Server.java, stringified object reference version
 */

import org.omg.CORBA.*;
     // All CORBA applications need these classes.
import Interest.*;      
   // The package containing our stubs.
import java.io.*;

public class Server {

  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
      InterestRates ratesRef = new InterestRates();
      orb.connect(ratesRef);

      // stringify the ratesRef and dump it in a file
      String str = orb.object_to_string(ratesRef);
      String filename = System.getProperty("user.home")+
                        System.getProperty("file.separator")+"RatesIOR";
      FileOutputStream fos = new FileOutputStream(filename);
      PrintStream ps = new PrintStream(fos);
      ps.print(str);
      ps.close();
     
System.out.println("The Servant Reference has been Stringified...");

      System.out.println("The CORBA Server is up and running...");
     
// Wait forever for current thread to die
      Thread.currentThread().join();

    } catch (Exception e) {
      System.err.println("ERROR: " + e);
      e.printStackTrace(System.out);
    }
  }
}

5. Compile the files and run the CORBA Server

E:\MyProjects\corba\Stringification>
E:\MyProjects\corba\Stringification>javac *.java

E:\MyProjects\corba\Stringification>java Server
The Servant Reference has been Stringified...
The CORBA Server is up and running...

 

About the Author...
Gopalan Suresh Raj is a Software Architect, Developer and an active Author. He is contributing author to a couple of books "Enterprise Java Computing-Applications and Architecture" (Cambridge University Press, June '99) and "The Awesome Power of JavaBeans" (Manning, July'98). His expertise spans enterprise component architectures and distributed object computing. Visit him at his Web Cornucopia© site (http://www.execpc.com/~gopalan) or mail him at gopalan@execpc.com.

 

click here to go to the
Coding a CORBA Client that uses a Stringified reference Page...
click here to go to
My CORBA HomePage...

Go to the Component Engineering Cornucopia page

This site was developed and is maintained by Gopalan Suresh Raj

This page has been visited times since September 21,1998.

Last Updated : Dec 19, '98

If you have any questions, comments, or problems regarding this site, please write to me I would love to hear from you.


Copyright (c) 1997-2000, Gopalan Suresh Raj - All rights reserved. Terms of use.

All products and companies mentioned at this site are trademarks of their respective owners.