Sun Java Solaris Communities My SDN Account Join SDN

Article

Java Technology/C++ Interoperability Using CORBA

 
 

April 2000

Introduction

Different objects, written in different programming languages, can interact with each other by using CORBA. ORB (Object Request Broker) provides common services to objects written in different languages. For example, Visibroker provides a common nameserver for C++/Java Technology CORBA objects. In some cases, two different ORBs may need to interact, such as a C++; CORBA object that uses the ORBIT ORB; to talk to a Java Technology object that uses the Java Technology ORB.

CORBA objects use IOR (Interoperable Object Reference) to communicate. ORB makes the IOR transparent to the programmers. In general, for object A to talk to object B, A uses the IOR of object B. IOR is the object's address that other objects can refer to. CORBA specification provides detailed information on the fields of the IOR. There are three ways to obtain the IOR of an object:

  1. string_to_object
  2. You can obtain a stringified object reference (Email, disk, file, etc.) and use the string_to_object call to convert it into an object reference.
     

  3. resolve_initial_references
  4. You can use this call to get IORs to a small set of well known services.
    For example, to use the nameserver in a single ORB environment, you make the following call:

    resolved_initial_references("NameServer");

    The ORB returns the IOR to the name server.

  5. Lookup

You can look up the IOR in the naming service. Once you have the IOR, you can convert it into an active object reference by using the string_to_object call and then invoke methods on it. In an ORB environment that supports binding for multiple languages (e.g. Visibroker and ORBacus support C++ and the Java Programming Language), the ORB provides an uniform naming service to objects of all the languages it supports.

The naming service holds information about all the objects in the ORB. In a single ORB environment, the naming service is transparent.

If you want objects located on two different ORBs to interact and they share a common nameserver, you would use the Lookup method. However, if the objects are located on different ORBs, then the client needs to get the IOR from the server objects. There are two ways to get the IOR from the server objects:

  1. You can use a stringified reference for Object B. B writes its reference in a location that is accessible by Object A (such as on a shared NFS drive). A then performs the following:

  2. try {
    BufferedRead in=
                  new BufferedReader( new FileReader( "account.ref" ) );
       ref = in.readLine();
    } catch( IOException ex) {
            System.out.println( "Could not open file 'account.ref'" );
            System.exit( -1 );
            }
            org.omg.CORBA.Object obj = orb.string_to_object( ref );
  3. You obtain an IOR for the nameserver of the ORB in which the other object resides. You then use the nameserver to get the reference to Object B. To get the IOR for the nameserver of the target ORB, you can use well known (published) IORs or stringified IOR. For example, you can use the -ORBNamingIOR argument to provide the NamingService IOR to the calling object.

Back to Top


Example

Here is an example of Interoperability between the Java Technology 2 ORB and Mico, a GPLd 2.3 CORBA compliant ORB. This section explains how a C++ object talks to a Java Technology object, and more specifically how a C++ client makes calls to a JavaTechnology Server. The easiest way is for the Java Technology object to store its IOR in a publicly available location. Then the C++ client reads it and requests services from the Java Technology object.

Another method is to use the name server. For example, in one window, you type:

tnameserv -ORBInitialPort 1050

tnameserv prints out its IOR to the terminal.

In another window, you run the Java object:

java HelloServer -ORBInitialPort 1050

Now you can run the C++ client:

./client -ORBNoCodeSets -ORBNamingIOR IOR:010000...

You do not need to change any of the codes. Here are some of the benefits of using nameserver instead of using plain IORs:

  1. You can dynamically discover services and bind to them.
  2. You need only one IOR, that of the NameServer, to make calls to all objects.
  3. You can browse through all the names that are in the NameServer and choose the calls you need to make.

April 2000

Back to Top


Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.

Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.