# TAO Trading Service Documentation

The TAO transient Trading Service implements the COS TradingObject Service specification, and conforms to the Linked Trader conformance criteria. This document details how to use the TAO Trading Service from the following perspectives:

- as an importer bootstrapping to the Trading Service;
- as a service offer exporter;
- as an administrator;
- as an out-of-the-box server process;
- as a collocated object.

In addition, it covers running the Trading Service tests and discusses known bugs and workarounds.

This document assumes you are familiar with Trading Service concepts, such as "importer," "exporter", "service type", "service offer," and "dynamic property", as well as the roles of each of the Trading Service's interfaces --- `Lookup`, `Register`, `Admin`, and `Link` (the TAO implementation doesn't currently support `Proxy`). I recommend reading the first two sections of the Trading Service specification. This document has the following layout:

1. The Client Role
   - Bootstrapping to the Trading Service
   - The Importer Role --- Performing a Query
     - Constraints
     - Preferences
     - Policies
     - Filtering Properties
     - Offer Iterators
     - Property Evaluation
   - The Exporter Role --- Registering a Service Type and Offer
     - The Service Type Repository
     - Exporting, Withdrawing, and Modifying Service Offers
     - Implementing Dynamic Properties
   - The Administrator Role --- Tweaking Policies and Adjusting Links
2. The Server Role
   - The TAO `Trading_Service` Application
   - Colocating the Trading Service in a TAO Application
3. Running the Trading Service Tests
4. Known Bugs and Workarounds
5. Future Work

# The Client Role

There are three categories of operations that a client can perform on a Trading Service instance: exporting a service offer to the Trading Service, importing a list of Service Offers whose properties satisfy a constraint expression, and attending to administrative duties --- tweaking policies or adjusting links. The first order of business, of course, is obtaining a reference to a Trading Service instance, assuming that instance is not colocated with the client.

## Bootstrapping to the Trading Service

Like with the Naming Service, the ORB will obtain a reference to a Trading Service instance's `Lookup` interface when a client invokes the `CORBA::ORB::resolve_initial_references` method and passes to it the `ObjectID` "`TradingService`". The following TAO code bootstraps to the Trading Service:

    {
      TAO_ORB_Manager orb_manager;
      orb_manager.init (argc, argv, );
      CORBA::ORB_var orb = orb_manager.orb ();
      CORBA::Object_var trading_obj =
        orb->resolve_initial_references ("TradingService");
      CosTrading::Lookup_var lookup_if =
        CosTrading::Lookup::_narrow (trading_obj.in ());
    }
    catch (const CORBA::Exception& ex)
    {
      ex.print_exception ("Failed to bootstrap to a trader");
    }

The first time `resolve_initial_references` is called, the ORB uses a multicast protocol to locate an existing trader. The ORB emits a multicast packet containing a field identifying the desired service --- Naming or Trading --- and the port number that the client is listening on for the response (the IP address can be inferred from the packet). When the trader receives the packet and finds that the id contained within matches its own, it opens a socket to the client on the designated port, and sends its IOR, which the ORB converts to an object reference that it caches.

If the trader IOR is known ahead of time, the string can be passed to the client in the environment variable `TradingService`, or by the command line option `-ORBtradingserviceior <IOR>`. Likewise, if the multicast port is known ahead of time and differs from the default port, the port number can be passed to the client in the environment variable `TradingServicePort`, or by the command line option `-ORBtradingserviceport <PORTNUM>`.

## The Importer Role --- Performing a Query

Once the importer has obtained a reference to a trader's `Lookup` interface, it next needs to fire up a query. The query method takes nine parameters (aside from the `CORBA::Environment`):

`const CosTrading::ServiceTypeName` | The Trading Service will search Offers belonging to this subtype. If the `exact_type_match` policy wasn't explicitly set to false, then offers belonging to subtypes of this type will also be searched.
`const CosTrading::Constraint` | An expression in the OMG standard constraint language, where each property name is a property defined in the Service Type description of the type being searched.
`const CosTrading::Lookup::Preference` | An expression in the OMG standard constraint language dictating how offers in the `returned_offers` sequence should be ordered.
`const CosTrading::PolicySeq` | Policies governing the breadth of search and the type of permissible offers. A policy is a name/value pair --- a string and an `Any` --- that affect the search algorithm.
`const CosTrading::Lookup::SpecifiedProps` | A union specifying which properties should be returned in each offer. If the descriminator is `CosTrading::Lookup::some`, the union contains the list of designated property names. Other options are `all`or `none`.
`CORBA::ULong how_many` | The number of offers that should be placed in the returned sequence.
`CosTrading::OfferSeq_out` | A list of ordered offers whose properties meet the constraints.
`CosTrading::OfferIterator_out` | Iterator over returned offers in excess of how_many --- unordered.
`CosTrading::PolicyNameSeq_out` | A sequence of policy names for policies that limited the search.

### Constraints

A constraint is a string in the OMG standard constraint language (the BNF can be found at the end of the specification). The trader iterates over applicable offers, and for each offer determines if its properties meet the constraints, replacing property names in the string with their values and computing the result. If the constraint evaluates to true, the offer is placed in the pool of matched offers. If the constraint string is syntactically invalid, contains property names not found in the service type description for the listed service type, or has operators with mismatched operand types, the query method will throw an `InvalidConstraint` exception.

Operands can be of two types: property names or literals. A property name is an unquoted string of alphanumeric characters and underscores that begins with a letter. The service type describes the type of a property. A literal is an signed or unsigned integer, floating point number --- scientific notation acceptable ---, single-quoted string, or boolean --- written TRUE or FALSE.

The constraint language supports the following operations:

Arithmetic (+, -, *, /) | `Disk_Space*1000 - Amount_Used/10` | Accepts two numeric operands.
Inequality (<,>,<=,>=) | `Amount_Used < Disk_Space` | Accepts two numeric or two string operands.
Equality (==, !=) | `Amount_Used == Disk_Space` | Accepts two numeric, two string, or two boolean operands.
Substring (~) | `'.wustl.edu' ~ Domain_Name` | Accept two string operands. Returns true if the right string contains the left.
Sequence inclusion (in) | `'sbw1' in User_Queue` | Accepts an operand of a primitive CORBA type on the left, and a sequence of the same type on the right. Returns true when the sequence contains the value in the left operand, false otherwise.
Property existence (exist) | `exist User_Queue` | Accepts a property name. Returns true if the property is defined in the offer.

### Preferences

A preference is a constraint language string that determines the order of offers in the returned offer sequence. There are five types of preferences:

`min` <expression> | Offers are ordered by ascending expression value. The expression must return a number.
`max` <expression> | Offers are ordered by descending expression value. The expression must return a number.
`with` <expression> | Offers are partitioned into two parts: those offers for which the expression returns true are placed in the front, the rest in the back. The expression must return a boolean value.
`random` | Offers in the sequence are shuffled.
`first` | Offers are placed in the sequence in the order they're evaluated.

### Policies

The following import policies are descibed in the specification and supported by the TAO Trading Service:

`exact_type_match` | `CORBA::Boolean` | True --- Search only considers offers belonging to the given type. False --- Search considers offers belonging to the given type or any of its subtypes.
`search_card` | `CORBA::ULong` | Search ceases after `search_card` number of offers have been evaluated.
`match_card` | `CORBA::ULong` | Search ceases after `search_card` number of offers have been matched.
`return_card` | `CORBA::ULong` | Query returns at most `return_card` number of offers.
`support_dynamic_properties` | `CORBA::Boolean` | Search considers offers with dynamic properties.
`support_modifiable_properties` | `CORBA::Boolean` | Search considers offers with not readonly properties.
`starting_trader` | `CosTrading::TraderName` | Query is forwarded across all links in the policy, and search begins at the final trader.
`hop_count` | `CORBA::ULong` | Maximum depth a query should be propagated in the trader federation.
`link_follow_rule` | `CosTrading::FollowOption` | Query propagates to other traders if the `link_follow_rule` permits it.

The TAO Trading Service comes with a handy utility --- `TAO_Policy_Manager` --- for creating a policy sequence to pass to the query method that won't incur any exceptions. Use the `TAO_Policy_Manager` in the following way:

    TAO_Policy_Manager policies;
    policies.exact_type_match (CORBA::B_FALSE);
    policies.search_card (16*NUM_OFFERS);
    policies.match_card (16*NUM_OFFERS);
    policies.return_card (16*NUM_OFFERS);
    policies.link_follow_rule (CosTrading::local_only);
    const CosTrading::PolicySeq& policy_seq = policies.policy_seq ();

### Filtering Properties

If the client wants only a subset of the properties defined for a service type returned in matching offers, it can specify those property names in the `desired_properties` parameter of the query method. Pass the `prop_names` method of `CosTrading::Lookup::SpecifiedProperties` a `CosTrading::PropNameSeq`:

    char* props[] = {"Name", "Description", "Location", "Host_Name" };
    CosTrading::Lookup::SpecifiedProps desired_props;
    CosTrading::PropertyNameSeq prop_name_seq (4, 4, props, CORBA::B_FALSE);
    desired_props.prop_names (prop_name_seq);

### Offer Iterators

Those offers returned from the query in excess of `how_many` are placed in an offer iterator for deferred retrieval. The `CosTrading::OfferIterator::next_n` method will allocate a sequence and fill it with either n offers, or if it has fewer than `n` offers, the remaining offers. The `next_n` method returns true if the iterator contains more offers, and false if it's been depleted. After finishing with the iterator, invoke its `destroy` method to release any server-side resources.

The following code is an example of obtaining offers from a `CosTrading::OfferIterator`:

    CORBA::Boolean any_left = CORBA::B_FALSE;
    CORBA::Environment _env;
    do
      {
        CosTrading::OfferSeq_ptr iter_offers_ptr;
        CosTrading::OfferSeq_out iter_offers_out (iter_offers_ptr);

        any_left = offer_iterator->next_n (length,
                            	       iter_offers_out,
                                           _env);
        ACE_CHECK_ENV_RETURN (_env, 0);

        CosTrading::OfferSeq_var iter_offers (iter_offers_ptr);
        // Process offers...

      } while (any_left);

### Property Evaluation

After the client completes a query that used dynamic properties, to review the property values of the returned offers, it has to distinguish between `Anys` containing static properties and `Anys` containing dynamic property structures. The `TAO_Property_Evaluator` class is a handy utility to obtain property values that hides how it evalutes properties for the client --- by simple `Any` value extraction for static properties, or by calling back to a dynamic property interface. The `TAO_Property_Evaluator` caches the value of a dynamic property, and frees the allocated `Anys` during its destruction.

The following code demonstrates how to use the `TAO_Property_Evaluator` to dump the properties of an offer to the screen.

    TAO_Property_Evaluator prop_eval (prop_seq);
    for (int length = prop_seq.length (), k = 0; k < length; k++)
      {
        ACE_DEBUG ((LM_DEBUG, "%-15s: ", prop_seq[k].name.in ()));
        ACE_TRY
          {
            CORBA::Boolean is_dynamic = prop_eval.is_dynamic_property (k);
            ACE_CHECK_ENV;

    	value = prop_eval.property_value(k, env);
        	ACE_CHECK_ENV;

    	if (value != 0)
    	  CORBA::Any::dump (*value);
          }
        ACE_CATCHANY
          {
            ACE_DEBUG ((LM_DEBUG, "Error retrieving property value.\n"));
          }
        ACE_ENDTRY;
      }

## The Exporter Role --- Registering a Service Type and Offer

Before an exporting client can register a new service offer with the Trading Service, it needs to ensure first that its service type is present in the service type repository of the target trader. The most efficient way to do this is to first invoke the `export` method on the `Register` interface, and if it raises an `UnknownServiceType` exception, obtain a reference to the Repository, add the Service Type, and attempt the `export` a second time. Here's the boilerplate code:

    CORBA::Object_var trading_obj =
      orb_ptr->resolve_initial_references ("TradingService");
    CosTrading::Lookup_var lookup_if =
      CosTrading::Lookup::_narrow (trading_obj.in ());
    CosTrading::Register_var register_if = lookup_if->register_if ();
    CosTrading::TypeRepository_ptr obj = this->trader_->type_repos ();
    CosTradingRepos::ServiceTypeRepository_var str =
      CosTradingRepos::ServiceTypeRepository::_narrow (obj);

    try
      {
        // Attempt to export the offer.
        offer_id = register_id->export (object_ref, type, props);
      }
    catch (const CosTrading::UnknownServiceType&, excp)
      {
        // If the ServiceTypeName wasn't found, we'll have to add the
        // type to the Service Type repository ourselves.
        str->add_type (type,
    		   object_ref->_interface_repository_id (),
    		   prop_struct_seq,
    		   super_type_name_seq);

        // Now we'll try again to register the offer.
        offer_id = reg->export (object_ref, type, this->tprops_);
      }
    catch (...)
      {
        // Sigh, all our efforts were for naught.
        throw ();
      }

### The Service Type Repository

Creating a service type description is simply a matter of filling in two sequences: a `CosTradingRepos::ServiceTypeRepository::PropStructSeq` and a `CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq`. When filling in the `value_type` field, remember to up the reference count of the `TypeCode`, since otherwise the `TypeCode_var` will sieze control of the memory and free it. Here's a code excerpt taken from `export_test` showing how to build the first couple elements of such sequences:

    this->type_structs_[TT_Info::PLOTTER].props.length (2);
    this->type_structs_[TT_Info::PLOTTER].super_types.length (1);
    this->type_structs_[TT_Info::PLOTTER].super_types[0] =
    TT_Info::INTERFACE_NAMES[TT_Info::REMOTE_IO];
    this->type_structs_[TT_Info::PLOTTER].props[0].name =
    TT_Info::PLOTTER_PROPERTY_NAMES[TT_Info::PLOTTER_NUM_COLORS];
    this->type_structs_[TT_Info::PLOTTER].props[0].value_type =
    CORBA::TypeCode::_duplicate (CORBA::_tc_long);
    this->type_structs_[TT_Info::PLOTTER].props[0].mode =
    CosTradingRepos::ServiceTypeRepository::PROP_NORMAL;
    this->type_structs_[TT_Info::PLOTTER].props[1].name =
    TT_Info::PLOTTER_PROPERTY_NAMES[TT_Info::PLOTTER_AUTO_LOADING];
    this->type_structs_[TT_Info::PLOTTER].props[1].value_type =
    CORBA::TypeCode::_duplicate (CORBA::_tc_boolean);
    this->type_structs_[TT_Info::PLOTTER].props[1].mode =
    CosTradingRepos::ServiceTypeRepository::PROP_READONLY;

### Exporting, Withdrawing, and Modifying Service Offers

Like with adding a Service Type, exporting an offer is just filling in the sequences. For offers, of course, property values are passed, so this involves employing the `Any` insertion operators. Here's a code exerpt from `export_test`:

    CosTrading::PropertySeq prop_seq (2);
    prop_seq[0].name =
      TT_Info::PLOTTER_PROPERTY_NAMES[TT_Info::PLOTTER_NUM_COLORS];
    prop_seq[0].value <<= ACE_static_cast (CORBA::Long, 256);
    prop_seq[1].name =
      TT_Info::PLOTTER_PROPERTY_NAMES[TT_Info::PLOTTER_AUTO_LOADING];
    prop_seq[1].value <<= CORBA::Any::from_boolean (CORBA::B_TRUE);

The `export_test` returns a `CosTrading::OfferId` string, which is required to perform the `withdraw` and `modify` operations on the exported offer. `withdraw` requires that you simply pass the `OfferId` of the offer to be withdrawn, while `modify` takes two additional sequences: a `CosTrading::PropertyNameSeq` of property names to be removed from the offer, and a `CosTrading::PropertySeq` of offers to be added or changed in the offer.

### Implementing Dynamic Properties

To export an offer with a dynamic property:

- inherit from the `TAO_Dynamic_Property` class and implement its `DP_Eval` method;
- create a `CosTradingDynamic::DynamicProperty` structure using the `TAO_Dynamic_Property::construct_dynamic_prop` method;
- insert the `CosTradingDynamic::DynamicProperty` in the value field of the property.

The following code, taken from the `export_test` example, illustrates this:

    // Step 1: Write the Dynamic Property callback handler.
    class Simple_DP : public TAO_Dynamic_Property
    {
    public:

      virtual CORBA::Any* evalDP (const char* name,
                                  CORBA::TypeCode_ptr returned_type,
                                  const CORBA::Any& extra_info,
    			      CORBA::Environment& _env)
        ACE_THROW_SPEC ((CosTradingDynamic::DPEvalFailure));
    };

    CORBA::Any*
    Simple_DP::evalDP (const char* name,
                       CORBA::TypeCode_ptr returned_type,
                       const CORBA::Any& extra_info,
                       CORBA::Environment& _env)
      ACE_THROW_SPEC ((CosTradingDynamic::DPEvalFailure))
    {
      CORBA::Any* return_value = 0;
      ACE_NEW_RETURN (return_value, CORBA::Any, 0);

      (*return_value) <<= ACE_static_cast (CORBA::ULong, ACE_OS::rand ());
      return return_value;
    }
    // Step 2: Create the Dynamic Property
    Simple_DP dp;
    CORBA::Any extra_info;
    CosTrading::PropertySeq prop_seq (1);
    CosTrading::DynamicProp* dp_struct =
      dp.construct_dynamic_prop ("prop_name",
                                 CORBA::_tc_ulong,
    			     extra_info);
    // Step 3: Turn over the dynamic property to the propery value Any.
    CORBA::Environment env;
    prop_seq[0].name = "prop_name";
    prop_seq[0].value.replace (CosTrading::_tc_DynamicProp,
                               dp_struct,
                               CORBA::B_TRUE,
                               env);
    ACE_CHECK_ENV_RETURN (env, -1);

## The Administrator Role --- Tweaking Policies and Adjusting Links

The trader can be configured remotely through two interfaces: the `Admin` interface, for tweaking global policies, enabling and disabling interfaces, and dumping the trader contents; and the `Link` interface, for attaching to and detaching from other traders.

Adjusting policies is straightforward. Here's an example of setting the `max_search_card` policy:

    // lookup_if returned from resolve_initial_references.
    CosTrading::Admin_var admin_if =
      lookup_if->admin_if ();
    admin_if->set_max_match_card (200);

Here's an example of using the list_offers method on the Admin interface to remove all offers from the Trader:

    {
    CosTrading::OfferIdIterator_ptr offer_id_iter;
    CosTrading::OfferIdSeq_ptr offer_id_seq;

    // lookup_if returned from resolve_initial_references.
    CosTrading::Admin_var admin_if =
      lookup_if->admin_if ();

    CosTrading::Register_var register_if =
      lookup_if->register_if ();

    admin_if->list_offers (10,
                           CosTrading::OfferIdSeq_out (offer_id_seq),
                           CosTrading::OfferIdIterator_out (offer_id_iter));

    if (offer_id_seq != 0)
     {
       CosTrading::OfferIdSeq_var offer_id_seq_var (offer_id_seq);
       for (CORBA::ULong i = 0; i < offer_id_seq_var.length (); i++)
         {
           register_if->withdraw (offer_id_seq_var[i]);
         }
     }

    if (offer_id_iter != CosTrading::OfferIdIterator::_nil ())
     {
       CORBA::Boolean any_left = CORBA::B_FALSE;
       CosTrading::OfferIdSeq_ptr id_seq = 0;
       CosTrading::OfferIdIterator_var offer_id_iter_var (offer_id_iter);

       do
         {
           any_left =
             offer_id_iter->next_n (length,
                                    CosTrading::OfferIdSeq_out (id_seq));

           CORBA::ULong offers = id_seq->length ();
           for (CORBA::ULong i = 0; i < offers; i++)
            {
              register_if->withdraw (id_seq[i]);
            }

           delete id_seq;
         }
       while (any_left);

       offer_id_iter->destroy ();
     }
    }
    catch (...)
    {
      // Handle Errors.
    }

Here's an example a trader linking itself to another trader (`this->trader_` is a colocated trader --- see the next section for more information):

     {
       CosTrading::Link_var link_if =  lookup_if->link_if ();

       TAO_Trading_Components_Impl& trd_comp =
         this->trader_->trading_components ();
       CosTrading::Lookup_ptr our_lookup = trd_comp.lookup_if ();
       CosTrading::Link_ptr our_link = trd_comp.link_if ();

       link_if->add_link (this->name_.in (),
                          our_lookup,
                          CosTrading::always,
                          CosTrading::always);

       our_link->add_link ("Bootstrap_Trader",
                           lookup_if.in (),
                           CosTrading::always,
                           CosTrading::always);
     }
    catch (...)
    {
      // Handle Errors.
    }

# The Server Role

The TAO Trading Service comes with an out-of-the-box executable suitable for common use. However, it can also easily be colocated with any other TAO server to add Trading Service functionality to that server.

## The TAO Trading Service Application

This out-of-the-box server takes a number of command line arguments:

`-TSthreadsafe` | The Trader will use reader/writer locks to protect the offer database and link collection, and normal thread mutexes for the rest of the shared state --- global policies, support attributes, and interface accessors. (default is not thread safe; Null Mutexes are used)
`-TSconformance` | Determines which conformance category the Trading Service will meet:
query | Instantiates the `Lookup` interface only
simple | Instantiates the `Lookup` and `Register` interfaces
standalone | Instantiates the `Lookup`, `Register`, and `Admin` interfaces
linked | Instantiates the `Lookup`, `Register`, `Admin`, and `Link` interfaces (default)
`-TSsupports_dynamic_properties` |
true | Will consider offers with dynamic properties in queries unless explicitly disabled by a policy passed to the query method. (default)
false | Will not consider offers with dynamic properties in queries, unless explicitly enabled by a policy passed to the query method.
`-TSsupports_modifiable_properties` |
true | Will consider offers with not explicitly modifable properties in queries unless explicitly disabled by a policy passed to the query method. Enables the `modify` method on the `Register` interface. (default)
false | Will not consider dynamic properties in queries, unless explicitly overridden by a query policy. Diables `modify` method on the `Register` interface.
`-TSdef_search_card` | Search cardinality if none is specified as a query policy. (default is 200)
`-TSmax_search_card` | Upper limit on the search cardinality for a query. (default is 500)
`-TSdef_match_card` | Match cardinality if none is specified as a query policy. (default is 200)
`-TSmax_match_card` | Upper limit on the match cardinality for a query. (default is 500)
`-TSdef_return_card` | Return cardinality if none is specified as a query policy. (default is 200)
`-TSmax_return_card` | Upper limit on the return cardinality for a query. (default is 500)
`-TSdef_hop_count` | The depths a federated query may go if no query policy is specified. (default 5)
`-TSmax_hop_count` | The maximum number of links a federated query can travel after it passes through this trader. (default is 10)
`-TSdef_follow_policy` |
always | The trader will always pass a query onto the next available linked trader.
if_no_local | The trader will pass a query onto the next trader only if the local search produced no results. (default)
local_only | The trader will never pass on a query.
`-TSmax_follow_policy` |
always | The trader doesn't limit the importer to the local offer space. (default)
if_no_local | The trader refuses to pass on queries of the local search matched offers.
local_only | The trader will never allow federated queries.
`-ORBtradingserviceport` | Port on which to listen for multicast bootstrap requests.
`-ORBtradingserviceport` | Port on which to listen for multicast bootstrap requests.
`-TSdumpior` | Dumps the trader's IOR to a file (default is stdout).

By default the trader will listen for multicast `resolve_initial_references` requests, and respond with the IOR of its `Lookup` inteface. For the purposes of testing federated queries, when passed the `-TSfederate` method, instead of becoming a bootstrappable server, the `Trading_Service` application will bootstrap itself to a multicast trader, link itself to that trader and every other trader accessible through that trader. This protocol will have all traders on the multicast network form a complete graph.

## Colocating the Trading Service in a TAO Application

Colocating the Trading Service in a TAO application amounts to constructing a `TAO_TRADER` object using the `TAO_Trader_Factory::construct_trader` call. The `argc` and `argv` parameters to `construct_trader` contain the configuration parameters described in the previous section. The trader is also configurable programatically through its attribute classes. The follow code exerpt demonstrates this.

In addition the application will need to create a service type repository implementation --- TAO's being the `TAO_Service_Type_Repository` --- and configure the trader with it. The service type repository is separate from the trader in this way to allow, for example, multiple traders to share the same service type repository. The following code exerpt also demontrates configuring the repository:

    TAO_TRADER* trader = TAO_Trader_Factory::create_trader (argc, argv);
    TAO_Support_Attributes_Impl& sup_attr = trader->support_attributes ();
    TAO_Import_Attributes_Impl& imp_attr = trader->trading_components ();

    // Configure the trader with a service type repository.
    CORBA::Environment _env;
    TAO_Service_Type_Repository type_repos* type_repos = 0;
    ACE_NEW (type_repos, TAO_Service_Type_Repository);
    sup_attr.type_repos (type_repos->_this (_env));
    ACE_CHECK_ENV_RETURN (_env, -1);
    // Configure other policies, overriding the command line arguments.
    imp_attr.search_card (20);
    sup_attr.supports_dynamic_properties (CORBA::B_FALSE);

The trader interfaces register themselves with the default POA during the Trading Service's construction. All that remains is to activate the POA and enter the ORB event loop.

# Running the Trading Service Tests

There are two executables that test the Trading Service functionality --- one to test the exporter role, and the other, the importer role. To run the tests simply launch the `Trading_Service` application, then run the `export_test` executable found in the `orbsvcs/tests/Trading` directory. When the `export_test` ceases to output data and enters the event loop, run the `import_test` found in the same directory.

Also of importance: the `-TSdumpior filename` argument to the trader dumps its IOR to the file. You can then paste the contents on the command line to the tests with `-ORBtradingserviceior IOR`, or into the environment variable `TradingServiceIOR`.

The expected output of the tests can be found in the README file in the tests directory.

To test federated queries, run at least three copies of the `Trading_Service` application, each using the `-TSfederate` flag. The traders will form a complete graph, with each link follow policy set to `CosTrading::always`. When run with the `-f` flag, the `export_test` will add the service types and export offers to each of the traders in the federation. When run with the `-f` flag, the `import_test` will perform a directed query to a trader two links distant from the trader boostrapped to, in addition to performing federated queries.

By default the tests dump the contents of service types and offers to the screen so the tester can validate the results. To run the tests in quiet mode, where the results of the describe and query methods are concealed, use the `-q` flag.

# Known Bugs and Workarounds

At this point there are no known problems with TAO that affect the Trading service.

# Future Work

- Persistence --- Have the Trading Service offer database and service type repository survive the lifetime of a single Trading Service process. This would be accomplished by either taking advantage of the ability to serialize IDL types --- using CDR streams --- or through memory-mapped files, a la the ACE Naming Service.

- The `Proxy` Interface --- Should we ever feel so motivated, we might implement the `Proxy` interface.