Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / docs / releasenotes / trader.html
blob95c1126de981cb479acadbbe1770cead0cf56e50
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
4 <head>
5 <title>TAO Trading Service Documentation</title>
6 </head>
8 <body text="#000000" link="#0000FF" vlink="#CC0000" bgcolor="#FFFFFF">
9 <!-- -->
10 <hr>
12 <h1 align="center">TAO Trading Service Documentation</h1>
14 <hr>
16 <p>The TAO transient Trading Service implements the COS TradingObject Service
17 specification, and&nbsp; conforms to the Linked Trader conformance criteria. This document
18 details how to use the TAO Trading Service from the following perspectives:
20 <ul>
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>
26 </ul>
28 <p>In addition, it covers running the Trading Service tests and discusses known bugs and
29 workarounds.</p>
31 <p>This document assumes you are familiar with Trading Service concepts, such as
32 &quot;importer,&quot; &quot;exporter&quot;, &quot;service type&quot;, &quot;service
33 offer,&quot; and &quot;dynamic property&quot;, 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:
39 <ol>
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>
49 </ul>
50 </li>
51 <li><a href="#TheExporterRole">The Exporter Role --- Registering a Service Type and Offer</a>
52 <ul>
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>
57 </ul>
58 </li>
59 <li><a href="#TheAdministratorRole">The Administrator Role --- Tweaking Policies and
60 Adjusting Links</a></li>
61 </ul>
62 </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>
67 </ul>
68 </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>
72 </ol>
74 <hr>
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
86 Service</a></h2>
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> &quot;<tt>TradingService</tt>&quot;. The
91 following TAO code bootstraps to the Trading Service:</p>
93 <table border="1" width="100%" cellpadding="6">
94 <tr>
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-&gt;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 (&quot;Failed to bootstrap to a trader&quot;);
109 </pre>
110 </td>
111 </tr>
112 </table>
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 &lt;IOR&gt;</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 &lt;PORTNUM&gt;</tt>. &nbsp; </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">
134 <tr>
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>
139 </tr>
140 <tr>
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>
144 </tr>
145 <tr>
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>
149 </tr>
150 <tr>
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>
155 </tr>
156 <tr>
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&nbsp; contains the list
160 of designated property names. Other options are <tt>all</tt>or <tt>none</tt>. </td>
161 </tr>
162 <tr>
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>
165 </tr>
166 <tr>
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>
169 </tr>
170 <tr>
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>
173 </tr>
174 <tr>
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>
177 </tr>
178 </table>
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">
200 <tr>
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>
204 </tr>
205 <tr>
206 <td width="25%">Inequality (&lt;,&gt;,&lt;=,&gt;=)</td>
207 <td width="34%"><tt>Amount_Used &lt; Disk_Space</tt></td>
208 <td width="41%">Accepts two numeric or two string operands.</td>
209 </tr>
210 <tr>
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>
214 </tr>
215 <tr>
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
219 left.</td>
220 </tr>
221 <tr>
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>
227 </tr>
228 <tr>
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
232 offer.</td>
233 </tr>
234 </table>
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">
242 <tr>
243 <td width="18%"><tt>min</tt> &lt;expression&gt;</td>
244 <td width="82%">Offers are ordered by ascending expression value. The expression must
245 return a number.</td>
246 </tr>
247 <tr>
248 <td width="18%"><tt>max</tt> &lt;expression&gt; </td>
249 <td width="82%">Offers are ordered by descending expression value. The expression must
250 return a number. </td>
251 </tr>
252 <tr>
253 <td width="18%"><tt>with</tt> &lt;expression&gt;</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>
257 </tr>
258 <tr>
259 <td width="18%"><tt>random</tt></td>
260 <td width="82%">Offers in the sequence are shuffled.</td>
261 </tr>
262 <tr>
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>
265 </tr>
266 </table>
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">
274 <tr>
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&nbsp; the given type.<br>
278 False --- Search considers offers belonging to the given type or any of its subtypes.</td>
279 </tr>
280 <tr>
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
284 evaluated.</td>
285 </tr>
286 <tr>
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
290 matched.</td>
291 </tr>
292 <tr>
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>
296 </tr>
297 <tr>
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>
301 </tr>
302 <tr>
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>
306 </tr>
307 <tr>
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>
312 </tr>
313 <tr>
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>
317 </tr>
318 <tr>
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
322 it.</td>
323 </tr>
324 </table>
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. &nbsp; Use the <tt>TAO_Policy_Manager</tt> in the following way:</p>
330 <table border="1" width="100%" cellpadding="3">
331 <tr>
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&amp; policy_seq = policies.policy_seq ();</pre>
339 </td>
340 </tr>
341 </table>
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">
351 <tr>
352 <td width="100%"><pre>char* props[] = {&quot;Name&quot;, &quot;Description&quot;, &quot;Location&quot;, &quot;Host_Name&quot; };
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>
356 </td>
357 </tr>
358 </table>
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">
372 <tr>
373 <td width="100%"><pre>CORBA::Boolean any_left = CORBA::B_FALSE;
374 CORBA::Environment _env;</pre>
375 <pre>do
377 CosTrading::OfferSeq_ptr iter_offers_ptr;
378 CosTrading::OfferSeq_out iter_offers_out (iter_offers_ptr);
380 any_left = offer_iterator-&gt;next_n (length,
381 iter_offers_out,
382 _env);
383 ACE_CHECK_ENV_RETURN (_env, 0);
385 CosTrading::OfferSeq_var iter_offers (iter_offers_ptr);
386 // Process offers...
388 } while (any_left);</pre>
389 </td>
390 </tr>
391 </table>
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
402 destruction. </p>
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">
408 <tr>
409 <td width="100%"><pre>TAO_Property_Evaluator prop_eval (prop_seq);
410 for (int length = prop_seq.length (), k = 0; k &lt; length; k++)
412 ACE_DEBUG ((LM_DEBUG, &quot;%-15s: &quot;, prop_seq[k].name.in ()));
413 ACE_TRY
415 CORBA::Boolean is_dynamic = prop_eval.is_dynamic_property (k);
416 ACE_CHECK_ENV;
418 value = prop_eval.property_value(k, env);
419 ACE_CHECK_ENV;
421 if (value != 0)
422 CORBA::Any::dump (*value);
424 ACE_CATCHANY
426 ACE_DEBUG ((LM_DEBUG, &quot;Error retrieving property value.\n&quot;));
428 ACE_ENDTRY;
429 }</pre>
430 </td>
431 </tr>
432 </table>
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">
444 <tr>
445 <td width="100%"><pre>CORBA::Object_var trading_obj =
446 orb_ptr-&gt;resolve_initial_references (&quot;TradingService&quot;);
447 CosTrading::Lookup_var lookup_if =
448 CosTrading::Lookup::_narrow (trading_obj.in ());
449 CosTrading::Register_var register_if = lookup_if-&gt;register_if ();
450 CosTrading::TypeRepository_ptr obj = this-&gt;trader_-&gt;type_repos ();
451 CosTradingRepos::ServiceTypeRepository_var str =
452 CosTradingRepos::ServiceTypeRepository::_narrow (obj);
456 // Attempt to export the offer.
457 offer_id = register_id-&gt;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-&gt;add_type (type,
464 object_ref-&gt;_interface_repository_id (),
465 prop_struct_seq,
466 super_type_name_seq);
468 // Now we'll try again to register the offer.
469 offer_id = reg-&gt;export (object_ref, type, this-&gt;tprops_);
471 catch (...)
473 // Sigh, all our efforts were for naught.
474 throw ();
476 </td>
477 </tr>
478 </table>
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">
490 <tr>
491 <td width="100%"><pre>this-&gt;type_structs_[TT_Info::PLOTTER].props.length (2);
492 this-&gt;type_structs_[TT_Info::PLOTTER].super_types.length (1);
493 this-&gt;type_structs_[TT_Info::PLOTTER].super_types[0] =
494 TT_Info::INTERFACE_NAMES[TT_Info::REMOTE_IO];
495 this-&gt;type_structs_[TT_Info::PLOTTER].props[0].name =
496 TT_Info::PLOTTER_PROPERTY_NAMES[TT_Info::PLOTTER_NUM_COLORS];
497 this-&gt;type_structs_[TT_Info::PLOTTER].props[0].value_type =
498 CORBA::TypeCode::_duplicate (CORBA::_tc_long);
499 this-&gt;type_structs_[TT_Info::PLOTTER].props[0].mode =
500 CosTradingRepos::ServiceTypeRepository::PROP_NORMAL;
501 this-&gt;type_structs_[TT_Info::PLOTTER].props[1].name =
502 TT_Info::PLOTTER_PROPERTY_NAMES[TT_Info::PLOTTER_AUTO_LOADING];
503 this-&gt;type_structs_[TT_Info::PLOTTER].props[1].value_type =
504 CORBA::TypeCode::_duplicate (CORBA::_tc_boolean);
505 this-&gt;type_structs_[TT_Info::PLOTTER].props[1].mode =
506 CosTradingRepos::ServiceTypeRepository::PROP_READONLY;</pre>
507 </td>
508 </tr>
509 </table>
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">
519 <tr>
520 <td width="100%"><pre>CosTrading::PropertySeq prop_seq (2);
521 prop_seq[0].name =
522 TT_Info::PLOTTER_PROPERTY_NAMES[TT_Info::PLOTTER_NUM_COLORS];
523 prop_seq[0].value &lt;&lt;= ACE_static_cast (CORBA::Long, 256);
524 prop_seq[1].name =
525 TT_Info::PLOTTER_PROPERTY_NAMES[TT_Info::PLOTTER_AUTO_LOADING];
526 prop_seq[1].value &lt;&lt;= CORBA::Any::from_boolean (CORBA::B_TRUE);</pre>
527 </td>
528 </tr>
529 </table>
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:
542 <ul>
543 <li>inherit from the <tt>TAO_Dynamic_Property</tt> class and implement its <tt>DP_Eval</tt>
544 method; </li>
545 <li>create a <tt>CosTradingDynamic::DynamicProperty</tt> structure using the <tt>TAO_Dynamic_Property::construct_dynamic_prop</tt>
546 method; </li>
547 <li>insert the <tt>CosTradingDynamic::DynamicProperty</tt> in the value field of the
548 property. </li>
549 </ul>
551 <p>The following code, taken from the <tt>export_test</tt> example, illustrates this:</p>
553 <table border="1" width="100%" cellpadding="3">
554 <tr>
555 <td width="100%"><pre>// Step 1: Write the Dynamic Property callback handler.
556 class Simple_DP : public TAO_Dynamic_Property
558 public:
560 virtual CORBA::Any* evalDP (const char* name,
561 CORBA::TypeCode_ptr returned_type,
562 const CORBA::Any&amp; extra_info,
563 CORBA::Environment&amp; _env)
564 ACE_THROW_SPEC ((CosTradingDynamic::DPEvalFailure));
567 CORBA::Any*
568 Simple_DP::evalDP (const char* name,
569 CORBA::TypeCode_ptr returned_type,
570 const CORBA::Any&amp; extra_info,
571 CORBA::Environment&amp; _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) &lt;&lt;= ACE_static_cast (CORBA::ULong, ACE_OS::rand ());
578 return return_value;
579 }</pre>
580 <pre>// Step 2: Create the Dynamic Property
581 Simple_DP dp;
582 CORBA::Any extra_info;
583 CosTrading::PropertySeq prop_seq (1);
584 CosTrading::DynamicProp* dp_struct =
585 dp.construct_dynamic_prop (&quot;prop_name&quot;,
586 CORBA::_tc_ulong,
587 extra_info);</pre>
588 <pre>// Step 3: Turn over the dynamic property to the propery value Any.
589 CORBA::Environment env;
590 prop_seq[0].name = &quot;prop_name&quot;;
591 prop_seq[0].value.replace (CosTrading::_tc_DynamicProp,
592 dp_struct,
593 CORBA::B_TRUE,
594 env);
595 ACE_CHECK_ENV_RETURN (env, -1);</pre>
596 </td>
597 </tr>
598 </table>
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
606 other traders. </p>
608 <p>Adjusting policies is straightforward. Here's an example of setting the <tt>max_search_card</tt>
609 policy:</p>
611 <table border="1" width="100%" cellpadding="3">
612 <tr>
613 <td width="100%"><pre>// lookup_if returned from resolve_initial_references.
614 CosTrading::Admin_var admin_if =
615 lookup_if-&gt;admin_if ();
616 </pre>
617 <pre>admin_if-&gt;set_max_match_card (200);</pre>
618 </td>
619 </tr>
620 </table>
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">
626 <tr>
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-&gt;admin_if ();
636 CosTrading::Register_var register_if =
637 lookup_if-&gt;register_if ();
639 admin_if-&gt;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 &lt; offer_id_seq_var.length (); i++)
648 register_if-&gt;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);
660 any_left =
661 offer_id_iter-&gt;next_n (length,
662 CosTrading::OfferIdSeq_out (id_seq));
664 CORBA::ULong offers = id_seq-&gt;length ();
665 for (CORBA::ULong i = 0; i &lt; offers; i++)
667 register_if-&gt;withdraw (id_seq[i]);
670 delete id_seq;
672 while (any_left);
674 offer_id_iter-&gt;destroy ();
677 catch (...)
679 // Handle Errors.
681 </pre>
682 </td>
683 </tr>
684 </table>
686 <p>Here's an example a trader linking itself to another trader (<tt>this-&gt;trader_</tt>
687 is a colocated trader --- see the next section for more information): </p>
689 <table border="1" width="100%" cellpadding="3">
690 <tr>
691 <td width="100%"><pre>
693 CosTrading::Link_var link_if = lookup_if-&gt;link_if ();
695 TAO_Trading_Components_Impl&amp; trd_comp =
696 this-&gt;trader_-&gt;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-&gt;add_link (this-&gt;name_.in (),
701 our_lookup,
702 CosTrading::always,
703 CosTrading::always);
705 our_link-&gt;add_link (&quot;Bootstrap_Trader&quot;,
706 lookup_if.in (),
707 CosTrading::always,
708 CosTrading::always);
710 catch (...)
712 // Handle Errors.
714 </pre>
715 </td>
716 </tr>
717 </table>
719 <hr>
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">
732 <tr>
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>
738 </tr>
739 <tr>
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">
743 <tr>
744 <td width="18%"><ul>
745 <li><em>query</em></li>
746 </ul>
747 </td>
748 <td width="82%" valign="top" align="left">Instantiates the <tt>Lookup</tt> interface only</td>
749 </tr>
750 <tr>
751 <td width="18%"><ul>
752 <li><em>simple</em></li>
753 </ul>
754 </td>
755 <td width="82%" valign="top" align="left">Instantiates the <tt>Lookup</tt> and <tt>Register</tt>
756 interfaces</td>
757 </tr>
758 <tr>
759 <td width="18%"><ul>
760 <li><em>standalone</em></li>
761 </ul>
762 </td>
763 <td width="82%" valign="top" align="left">Instantiates the <tt>Lookup</tt>, <tt>Register</tt>,
764 and <tt>Admin</tt> interfaces</td>
765 </tr>
766 <tr>
767 <td width="18%"><ul>
768 <li><em>linked</em></li>
769 </ul>
770 </td>
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>
773 </tr>
774 </table>
775 </td>
776 </tr>
777 <tr>
778 <td width="26%"><tt>-TSsupports_dynamic_properties</tt></td>
779 <td width="74%"><table border="0" width="100%" cellpadding="3">
780 <tr>
781 <td width="18%"><ul>
782 <li><em>true</em></li>
783 </ul>
784 </td>
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>
787 </tr>
788 <tr>
789 <td width="18%"><ul>
790 <li><em>false</em></li>
791 </ul>
792 </td>
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>
795 </tr>
796 </table>
797 </td>
798 </tr>
799 <tr>
800 <td width="26%"><tt>-TSsupports_modifiable_properties</tt></td>
801 <td width="74%"><table border="0" width="100%" cellpadding="3">
802 <tr>
803 <td width="18%"><ul>
804 <li><em>true</em></li>
805 </ul>
806 </td>
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>
810 </tr>
811 <tr>
812 <td width="18%"><ul>
813 <li><em>false</em></li>
814 </ul>
815 </td>
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>
818 interface.</td>
819 </tr>
820 </table>
821 </td>
822 </tr>
823 <tr>
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
826 200)</td>
827 </tr>
828 <tr>
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>
831 </tr>
832 <tr>
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>
835 </tr>
836 <tr>
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>
839 </tr>
840 <tr>
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
843 200)</td>
844 </tr>
845 <tr>
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>
848 </tr>
849 <tr>
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.
852 (default 5)</td>
853 </tr>
854 <tr>
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>
858 </tr>
859 <tr>
860 <td width="26%"><tt>-TSdef_follow_policy</tt></td>
861 <td width="74%"><table border="0" width="100%" cellpadding="3">
862 <tr>
863 <td width="18%"><ul>
864 <li><em>always</em></li>
865 </ul>
866 </td>
867 <td width="82%" valign="top" align="left">The trader will always pass a query onto the
868 next available linked trader.</td>
869 </tr>
870 <tr>
871 <td width="18%"><ul>
872 <li><em>if_no_local</em></li>
873 </ul>
874 </td>
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>
877 </tr>
878 <tr>
879 <td width="18%"><ul>
880 <li><em>local_only</em></li>
881 </ul>
882 </td>
883 <td width="82%" valign="top" align="left">The trader will never pass on a query.</td>
884 </tr>
885 </table>
886 </td>
887 </tr>
888 <tr>
889 <td width="26%"><tt>-TSmax_follow_policy</tt></td>
890 <td width="74%"><table border="0" width="100%" cellpadding="3">
891 <tr>
892 <td width="18%"><ul>
893 <li><em>always</em></li>
894 </ul>
895 </td>
896 <td width="82%" valign="top" align="left">The trader doesn't limit the importer to the
897 local offer space. (default)</td>
898 </tr>
899 <tr>
900 <td width="18%"><ul>
901 <li><em>if_no_local</em></li>
902 </ul>
903 </td>
904 <td width="82%" valign="top" align="left">The trader refuses to pass on queries of the
905 local search matched offers.</td>
906 </tr>
907 <tr>
908 <td width="18%"><ul>
909 <li><em>local_only</em></li>
910 </ul>
911 </td>
912 <td width="82%" valign="top" align="left">The trader will never allow federated queries.</td>
913 </tr>
914 </table>
915 </td>
916 </tr>
917 <tr>
918 <td width="26%"><tt>-ORBtradingserviceport</tt></td>
919 <td width="74%">Port on which to listen for multicast bootstrap requests.</td>
920 </tr>
921 <tr>
922 <td width="26%"><tt>-ORBtradingserviceport</tt></td>
923 <td width="74%">Port on which to listen for multicast bootstrap requests.</td>
924 </tr>
925 <tr>
926 <td width="26%"><tt>-TSdumpior</tt></td>
927 <td width="74%">Dumps the trader's IOR to a file (default is stdout).</td>
928 </tr>
929 </table>
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
937 complete graph. </p>
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">
955 <tr>
956 <td width="100%"><pre>TAO_TRADER* trader = TAO_Trader_Factory::create_trader (argc, argv);
957 TAO_Support_Attributes_Impl&amp; sup_attr = trader-&gt;support_attributes ();
958 TAO_Import_Attributes_Impl&amp; imp_attr = trader-&gt;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-&gt;_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>
969 </td>
970 </tr>
971 </table>
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
975 loop. </p>
977 <hr>
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
993 tests directory.</p>
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.&nbsp;&nbsp; </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>
1007 <hr>
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>
1014 <hr>
1016 <h1><a name="FutureWork">Future Work</a></h1>
1018 <ul>
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>
1023 </ul>
1025 <ul>
1026 <li><strong>The <tt>Proxy</tt> Interface </strong>--- Should we ever feel so motivated, we
1027 might implement the <tt>Proxy</tt> interface.&nbsp; </li>
1028 </ul>
1030 <hr>
1032 <address>
1033 <a href="mailto:sbw1@cs.wustl.edu">Seth Benjamin Widoff</a>
1034 </address>
1035 <!-- Created: Mon Jun 29 12:26:36 CDT 1998 -->
1036 <!-- hhmts start -->
1037 </body>
1038 </html>