Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Locating CORBA objects using Java IDL

Learn how to use stringification and the COS Naming Service to find CORBA objects spread around the enterprise

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Page 2 of 6

IORs are convenient because they are easy to use and are ORB-implementation-independent, but they present a small challenge: How does a client obtain a copy of the stringified IOR? Although this article won't present any "real" solutions to this problem, let me offer a few possibilities:

Distributed filesystem -- The server process writes the stringified IOR to a known mount point, or shared folder, to be read by client applications, assuming every system supports a common distributed filesystem (NFS, Novell, Windows networking)

Web publishing -- The server process writes the stringified IOR to a known location in the server's document root using a servlet or CGI script, enabling client programs to easily retrieve stringified references from the Web server using the HTTP protocol

Database -- The server process writes the IOR to a table of IORs using a symbolic name as the primary key value and client programs retrieve the IOR using any suitable database API



A future column will demonstrate how to use Java Naming and Directory Interface (JNDI) to access naming and directory services, and then provide several techniques to publish CORBA objects and IORs.

Using stringification

A CORBA object is uniquely identified by an object reference. The IIOP specification defines an IOR as an ORB-independent object reference. Given a stringified object reference, a client can create a proxy that enables requests to be forwarded to the remote CORBA object. Java IDL, along with the underlying OMG CORBA standard, defines two org.omg.CORBA.ORB methods used for stringification:

  • String object_to_string(org.omg.CORBA.Object o) -- Converts the given CORBA object reference to a stringified IOR. Note: the string returned by this method is not designed to be human readable, as is the case with the Object toString() method.

  • org.omg.CORBA.Object string_to_object(String ior) -- Converts a stringified IOR produced by the method object_to_string() back to a CORBA object reference.


The stringification process is illustrated in Figure 1.

Figure 1. The stringification process

Example code

The following code sample creates a SimpleObject implementation, generates a stringified IOR, and writes it to a file called simple.ior.

package ior;
import org.omg.CORBA.ORB;
import java.io.*;
public class IorServer {
   public static void main(String args[]) throws IOException {
      //create object and register with ORB
      SimpleObjectImpl simple = new
 SimpleObjectImpl();
      //initialize ORB and stringify object
      ORB orb = ORB.init(args, null);
      String ior = orb.object_to_string(simple);
      System.out.println("IOR: " + ior);
      //write stringified object to file
      FileWriter fw = new FileWriter("simple.ior");
      fw.write(ior); 
      fw.close();
      //block to prevent application from terminating
      //CORBA does not create any user threads to service clients
      System.out.println("Ready for client requests to simple
 object...");try {
         Thread.currentThread().join();
      } catch(InterruptedException ex) {}
   }
}


After using the command-line parameters to initialize the ORB, a stringified IOR is generated using the object_to_string(). The IOR is written to a file which the client program will read to obtain the IOR. Java IDL does not create any user threads to service client requests, so the program deadlocks the interpreter's thread to prevent the application from terminating. Running the application yields the following output:

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • Download the complete source in zip format. You will need Java 2 to run the code http://www.javaworld.com/jw-02-1999/enterprise/jw-02-enterprise.zip
  • Sun's Java IDL documentation, which includes documentation covering the Java IDL API, the naming service, creating and using CORBA object references, and an introductory tutorial http://java.sun.com/products/jdk/1.2/docs/guide/idl/index.html
  • Java 2 includes support for running CORBA server and client processes, including an implementation of a CORBA-compliant transient naming service http://java.sun.com/products/jdk/1.2/
  • Java 2 does not ship with an IDL-to-Java compiler so you must download it separately if you intend to develop and implement ORB-based services. Accessing this page requires you possess a Developer Connection account (joining is free) http://developer.java.sun.com/developer/earlyAccess/jdk12/idltojava.html
  • An excellent introductory tutorial to Java IDL is provided online in Sun's The Java Tutorial http://java.sun.com/docs/books/tutorial/idl/index.html
  • The Java Naming and Directory Interface (JNDI) is a standard Java extension and provides applications with a unified interface to multiple naming and directory services http://java.sun.com/products/jndi/index.html
  • The CORBA/IIOP 2.2 Specification is available online http://www.omg.org/corba/corbaiiop.html
  • The Iona OrbixNames, Iona's implementation of the COS Naming Service is documented online http://www.iona.com/products/sysman/orbixnames/fordevelopers.html
  • The VisiBroker Naming and Event Services, Inprise's implementation of the COS Naming Service, is documented online http://www.inprise.com/techpubs/books/vbnes/vbnes33/index.html
  • Read the first-ever Enterprise Java column,"Revolutionary RMIDynamic class loading and behavior objects," in the December issue of JavaWorld http://www.javaworld.com/jw-12-1998/jw-12-enterprise.html