11.1.6 Preparing Callback Objects Using CORBA (C++ Joint Client/Servers Only)

To set up Oracle Tuxedo C++ callback objects using CORBA, the client must do the following:

  1. Establish a connection with a POA with the appropriate policies for the callback object model. (This can be the root POA, available by default, or it may require creating a new POA.)
  2. Create a servant (that is, an instance of the C++ implementation class for the interface).
  3. Inform the POA that the servant is ready to accept requests on the callback object. Technically, this means the client activates the object in the POA (that is, puts the servant and the ObjectId into the POA’s Active Object Map).
  4. Tell the POA to start accepting requests from the network (that is, activate the POA itself).
  5. Create an object reference for the callback object.
  6. Give out the object reference. This usually happens by making an invocation on another object with the callback object reference as a parameter (that is, the parameter is a callback object). That other object will then invoke the callback object (perform a callback invocation) at some later time.

Assuming that the client already has obtained a reference to the ORB, performing this task takes four interactions with the ORB and the POA. It might look like the model show in the following code snippet. In this model, only the Root POA is needed.

// Create a servant for the callback Object
Catcher_i* my_catcher_i = new Catcher_i();
// Get root POA reference and activate the POA
1 CORBA::Object_var oref =
           orb->resolve_initial_references("RootPOA");
2 PortableServer::POA_var root_poa =
           PortableServer::POA::_narrow(oref);
3 root_poa -> the_POAManager() -> activate();
4 PortableServer::objectId_var temp_Oid =
            root_poa ->activate_object ( my_catcher_i );
5 oref = root_poa->create_reference_with_id(
            temp_Oid, _tc_Catcher->id() );
6 Catcher_var my_catcher_ref = Catcher::_narrow( oref );

To use the Persistent/UserId model, there are some additional steps required when creating a POA. Further, the ObjectId is specified by the client, and this requires more steps. It might look like the model shown in the following code snippet.

Catcher_i* my_catcher_i = new Catcher_i();
const char* oid_str = "783";
1 PortableServer::objectId_var oid =
            PortableServer::string_to_objectId(oid_str);
// Find root POA
2 CORBA::Object_var oref =
           orb->resolve_initial_references("RootPOA");
3 PortableServer::POA_var root_poa =
           PortableServer::POA::_narrow(oref);
// Create and activate a Persistent/UserId POA
4 CORBA::PolicyList policies(2);
5 policies.length(2);
6 policies[0] = root_poa->create_lifespan_policy(
           PortableServer::PERSISTENT);
7 policies[1] = root_poa->create_id_assignment_policy(
           PortableServer::USER_ID );
8 PortableServer::POA_var my_poa_ref =
           root_poa->create_POA(
"my_poa_ref", root_poa->the_POAManager(), policies);
9 root_poa->the_POAmanager()->activate();
// Create object reference for callback Object
10 oref = my_poa_ref -> create_reference_with_id(
                                         oid, _tc_Catcher->id());
11 Catcher_var my_catcher_ref = Catcher::_narrow( oref );
// activate object
12 my_poa_ref -> activate_object_with_id( oid, my_catcher_i );
// Make the call passing the callback ref
    foo -> register_callback ( my_catcher_ref );

All the interfaces and operations described here are standard CORBA interfaces and operations.