Oracle8i CORBA Developer's Guide and Reference Release 3 (8.1.7) Part Number A83722-01 |
Library | Service | Contents | Index

## Implementing CORBA Callbacks

This section describes how a CORBA server object can call back to a client. The basic technique that is shown in this example is the following:

- Write a client object that runs on the client side and contains the methods the called-back-to object performs.

- Implement a server object that has a method that takes a reference to the client callback object as a parameter.

- In the client code:

  - Instantiate the client callback object.

  - Register it with the BOA.

  - Pass its reference to the server object that calls it.

- In the server object implementation, perform the callback to the client.

  Note: See "Callbacks using Security" for examples of using callbacks within an SSL environment.

### IDL

The IDL for this example is shown below. There are two separate IDL files: `client.idl` and `server.idl`:

    /* client.idl */
    module client {
      interface Client {
        wstring helloBack ();
      };
    };

    /* server.idl */
    #include <client.idl>

    module server {
      interface Server {
        wstring hello (in client::Client object);
      };
    };

Note that the server interface includes the interface defined in `client.idl`.

### Client Code

The client code for this example must instantiate the client-side callback object and register it with the BOA so that it can be accessed by the server. The code performs the following steps to do this:

- Invokes the `init()` method, with no parameters, on the ORB pseudo-object. This returns a reference to the existing client-side ORB.

- Uses the ORB reference to initialize the BOA.

- Instantiates a new client object.

- Registers the client object with the client-side BOA.

The code to perform these steps is as follows:

    com.visigenic.vbroker.orb.ORB orb = oracle.aurora.jndi.orb_dep.Orb.init();
    org.omg.CORBA.BOA boa = orb.BOA_init ();
    ClientImpl client = new ClientImpl ();
    boa.obj_is_ready (client);

Finally, the client code calls the server object, passes it a reference to the registered client-side callback object, and prints its return value, as follows:

    System.out.println (server.hello (client));

### Callback Server Implementation

The implementation of the server-side object is very simple. It receives the client-side callback object and invokes a method from this object. In this example, the server invokes the client-side `helloBack` method.

    package serverServer;

    import server.*;
    import client.*;
    import oracle.aurora.AuroraServices.ActivatableObject;

    public class ServerImpl extends _ServerImplBase implements ActivatableObject
    {
      public String hello (Client client) {
        return "I Called back and got: " + client.helloBack ();
      }

      public org.omg.CORBA.Object _initializeAuroraObject () {
        return this;
      }
    }

The server simply returns a string that includes the string return value from the callback.

### Callback Client-Server Implementation

The client-side callback server implements the desired callback method. The following example implements the `helloBack` method:

    package clientServer;

    import client.*;
    import oracle.aurora.AuroraServices.ActivatableObject;

    public class ClientImpl extends _ClientImplBase implements ActivatableObject
    {
      public String helloBack () {
        return "Hello Client World!";
      }

      public org.omg.CORBA.Object _initializeAuroraObject () {
        return this;
      }
    }

The client-side object is just like any other server object. But in this callback example it is running in the client ORB, which can be running on a client system, not necessarily running inside an Oracle8i database server.

| Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
Library | Service | Contents | Index