Advanced Topic: The Dynamic Skeleton Interface (DSI)


The Dynamic Skeleton Interface (DSI) allows servers to serve a servant object without prior (compile time) knowledge of the object's interface. Insead of using skeleton code compiled from the IDL interface definition, the server constructs an operation invocation dynamically.

Why Use DSI?

DSI can be used to bridge CORBA with non-CORBA environments. Such a bridge would allow CORBA clients to invoke methods on CORBA objects that are implemented as, for example, COM services.

The dynamic servant is implemented to convert the CORBA client request to a format understood by the COM server. You must write all the code to perform this work. Contrast this with a typical static object invocation. The server has access to the compiled skeletons for the interface being invoked. These skeletons are generated by compiling the IDL interface definitions with the idltojava compiler. When the ORB receives a request, it uses the skeleton code to build operation arguments on the server side and to send back any result.

Dynamic Servant Implementation Example

Consider the following interface:

module HelloApp
{
    interface Hello
    {
        string printHelloArgs(in string arg1, in short arg2);
    };
};

The following code is a shell implementation of a dynamic servant for the above interface. It is a shell because only the basic compilable infrastructure for parsing method requests is provided. You would need to insert code to implement a bridge.

// Copyright and License 

import HelloApp.*;

import java.util.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import java.io.*;
import org.omg.CORBA.*;

// servant must extend DynamicImplementation
class HelloServant extends DynamicImplementation
{

    // store the repository ID for the implemented interface
    static String[] myIDs = {"IDL:JavaIDL/DSIExample:1.0"};
    ORB orb;

    // create a reference to the ORB
    HelloServant(ORB orb) {
        this.orb = orb;
    }
    // must implement invoke() for handling requests
    public void invoke(ServerRequest request) {
        try {
            System.out.println("DSI: invoke called, op = "+request.op_name());

	    // create an NVList to hold the parameters
            NVList nvlist = orb.create_list(0);

	    // need an if statement like this for each method name
            if (request.op_name().equals("printHelloArgs") == true) {

		    // need an Any for each argument
                    Any any1 = orb.create_any();
                    any1.insert_string("");
                    nvlist.add_value("arg1", any1, ARG_IN.value);

                    Any any2 = orb.create_any();
                    any2.insert_string("");
                    nvlist.add_value("arg2", any2, ARG_IN.value);

		    // pass the NVList to the request to get values
                    request.params(nvlist);

                    System.err.println("Argument 1: In value: " + nvlist.item(0).value().extract_string());

                    System.err.println("Argument 2: In value: " + nvlist.item(1).value().extract_short());

                    TypeCode result_tc = orb.get_primitive_tc(TCKind.tk_void);
                    Any result_any = orb.create_any();
                    result_any.type(result_tc);

                    request.result(result_any);
            }
        }
        catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("DSIExample: Exception thrown: " + ex);
        }
    }    

// implement an _ids method to return repository ID of interface
public String[] _ids() {    
        return myIDs;
}

// HelloServer implemented in the usual fashion 
public class HelloServer {
 
    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
            HelloServant helloRef = new HelloServant(orb);
            orb.connect(helloRef);
 
            OutputStream f = new FileOutputStream(System.getProperty("user.home")+System.getProperty("file.separator")+"DSI.ior");
            DataOutputStream out = new DataOutputStream(f);
            String ior = orb.object_to_string(helloRef);
            out.writeBytes(ior);
            out.close();
 
            System.out.println("IOR is "+ ior);
 
            // wait for invocations from clients
            java.lang.Object sync = new java.lang.Object();
            synchronized (sync) {
                sync.wait();
            }
 
        } catch (Exception e) {
            System.err.println("ERROR: " + e);
            e.printStackTrace(System.out);
        }
    }
}      


Home

Copyright © 1995-98 Sun Microsystems, Inc. All Rights Reserved.