2.5.3 Implementing Factory-based Routing in a Factory

Factories implement factory-based routing in the way the invocation to the TP::create_object_reference() operation is implemented. This operation has the C++ binding for create_object_reference in the following code snippet.

CORBA::Object_ptr  TP::create_object_reference (
                       const char* interfaceName,
                       const PortableServer::oid &stroid,
                        CORBA::NVlist_ptr criteria);

The third parameter to this operation, criteria, specifies a list of named values to be used for factory-based routing. To implement factory-based routing in a factory, you need to build the NVlist. The use of factory-based routing is optional and is dependent on this argument. Instead of using factory-based routing, you can pass a value of 0 (zero) for this argument.

As stated previously, the RegistrarFactory object in the Production sample application specifies the value STU_ID. This value must exactly match the following information in the UBBCONFIG file:

  • The routing name, type, and allowable values specified by the FACTORYROUTING identifier in the INTERFACES section.
  • The routing criteria name, field, and field type specified in the ROUTING section.

The RegistrarFactory object inserts the student ID into the NVlist using the code shown in the following code snippet.

// put the student id (which is the routing criteria)
// into a CORBA NVList:
CORBA::NVList_var v_criteria;
TP::orb()->create_list(1, v_criteria.out());
CORBA::Any any;
any <<= (CORBA::Long)student;
v_criteria->add_value("student_id", any, 0);

The RegistrarFactory object has an invocation to the TP::create_object_reference() operation, as shown in the following code snippet. The following code snippet passes the NVlist created.

// create the registrar object reference using
// the routing criteria :
CORBA::Object_var v_reg_oref =
    TP::create_object_reference(
        UniversityP::_tc_Registrar->id(),
        object_id,
        v_criteria.in()
    );

The Production sample application also uses factory-based routing in the TellerFactory object to determine the group in which Teller objects should be instantiated based on an account number.