Make your own free website on Tripod.com

Developing a CORBA Client which invokes a CORBA Server using
The Dynamic Invocation Interface (DII)
Gopalan Suresh Raj

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

What happens if the Java interfaces for the remote CORBA Object servers are not available at compile time? You might get a reference to a CORBA Object from a Naming Service, and not know what interface that object implements. Both the Dynamic Invocation Interface (DII) and the Dynamic Skeleton Interface (DSI) API in CORBA provide "A Dynamic Interface to a CORBA Object whose interface is not known at compile time to the client of the CORBA Object".

The Steps involved in developing a CORBA Client that invokes a CORBA Server dynamically using the Dynamic Invocation Interface are:

  1. Implement your CORBA client application
  2. Compile the files and run the CORBA client

1. Implement your CORBA client application which uses DII to call the Server component

StockMarketClient.java
// StockMarketClient using DII
import org.omg.CORBA.*;
import org.omg.CosNaming.*;

public class DIIStockMarketClient {
 
 public static void main (String[] args) {
 
  ORB myORB = ORB.init (args, null);
  ORB singleORB = ORB.init ();
 
  try {
 
   // Get a reference to the object
   org.omg.CORBA.Object ncRef = myORB.resolve_initial_references ("NameService");
   NamingContext nc = NamingContextHelper.narrow (ncRef);
   NameComponent nComp = new NameComponent ("NASDAQ", "");
   NameComponent [] path = {nComp};
   org.omg.CORBA.Object objRef = nc.resolve (path);
 
   // Now make a dynamic call to the get_price method.  The first step is
   // to build the argument list. In this case, there's a single String
   // argument to the method, so create an NVList of length 1.  Next
   // create an Any object to hold the value of the argument and insert
   // the desired value.  Finally, wrap the Any object with a NamedValue
   // and insert it into the NVList, specifying that it is an input
   // parameter.
   NVList argList = myORB.create_list (1);
   Any argument = myORB.create_any ();
   argument.insert_string ("MY_COMPANY");
   NamedValue nvArg = argList.add_value ("symbol", argument, org.omg.CORBA.ARG_IN.value);
 
   // Create an Any object to hold the return value of the method and
   // wrap it in a NamedValue
   Any result = myORB.create_any ();
   result.insert_float (0);
   NamedValue resultVal = myORB.create_named_value ("result", result, org.omg.CORBA.ARG_OUT.value);
 

   // Create the method request using the default context, the name of
   // the method, the NVList argument list, and the NamedValue for the
   // result.  Then invoke the method by calling invoke () on the Request.
   Request thisReq = objRef._create_request (null, "get_price", argList, resultVal);
   thisReq.invoke ();
 
   // Get the return value from the Request object and output results.
   result = thisReq.result().value ();
   System.out.println ("get_price () returned: " + result.extract_float ());
 
  }
  catch (Exception e) {
   e.printStackTrace ();
  }
 
 }
}

2. Compile the files and run the CORBA client

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

E:\MyProjects\corba\StockCorba>java
DIIStockMarketClient
get_price () returned: $159.2

E:\MyProjects\corba\StockCorba>

 

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
Developing a CORBA Server 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.