1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
5 <title>TAO Trading Service Documentation
</title>
8 <body text=
"#000000" link=
"#0000FF" vlink=
"#CC0000" bgcolor=
"#FFFFFF">
12 <h1 align=
"center">TAO Trading Service Documentation
</h1>
16 <p>The TAO transient Trading Service implements the COS TradingObject Service
17 specification, and
conforms to the Linked Trader conformance criteria. This document
18 details how to use the TAO Trading Service from the following perspectives:
21 <li>as an importer bootstrapping to the Trading Service;
</li>
22 <li>as a service offer exporter;
</li>
23 <li>as an administrator;
</li>
24 <li>as an out-of-the-box server process;
</li>
25 <li>as a collocated object.
</li>
28 <p>In addition, it covers running the Trading Service tests and discusses known bugs and
31 <p>This document assumes you are familiar with Trading Service concepts, such as
32 "importer,
" "exporter
",
"service type
",
"service
33 offer,
" and
"dynamic property
", as well as the roles of each of the Trading
34 Service's interfaces ---
<tt>Lookup
</tt>,
<tt>Register
</tt>,
<tt>Admin
</tt>, and
<tt>Link
</tt>
35 (the TAO implementation doesn't currently support
<tt>Proxy
</tt>). I recommend reading the
36 first two sections of the
<a href=
"ftp://www.omg.org/pub/docs/formal/97-12-23.pdf">Trading
37 Service specification
</a>. This document has the following layout:
40 <li><a href=
"#TheClientRole">The Client Role
</a> <ul>
41 <li><a href=
"#BootstrappingtotheTradingService">Bootstrapping to the Trading Service
</a> </li>
42 <li><a href=
"#The ImporterRolePerformingaQuery">The Importer Role --- Performing a Query
</a><ul>
43 <li><a href=
"#Constraints">Constraints
</a></li>
44 <li><a href=
"#Preferences">Preferences
</a></li>
45 <li><a href=
"#Policies">Policies
</a></li>
46 <li><a href=
"#FilteringProperties">Filtering Properties
</a> </li>
47 <li><a href=
"#OfferIterators">Offer Iterators
</a></li>
48 <li><a href=
"#PropertyEvaluation">Property Evaluation
</a></li>
51 <li><a href=
"#TheExporterRole">The Exporter Role --- Registering a Service Type and Offer
</a>
53 <li><a href=
"#TheServiceTypeRepository">The Service Type Repository
</a> </li>
54 <li><a href=
"#ExportingWithdrawingandModifying">Exporting, Withdrawing, and Modifying
55 Service Offers
</a> </li>
56 <li><a href=
"#ImplementingDynamicProperties">Implementing Dynamic Properties
</a></li>
59 <li><a href=
"#TheAdministratorRole">The Administrator Role --- Tweaking Policies and
60 Adjusting Links
</a></li>
63 <li><a href=
"#TheServerRole">The Server Role
</a><ul>
64 <li><a href=
"#TheTAOTradingServiceApplication">The TAO
<tt>Trading_Service
</tt> Application
</a></li>
65 <li><a href=
"#ColocatingtheTradingServiceinaTAOApplication">Colocating the Trading Service
66 in a TAO Application
</a></li>
69 <li><a href=
"#RunningtheTradingServiceTests">Running the Trading Service Tests
</a></li>
70 <li><a href=
"#KnownBugsandWorkarounds">Known Bugs and Workarounds
</a></li>
71 <li><a href=
"#FutureWork">Future Work
</a></li>
76 <h1><a name=
"TheClientRole">The Client Role
</a></h1>
78 <p align=
"left">There are three categories of operations that a client can perform on a
79 Trading Service instance: exporting a service offer to the Trading Service, importing a
80 list of Service Offers whose properties satisfy a constraint expression, and attending to
81 administrative duties --- tweaking policies or adjusting links. The first order of
82 business, of course, is obtaining a reference to a Trading Service instance, assuming that
83 instance is not colocated with the client.
</p>
85 <h2 align=
"left"><a name=
"BootstrappingtotheTradingService">Bootstrapping to the Trading
88 <p align=
"left">Like with the Naming Service, the ORB will obtain a reference to a Trading
89 Service instance's
<tt>Lookup
</tt> interface when a client invokes the
<tt>CORBA::ORB::resolve_initial_references
</tt>
90 method and passes to it the
<tt>ObjectID
</tt> "<tt>TradingService
</tt>". The
91 following TAO code bootstraps to the Trading Service:
</p>
93 <table border=
"1" width=
"100%" cellpadding=
"6">
95 <td width=
"100%"><pre>
97 TAO_ORB_Manager orb_manager;
98 orb_manager.init (argc, argv, );
99 CORBA::ORB_var orb = orb_manager.orb ();
100 CORBA::Object_var trading_obj =
101 orb-
>resolve_initial_references (
"TradingService");
102 CosTrading::Lookup_var lookup_if =
103 CosTrading::Lookup::_narrow (trading_obj.in ());
105 catch (const CORBA::Exception& ex)
107 ex.print_exception (
"Failed to bootstrap to a trader
");
114 <p>The first time
<tt>resolve_initial_references
</tt> is called, the ORB uses a multicast
115 protocol to locate an existing trader. The ORB emits a multicast packet containing a field
116 identifying the desired service --- Naming or Trading --- and the port number that the
117 client is listening on for the response (the IP address can be inferred from the packet).
118 When the trader receives the packet and finds that the id contained within matches its
119 own, it opens a socket to the client on the designated port, and sends its IOR, which the
120 ORB converts to an object reference that it caches.
</p>
122 <p>If the trader IOR is known ahead of time, the string can be passed to the client in the
123 environment variable
<tt>TradingService
</tt>, or by the command line option
<tt>-ORBtradingserviceior
124 <IOR
></tt>. Likewise, if the multicast port is known ahead of time and differs from
125 the default port, the port number can be passed to the client in the environment variable
<tt>TradingServicePort
</tt>,
126 or by the command line option
<tt>-ORBtradingserviceport
<PORTNUM
></tt>.
</p>
128 <h2><a name=
"The ImporterRolePerformingaQuery">The Importer Role --- Performing a Query
</a></h2>
130 <p>Once the importer has obtained a reference to a trader's
<tt>Lookup
</tt> interface, it
131 next needs to fire up a query. The query method takes nine parameters (aside from the
<tt>CORBA::Environment
</tt>):
</p>
133 <table border=
"1" width=
"100%" cellpadding=
"3">
135 <td width=
"39%"><tt>const CosTrading::ServiceTypeName
</tt></td>
136 <td width=
"61%">The Trading Service will search Offers belonging to this subtype. If the
<tt>exact_type_match
</tt>
137 policy wasn't explicitly set to false, then offers belonging to subtypes of this type will
138 also be searched.
</td>
141 <td width=
"39%"><tt>const CosTrading::Constraint
</tt></td>
142 <td width=
"61%">An expression in the OMG standard constraint language, where each property
143 name is a property defined in the Service Type description of the type being searched.
</td>
146 <td width=
"39%"><tt>const CosTrading::Lookup::Preference
</tt></td>
147 <td width=
"61%">An expression in the OMG standard constraint language dictating how offers
148 in the
<tt>returned_offers
</tt> sequence should be ordered.
</td>
151 <td width=
"39%"><tt>const CosTrading::PolicySeq
</tt></td>
152 <td width=
"61%">Policies governing the breadth of search and the type of permissible
153 offers. A policy is a name/value pair --- a string and an
<tt>Any
</tt> --- that affect the
154 search algorithm.
</td>
157 <td width=
"39%"><tt>const CosTrading::Lookup::SpecifiedProps
</tt></td>
158 <td width=
"61%">A union specifying which properties should be returned in each offer. If
159 the descriminator is
<tt>CosTrading::Lookup::some
</tt>, the union
contains the list
160 of designated property names. Other options are
<tt>all
</tt>or
<tt>none
</tt>.
</td>
163 <td width=
"39%"><tt>CORBA::ULong how_many
</tt></td>
164 <td width=
"61%">The number of offers that should be placed in the returned sequence.
</td>
167 <td width=
"39%"><tt>CosTrading::OfferSeq_out
</tt></td>
168 <td width=
"61%">A list of ordered offers whose properties meet the constraints.
</td>
171 <td width=
"39%"><tt>CosTrading::OfferIterator_out
</tt></td>
172 <td width=
"61%">Iterator over returned offers in excess of how_many --- unordered.
</td>
175 <td width=
"39%"><tt>CosTrading::PolicyNameSeq_out
</tt></td>
176 <td width=
"61%">A sequence of policy names for policies that limited the search.
</td>
180 <h3><a name=
"Constraints">Constraints
</a></h3>
182 <p>A constraint is a string in the OMG standard constraint language (the BNF can be found
183 at the end of the specification). The trader iterates over applicable offers, and for each
184 offer determines if its properties meet the constraints, replacing property names in the
185 string with their values and computing the result. If the constraint evaluates to true,
186 the offer is placed in the pool of matched offers. If the constraint string is
187 syntactically invalid, contains property names not found in the service type description
188 for the listed service type, or has operators with mismatched operand types, the query
189 method will throw an
<tt>InvalidConstraint
</tt> exception.
</p>
191 <p>Operands can be of two types: property names or literals. A property name is an
192 unquoted string of alphanumeric characters and underscores that begins with a letter. The
193 service type describes the type of a property. A literal is an signed or unsigned integer,
194 floating point number --- scientific notation acceptable ---, single-quoted string, or
195 boolean --- written TRUE or FALSE.
</p>
197 <p>The constraint language supports the following operations:
</p>
199 <table border=
"1" width=
"100%" cellpadding=
"3">
201 <td width=
"25%">Arithmetic (+, -, *, /)
</td>
202 <td width=
"34%"><tt>Disk_Space*
1000 - Amount_Used/
10</tt></td>
203 <td width=
"41%">Accepts two numeric operands.
</td>
206 <td width=
"25%">Inequality (
<,
>,
<=,
>=)
</td>
207 <td width=
"34%"><tt>Amount_Used
< Disk_Space
</tt></td>
208 <td width=
"41%">Accepts two numeric or two string operands.
</td>
211 <td width=
"25%">Equality (==, !=)
</td>
212 <td width=
"34%"><tt>Amount_Used == Disk_Space
</tt></td>
213 <td width=
"41%">Accepts two numeric, two string, or two boolean operands.
</td>
216 <td width=
"25%">Substring (~)
</td>
217 <td width=
"34%"><tt>'.wustl.edu' ~ Domain_Name
</tt></td>
218 <td width=
"41%">Accept two string operands. Returns true if the right string contains the
222 <td width=
"25%">Sequence inclusion (in)
</td>
223 <td width=
"34%"><tt>'sbw1' in User_Queue
</tt></td>
224 <td width=
"41%">Accepts an operand of a primitive CORBA type on the left, and a sequence
225 of the same type on the right. Returns true when the sequence contains the value in the
226 left operand, false otherwise.
</td>
229 <td width=
"25%">Property existence (exist)
</td>
230 <td width=
"34%"><tt>exist User_Queue
</tt></td>
231 <td width=
"41%">Accepts a property name. Returns true if the property is defined in the
236 <h3><a name=
"Preferences">Preferences
</a></h3>
238 <p>A preference is a constraint language string that determines the order of offers in the
239 returned offer sequence. There are five types of preferences:
</p>
241 <table border=
"1" width=
"100%" cellpadding=
"3">
243 <td width=
"18%"><tt>min
</tt> <expression
></td>
244 <td width=
"82%">Offers are ordered by ascending expression value. The expression must
245 return a number.
</td>
248 <td width=
"18%"><tt>max
</tt> <expression
> </td>
249 <td width=
"82%">Offers are ordered by descending expression value. The expression must
250 return a number.
</td>
253 <td width=
"18%"><tt>with
</tt> <expression
></td>
254 <td width=
"82%">Offers are partitioned into two parts: those offers for which the
255 expression returns true are placed in the front, the rest in the back. The expression must
256 return a boolean value.
</td>
259 <td width=
"18%"><tt>random
</tt></td>
260 <td width=
"82%">Offers in the sequence are shuffled.
</td>
263 <td width=
"18%"><tt>first
</tt></td>
264 <td width=
"82%">Offers are placed in the sequence in the order they're evaluated.
</td>
268 <h3><a name=
"Policies">Policies
</a></h3>
270 <p>The following import policies are descibed in the specification and supported by the
271 TAO Trading Service:
</p>
273 <table border=
"1" width=
"100%" cellpadding=
"3">
275 <td width=
"22%"><tt>exact_type_match
</tt></td>
276 <td width=
"18%"><tt>CORBA::Boolean
</tt></td>
277 <td width=
"60%">True --- Search only considers offers belonging to
the given type.
<br>
278 False --- Search considers offers belonging to the given type or any of its subtypes.
</td>
281 <td width=
"22%"><tt>search_card
</tt></td>
282 <td width=
"18%"><tt>CORBA::ULong
</tt></td>
283 <td width=
"60%">Search ceases after
<tt>search_card
</tt> number of offers have been
287 <td width=
"22%"><tt>match_card
</tt></td>
288 <td width=
"18%"><tt>CORBA::ULong
</tt></td>
289 <td width=
"60%">Search ceases after
<tt>search_card
</tt> number of offers have been
293 <td width=
"22%"><tt>return_card
</tt></td>
294 <td width=
"18%"><tt>CORBA::ULong
</tt></td>
295 <td width=
"60%">Query returns at most
<tt>return_card
</tt> number of offers.
</td>
298 <td width=
"22%"><tt>support_dynamic_properties
</tt></td>
299 <td width=
"18%"><tt>CORBA::Boolean
</tt></td>
300 <td width=
"60%">Search considers offers with dynamic properties.
</td>
303 <td width=
"22%"><tt>support_modifiable_properties
</tt></td>
304 <td width=
"18%"><tt>CORBA::Boolean
</tt></td>
305 <td width=
"60%">Search considers offers with not readonly properties.
</td>
308 <td width=
"22%"><tt>starting_trader
</tt></td>
309 <td width=
"18%"><tt>CosTrading::TraderName
</tt></td>
310 <td width=
"60%">Query is forwarded across all links in the policy, and search begins at
311 the final trader.
</td>
314 <td width=
"22%"><tt>hop_count
</tt></td>
315 <td width=
"18%"><tt>CORBA::ULong
</tt></td>
316 <td width=
"60%">Maximum depth a query should be propagated in the trader federation.
</td>
319 <td width=
"22%"><tt>link_follow_rule
</tt></td>
320 <td width=
"18%"><tt>CosTrading::FollowOption
</tt></td>
321 <td width=
"60%">Query propagates to other traders if the
<tt>link_follow_rule
</tt> permits
326 <p>The TAO Trading Service comes with a handy utility ---
<tt>TAO_Policy_Manager
</tt> ---
327 for creating a policy sequence to pass to the query method that won't incur any
328 exceptions.
Use the
<tt>TAO_Policy_Manager
</tt> in the following way:
</p>
330 <table border=
"1" width=
"100%" cellpadding=
"3">
332 <td width=
"100%"><pre>TAO_Policy_Manager policies;
333 policies.exact_type_match (CORBA::B_FALSE);
334 policies.search_card (
16*NUM_OFFERS);
335 policies.match_card (
16*NUM_OFFERS);
336 policies.return_card (
16*NUM_OFFERS);
337 policies.link_follow_rule (CosTrading::local_only);
338 const CosTrading::PolicySeq
& policy_seq = policies.policy_seq ();
</pre>
343 <h3><a name=
"FilteringProperties">Filtering Properties
</a></h3>
345 <p>If the client wants only a subset of the properties defined for a service type returned
346 in matching offers, it can specify those property names in the
<tt>desired_properties
</tt>
347 parameter of the query method. Pass the
<tt>prop_names
</tt> method of
<tt>CosTrading::Lookup::SpecifiedProperties
</tt>
348 a
<tt>CosTrading::PropNameSeq
</tt>:
</p>
350 <table border=
"1" width=
"100%" cellpadding=
"3">
352 <td width=
"100%"><pre>char* props[] = {
"Name
",
"Description
",
"Location
",
"Host_Name
" };
353 CosTrading::Lookup::SpecifiedProps desired_props;
354 CosTrading::PropertyNameSeq prop_name_seq (
4,
4, props, CORBA::B_FALSE);
355 desired_props.prop_names (prop_name_seq);
</pre>
360 <h3><a name=
"OfferIterators">Offer Iterators
</a></h3>
362 <p>Those offers returned from the query in excess of
<tt>how_many
</tt> are placed in an
363 offer iterator for deferred retrieval. The
<tt>CosTrading::OfferIterator::next_n
</tt>
364 method will allocate a sequence and fill it with either n offers, or if it has fewer than
<tt>n
</tt>
365 offers, the remaining offers. The
<tt>next_n
</tt> method returns true if the iterator
366 contains more offers, and false if it's been depleted. After finishing with the iterator,
367 invoke its
<tt>destroy
</tt> method to release any server-side resources.
</p>
369 <p>The following code is an example of obtaining offers from a
<tt>CosTrading::OfferIterator
</tt>:
</p>
371 <table border=
"1" width=
"100%" cellpadding=
"3">
373 <td width=
"100%"><pre>CORBA::Boolean any_left = CORBA::B_FALSE;
374 CORBA::Environment _env;
</pre>
377 CosTrading::OfferSeq_ptr iter_offers_ptr;
378 CosTrading::OfferSeq_out iter_offers_out (iter_offers_ptr);
380 any_left = offer_iterator-
>next_n (length,
383 ACE_CHECK_ENV_RETURN (_env,
0);
385 CosTrading::OfferSeq_var iter_offers (iter_offers_ptr);
388 } while (any_left);
</pre>
393 <h3><a name=
"PropertyEvaluation">Property Evaluation
</a></h3>
395 <p>After the client completes a query that used dynamic properties, to review the property
396 values of the returned offers, it has to distinguish between
<tt>Anys
</tt> containing
397 static properties and
<tt>Anys
</tt> containing dynamic property structures. The
<tt>TAO_Property_Evaluator
</tt>
398 class is a handy utility to obtain property values that hides how it evalutes properties
399 for the client --- by simple
<tt>Any
</tt> value extraction for static properties, or by
400 calling back to a dynamic property interface. The
<tt>TAO_Property_Evaluator
</tt> caches
401 the value of a dynamic property, and frees the allocated
<tt>Anys
</tt> during its
404 <p>The following code demonstrates how to use the
<tt>TAO_Property_Evaluator
</tt> to dump
405 the properties of an offer to the screen.
</p>
407 <table border=
"1" width=
"100%" cellpadding=
"3">
409 <td width=
"100%"><pre>TAO_Property_Evaluator prop_eval (prop_seq);
410 for (int length = prop_seq.length (), k =
0; k
< length; k++)
412 ACE_DEBUG ((LM_DEBUG,
"%-
15s:
", prop_seq[k].name.in ()));
415 CORBA::Boolean is_dynamic = prop_eval.is_dynamic_property (k);
418 value = prop_eval.property_value(k, env);
422 CORBA::Any::dump (*value);
426 ACE_DEBUG ((LM_DEBUG,
"Error retrieving property value.\n
"));
434 <h2><a name=
"TheExporterRole">The Exporter Role --- Registering a Service Type and Offer
</a></h2>
436 <p>Before an exporting client can register a new service offer with the Trading Service,
437 it needs to ensure first that its service type is present in the service type repository
438 of the target trader. The most efficient way to do this is to first invoke the
<tt>export
</tt>
439 method on the
<tt>Register
</tt> interface, and if it raises an
<tt>UnknownServiceType
</tt>
440 exception, obtain a reference to the Repository, add the Service Type, and attempt the
<tt>export
</tt>
441 a second time. Here's the boilerplate code:
</p>
443 <table border=
"1" width=
"100%" cellpadding=
"3">
445 <td width=
"100%"><pre>CORBA::Object_var trading_obj =
446 orb_ptr-
>resolve_initial_references (
"TradingService
");
447 CosTrading::Lookup_var lookup_if =
448 CosTrading::Lookup::_narrow (trading_obj.in ());
449 CosTrading::Register_var register_if = lookup_if-
>register_if ();
450 CosTrading::TypeRepository_ptr obj = this-
>trader_-
>type_repos ();
451 CosTradingRepos::ServiceTypeRepository_var str =
452 CosTradingRepos::ServiceTypeRepository::_narrow (obj);
456 // Attempt to export the offer.
457 offer_id = register_id-
>export (object_ref, type, props);
459 catch (const CosTrading::UnknownServiceType&, excp)
461 // If the ServiceTypeName wasn't found, we'll have to add the
462 // type to the Service Type repository ourselves.
463 str-
>add_type (type,
464 object_ref-
>_interface_repository_id (),
466 super_type_name_seq);
468 // Now we'll try again to register the offer.
469 offer_id = reg-
>export (object_ref, type, this-
>tprops_);
473 // Sigh, all our efforts were for naught.
480 <h3><a name=
"TheServiceTypeRepository">The Service Type Repository
</a></h3>
482 <p>Creating a service type description is simply a matter of filling in two sequences: a
<tt>CosTradingRepos::ServiceTypeRepository::PropStructSeq
</tt>
483 and a
<tt>CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq
</tt>. When filling in
484 the
<tt>value_type
</tt> field, remember to up the reference count of the
<tt>TypeCode
</tt>,
485 since otherwise the
<tt>TypeCode_var
</tt> will sieze control of the memory and free it.
486 Here's a code excerpt taken from
<tt>export_test
</tt> showing how to build the first
487 couple elements of such sequences:
</p>
489 <table border=
"1" width=
"100%" cellpadding=
"3">
491 <td width=
"100%"><pre>this-
>type_structs_[TT_Info::PLOTTER].props.length (
2);
492 this-
>type_structs_[TT_Info::PLOTTER].super_types.length (
1);
493 this-
>type_structs_[TT_Info::PLOTTER].super_types[
0] =
494 TT_Info::INTERFACE_NAMES[TT_Info::REMOTE_IO];
495 this-
>type_structs_[TT_Info::PLOTTER].props[
0].name =
496 TT_Info::PLOTTER_PROPERTY_NAMES[TT_Info::PLOTTER_NUM_COLORS];
497 this-
>type_structs_[TT_Info::PLOTTER].props[
0].value_type =
498 CORBA::TypeCode::_duplicate (CORBA::_tc_long);
499 this-
>type_structs_[TT_Info::PLOTTER].props[
0].mode =
500 CosTradingRepos::ServiceTypeRepository::PROP_NORMAL;
501 this-
>type_structs_[TT_Info::PLOTTER].props[
1].name =
502 TT_Info::PLOTTER_PROPERTY_NAMES[TT_Info::PLOTTER_AUTO_LOADING];
503 this-
>type_structs_[TT_Info::PLOTTER].props[
1].value_type =
504 CORBA::TypeCode::_duplicate (CORBA::_tc_boolean);
505 this-
>type_structs_[TT_Info::PLOTTER].props[
1].mode =
506 CosTradingRepos::ServiceTypeRepository::PROP_READONLY;
</pre>
511 <h3><a name=
"ExportingWithdrawingandModifying">Exporting, Withdrawing, and Modifying
512 Service Offers
</a></h3>
514 <p>Like with adding a Service Type, exporting an offer is just filling in the sequences.
515 For offers, of course, property values are passed, so this involves employing the
<tt>Any
</tt>
516 insertion operators. Here's a code exerpt from
<tt>export_test
</tt>:
</p>
518 <table border=
"1" width=
"100%" cellpadding=
"3">
520 <td width=
"100%"><pre>CosTrading::PropertySeq prop_seq (
2);
522 TT_Info::PLOTTER_PROPERTY_NAMES[TT_Info::PLOTTER_NUM_COLORS];
523 prop_seq[
0].value
<<= ACE_static_cast (CORBA::Long,
256);
525 TT_Info::PLOTTER_PROPERTY_NAMES[TT_Info::PLOTTER_AUTO_LOADING];
526 prop_seq[
1].value
<<= CORBA::Any::from_boolean (CORBA::B_TRUE);
</pre>
531 <p>The
<tt>export_test
</tt> returns a
<tt>CosTrading::OfferId
</tt> string, which is
532 required to perform the
<tt>withdraw
</tt> and
<tt>modify
</tt> operations on the exported
533 offer.
<tt>withdraw
</tt> requires that you simply pass the
<tt>OfferId
</tt> of the offer
534 to be withdrawn, while
<tt>modify
</tt> takes two additional sequences: a
<tt>CosTrading::PropertyNameSeq
</tt>
535 of property names to be removed from the offer, and a
<tt>CosTrading::PropertySeq
</tt> of
536 offers to be added or changed in the offer.
</p>
538 <h3><a name=
"ImplementingDynamicProperties">Implementing Dynamic Properties
</a></h3>
540 <p>To export an offer with a dynamic property:
543 <li>inherit from the
<tt>TAO_Dynamic_Property
</tt> class and implement its
<tt>DP_Eval
</tt>
545 <li>create a
<tt>CosTradingDynamic::DynamicProperty
</tt> structure using the
<tt>TAO_Dynamic_Property::construct_dynamic_prop
</tt>
547 <li>insert the
<tt>CosTradingDynamic::DynamicProperty
</tt> in the value field of the
551 <p>The following code, taken from the
<tt>export_test
</tt> example, illustrates this:
</p>
553 <table border=
"1" width=
"100%" cellpadding=
"3">
555 <td width=
"100%"><pre>// Step
1: Write the Dynamic Property callback handler.
556 class Simple_DP : public TAO_Dynamic_Property
560 virtual CORBA::Any* evalDP (const char* name,
561 CORBA::TypeCode_ptr returned_type,
562 const CORBA::Any
& extra_info,
563 CORBA::Environment
& _env)
564 ACE_THROW_SPEC ((CosTradingDynamic::DPEvalFailure));
568 Simple_DP::evalDP (const char* name,
569 CORBA::TypeCode_ptr returned_type,
570 const CORBA::Any
& extra_info,
571 CORBA::Environment
& _env)
572 ACE_THROW_SPEC ((CosTradingDynamic::DPEvalFailure))
574 CORBA::Any* return_value =
0;
575 ACE_NEW_RETURN (return_value, CORBA::Any,
0);
577 (*return_value)
<<= ACE_static_cast (CORBA::ULong, ACE_OS::rand ());
580 <pre>// Step
2: Create the Dynamic Property
582 CORBA::Any extra_info;
583 CosTrading::PropertySeq prop_seq (
1);
584 CosTrading::DynamicProp* dp_struct =
585 dp.construct_dynamic_prop (
"prop_name
",
588 <pre>// Step
3: Turn over the dynamic property to the propery value Any.
589 CORBA::Environment env;
590 prop_seq[
0].name =
"prop_name
";
591 prop_seq[
0].value.replace (CosTrading::_tc_DynamicProp,
595 ACE_CHECK_ENV_RETURN (env, -
1);
</pre>
600 <h2><a name=
"TheAdministratorRole">The Administrator Role --- Tweaking Policies and
601 Adjusting Links
</a></h2>
603 <p>The trader can be configured remotely through two interfaces: the
<tt>Admin
</tt>
604 interface, for tweaking global policies, enabling and disabling interfaces, and dumping
605 the trader contents; and the
<tt>Link
</tt> interface, for attaching to and detaching from
608 <p>Adjusting policies is straightforward. Here's an example of setting the
<tt>max_search_card
</tt>
611 <table border=
"1" width=
"100%" cellpadding=
"3">
613 <td width=
"100%"><pre>// lookup_if returned from resolve_initial_references.
614 CosTrading::Admin_var admin_if =
615 lookup_if-
>admin_if ();
617 <pre>admin_if-
>set_max_match_card (
200);
</pre>
622 <p>Here's an example of using the list_offers method on the Admin interface to remove all
623 offers from the Trader:
</p>
625 <table border=
"1" width=
"100%" cellpadding=
"3">
627 <td width=
"100%"><pre>
629 CosTrading::OfferIdIterator_ptr offer_id_iter;
630 CosTrading::OfferIdSeq_ptr offer_id_seq;
632 // lookup_if returned from resolve_initial_references.
633 CosTrading::Admin_var admin_if =
634 lookup_if-
>admin_if ();
636 CosTrading::Register_var register_if =
637 lookup_if-
>register_if ();
639 admin_if-
>list_offers (
10,
640 CosTrading::OfferIdSeq_out (offer_id_seq),
641 CosTrading::OfferIdIterator_out (offer_id_iter));
643 if (offer_id_seq !=
0)
645 CosTrading::OfferIdSeq_var offer_id_seq_var (offer_id_seq);
646 for (CORBA::ULong i =
0; i
< offer_id_seq_var.length (); i++)
648 register_if-
>withdraw (offer_id_seq_var[i]);
652 if (offer_id_iter != CosTrading::OfferIdIterator::_nil ())
654 CORBA::Boolean any_left = CORBA::B_FALSE;
655 CosTrading::OfferIdSeq_ptr id_seq =
0;
656 CosTrading::OfferIdIterator_var offer_id_iter_var (offer_id_iter);
661 offer_id_iter-
>next_n (length,
662 CosTrading::OfferIdSeq_out (id_seq));
664 CORBA::ULong offers = id_seq-
>length ();
665 for (CORBA::ULong i =
0; i
< offers; i++)
667 register_if-
>withdraw (id_seq[i]);
674 offer_id_iter-
>destroy ();
686 <p>Here's an example a trader linking itself to another trader (
<tt>this-
>trader_
</tt>
687 is a colocated trader --- see the next section for more information):
</p>
689 <table border=
"1" width=
"100%" cellpadding=
"3">
691 <td width=
"100%"><pre>
693 CosTrading::Link_var link_if = lookup_if-
>link_if ();
695 TAO_Trading_Components_Impl
& trd_comp =
696 this-
>trader_-
>trading_components ();
697 CosTrading::Lookup_ptr our_lookup = trd_comp.lookup_if ();
698 CosTrading::Link_ptr our_link = trd_comp.link_if ();
700 link_if-
>add_link (this-
>name_.in (),
705 our_link-
>add_link (
"Bootstrap_Trader
",
721 <h1><a name=
"TheServerRole">The Server Role
</a></h1>
723 <p>The TAO Trading Service comes with an out-of-the-box executable suitable for common
724 use. However, it can also easily be colocated with any other TAO server to add Trading
725 Service functionality to that server.
</p>
727 <h2><a name=
"TheTAOTradingServiceApplication">The TAO Trading Service Application
</a></h2>
729 <p>This out-of-the-box server takes a number of command line arguments:
</p>
731 <table border=
"1" width=
"100%" cellpadding=
"3">
733 <td width=
"26%"><tt>-TSthreadsafe
</tt></td>
734 <td width=
"74%">The Trader will use reader/writer locks to protect the offer database and
735 link collection, and normal thread mutexes for the rest of the shared state --- global
736 policies, support attributes, and interface accessors. (default is not thread safe; Null
737 Mutexes are used)
</td>
740 <td width=
"26%"><tt>-TSconformance
</tt></td>
741 <td width=
"74%">Determines which conformance category the Trading Service will meet:
<br>
742 <table border=
"0" width=
"100%" cellpadding=
"3">
745 <li><em>query
</em></li>
748 <td width=
"82%" valign=
"top" align=
"left">Instantiates the
<tt>Lookup
</tt> interface only
</td>
752 <li><em>simple
</em></li>
755 <td width=
"82%" valign=
"top" align=
"left">Instantiates the
<tt>Lookup
</tt> and
<tt>Register
</tt>
760 <li><em>standalone
</em></li>
763 <td width=
"82%" valign=
"top" align=
"left">Instantiates the
<tt>Lookup
</tt>,
<tt>Register
</tt>,
764 and
<tt>Admin
</tt> interfaces
</td>
768 <li><em>linked
</em></li>
771 <td width=
"82%" valign=
"top" align=
"left">Instantiates the
<tt>Lookup
</tt>,
<tt>Register
</tt>,
772 <tt>Admin
</tt>, and
<tt>Link
</tt> interfaces (default)
</td>
778 <td width=
"26%"><tt>-TSsupports_dynamic_properties
</tt></td>
779 <td width=
"74%"><table border=
"0" width=
"100%" cellpadding=
"3">
782 <li><em>true
</em></li>
785 <td width=
"82%" valign=
"top" align=
"left">Will consider offers with dynamic properties in
786 queries unless explicitly disabled by a policy passed to the query method. (default)
</td>
790 <li><em>false
</em></li>
793 <td width=
"82%" valign=
"top" align=
"left">Will not consider offers with dynamic properties
794 in queries, unless explicitly enabled by a policy passed to the query method.
</td>
800 <td width=
"26%"><tt>-TSsupports_modifiable_properties
</tt></td>
801 <td width=
"74%"><table border=
"0" width=
"100%" cellpadding=
"3">
804 <li><em>true
</em></li>
807 <td width=
"82%" valign=
"top" align=
"left">Will consider offers with not explicitly
808 modifable properties in queries unless explicitly disabled by a policy passed to the query
809 method. Enables the
<tt>modify
</tt> method on the
<tt>Register
</tt> interface. (default)
</td>
813 <li><em>false
</em></li>
816 <td width=
"82%" valign=
"top" align=
"left">Will not consider dynamic properties in queries,
817 unless explicitly overridden by a query policy. Diables
<tt>modify
</tt> method on the
<tt>Register
</tt>
824 <td width=
"26%"><tt>-TSdef_search_card
</tt></td>
825 <td width=
"74%">Search cardinality if none is specified as a query policy. (default is
829 <td width=
"26%"><tt>-TSmax_search_card
</tt></td>
830 <td width=
"74%">Upper limit on the search cardinality for a query. (default is
500)
</td>
833 <td width=
"26%"><tt>-TSdef_match_card
</tt></td>
834 <td width=
"74%">Match cardinality if none is specified as a query policy. (default is
200)
</td>
837 <td width=
"26%"><tt>-TSmax_match_card
</tt></td>
838 <td width=
"74%">Upper limit on the match cardinality for a query. (default is
500)
</td>
841 <td width=
"26%"><tt>-TSdef_return_card
</tt></td>
842 <td width=
"74%">Return cardinality if none is specified as a query policy. (default is
846 <td width=
"26%"><tt>-TSmax_return_card
</tt></td>
847 <td width=
"74%">Upper limit on the return cardinality for a query. (default is
500)
</td>
850 <td width=
"26%"><tt>-TSdef_hop_count
</tt></td>
851 <td width=
"74%">The depths a federated query may go if no query policy is specified.
855 <td width=
"26%"><tt>-TSmax_hop_count
</tt></td>
856 <td width=
"74%">The maximum number of links a federated query can travel after it passes
857 through this trader. (default is
10)
</td>
860 <td width=
"26%"><tt>-TSdef_follow_policy
</tt></td>
861 <td width=
"74%"><table border=
"0" width=
"100%" cellpadding=
"3">
864 <li><em>always
</em></li>
867 <td width=
"82%" valign=
"top" align=
"left">The trader will always pass a query onto the
868 next available linked trader.
</td>
872 <li><em>if_no_local
</em></li>
875 <td width=
"82%" valign=
"top" align=
"left">The trader will pass a query onto the next
876 trader only if the local search produced no results. (default)
</td>
880 <li><em>local_only
</em></li>
883 <td width=
"82%" valign=
"top" align=
"left">The trader will never pass on a query.
</td>
889 <td width=
"26%"><tt>-TSmax_follow_policy
</tt></td>
890 <td width=
"74%"><table border=
"0" width=
"100%" cellpadding=
"3">
893 <li><em>always
</em></li>
896 <td width=
"82%" valign=
"top" align=
"left">The trader doesn't limit the importer to the
897 local offer space. (default)
</td>
901 <li><em>if_no_local
</em></li>
904 <td width=
"82%" valign=
"top" align=
"left">The trader refuses to pass on queries of the
905 local search matched offers.
</td>
909 <li><em>local_only
</em></li>
912 <td width=
"82%" valign=
"top" align=
"left">The trader will never allow federated queries.
</td>
918 <td width=
"26%"><tt>-ORBtradingserviceport
</tt></td>
919 <td width=
"74%">Port on which to listen for multicast bootstrap requests.
</td>
922 <td width=
"26%"><tt>-ORBtradingserviceport
</tt></td>
923 <td width=
"74%">Port on which to listen for multicast bootstrap requests.
</td>
926 <td width=
"26%"><tt>-TSdumpior
</tt></td>
927 <td width=
"74%">Dumps the trader's IOR to a file (default is stdout).
</td>
931 <p>By default the trader will listen for multicast
<tt>resolve_initial_references
</tt>
932 requests, and respond with the IOR of its
<tt>Lookup
</tt> inteface. For the purposes of
933 testing federated queries, when passed the
<tt>-TSfederate
</tt> method, instead of
934 becoming a bootstrappable server, the
<tt>Trading_Service
</tt> application will bootstrap
935 itself to a multicast trader, link itself to that trader and every other trader accessible
936 through that trader. This protocol will have all traders on the multicast network form a
939 <h2><a name=
"ColocatingtheTradingServiceinaTAOApplication">Colocating the Trading Service
940 in a TAO Application
</a></h2>
942 <p>Colocating the Trading Service in a TAO application amounts to constructing a
<tt>TAO_TRADER
</tt>
943 object using the
<tt>TAO_Trader_Factory::construct_trader
</tt> call. The
<tt>argc
</tt> and
944 <tt>argv
</tt> parameters to
<tt>construct_trader
</tt> contain the configuration parameters
945 described in the previous section. The trader is also configurable programatically through
946 its attribute classes. The follow code exerpt demonstrates this.
</p>
948 <p>In addition the application will need to create a service type repository
949 implementation --- TAO's being the
<tt>TAO_Service_Type_Repository
</tt> --- and configure
950 the trader with it. The service type repository is separate from the trader in this way to
951 allow, for example, multiple traders to share the same service type repository. The
952 following code exerpt also demontrates configuring the repository:
</p>
954 <table border=
"1" width=
"100%" cellpadding=
"3">
956 <td width=
"100%"><pre>TAO_TRADER* trader = TAO_Trader_Factory::create_trader (argc, argv);
957 TAO_Support_Attributes_Impl
& sup_attr = trader-
>support_attributes ();
958 TAO_Import_Attributes_Impl
& imp_attr = trader-
>trading_components ();
960 // Configure the trader with a service type repository.
961 CORBA::Environment _env;
962 TAO_Service_Type_Repository type_repos* type_repos =
0;
963 ACE_NEW (type_repos, TAO_Service_Type_Repository);
964 sup_attr.type_repos (type_repos-
>_this (_env));
965 ACE_CHECK_ENV_RETURN (_env, -
1);
</pre>
966 <pre>// Configure other policies, overriding the command line arguments.
967 imp_attr.search_card (
20);
968 sup_attr.supports_dynamic_properties (CORBA::B_FALSE);
</pre>
973 <p>The trader interfaces register themselves with the default POA during the Trading
974 Service's construction. All that remains is to activate the POA and enter the ORB event
979 <h1><a name=
"RunningtheTradingServiceTests">Running the Trading Service Tests
</a></h1>
981 <p>There are two executables that test the Trading Service functionality --- one to test
982 the exporter role, and the other, the importer role. To run the tests simply launch the
<tt>Trading_Service
</tt>
983 application, then run the
<tt>export_test
</tt> executable found in the
<tt>orbsvcs/tests/Trading
</tt>
984 directory. When the
<tt>export_test
</tt> ceases to output data and enters the event loop,
985 run the
<tt>import_test
</tt> found in the same directory.
</p>
987 <p>Also of importance: the
<tt>-TSdumpior filename
</tt> argument to the trader dumps
988 its IOR to the file. You can then paste the contents on the command line to
989 the tests with
<tt>-ORBtradingserviceior IOR
</tt>, or into the environment variable
990 <tt>TradingServiceIOR
</tt>.
</p>
992 <p>The expected output of the tests can be found in the README file in the
995 <p>To test federated queries, run at least three copies of the
<tt>Trading_Service
</tt>
996 application, each using the
<tt>-TSfederate
</tt> flag. The traders will form a complete
997 graph, with each link follow policy set to
<tt>CosTrading::always
</tt>. When run with the
<tt>-f
</tt>
998 flag, the
<tt>export_test
</tt> will add the service types and export offers to each of the
999 traders in the federation. When run with the
<tt>-f
</tt> flag, the
<tt>import_test
</tt>will
1000 perform a directed query to a trader two links distant from the trader boostrapped to, in
1001 addition to performing federated queries.
</p>
1003 <p>By default the tests dump the contents of service types and offers to the screen so the
1004 tester can validate the results. To run the tests in quiet mode, where the results of the
1005 describe and query methods are concealed, use the
<tt>-q
</tt> flag.
</p>
1009 <h1><a name=
"KnownBugsandWorkarounds">Known Bugs and Workarounds
</a></h1>
1011 <p>At this point there are no known problems with TAO that affect the
1012 Trading service.
</p>
1016 <h1><a name=
"FutureWork">Future Work
</a></h1>
1019 <li><strong>Persistence
</strong> --- Have the Trading Service offer database and service
1020 type repository survive the lifetime of a single Trading Service process. This would be
1021 accomplished by either taking advantage of the ability to serialize IDL types --- using
1022 CDR streams --- or through memory-mapped files,
<em>a la
</em>the ACE Naming Service.
</li>
1026 <li><strong>The
<tt>Proxy
</tt> Interface
</strong>--- Should we ever feel so motivated, we
1027 might implement the
<tt>Proxy
</tt> interface.
</li>
1033 <a href=
"mailto:sbw1@cs.wustl.edu">Seth Benjamin Widoff
</a>
1035 <!-- Created: Mon Jun 29 12:26:36 CDT 1998 -->
1036 <!-- hhmts start -->