Oracle8i Enterprise JavaBeans and CORBA Developer's Guide
Release 8.1.5






Prev  Chap Top Next

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:


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:

The code to do these steps is:

org.omg.CORBA.ORB orb = org.omg.CORBA.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:

package serverServer;

import server.*;
import client.*;

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

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

Callback Client-Server Implementation

The client-side callback server is implemented like this:

package clientServer;

import client.*;

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

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.

Printback Example

Among the CORBA examples shipped on the CD there is a very interesting variant of the callback example called printback. This example shows how a server object can call back to a client to print strings from the server on the client's console. You can use code like this for debugging a running server object.



Copyright © 1999 Oracle Corporation.

All Rights Reserved.