#include <Trader_Interfaces.h>
Inheritance diagram for TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >:
Public Member Functions | |
TAO_Lookup (TAO_Trader< TRADER_LOCK_TYPE, MAP_LOCK_TYPE > &trader) | |
~TAO_Lookup (void) | |
virtual void | query (const char *type, const char *constr, const char *pref, const CosTrading::PolicySeq &policies, const CosTrading::Lookup::SpecifiedProps &desired_props, CORBA::ULong how_many, CosTrading::OfferSeq_out offers, CosTrading::OfferIterator_out offer_itr, CosTrading::PolicyNameSeq_out limits_applied) throw (CORBA::SystemException, CosTrading::IllegalServiceType, CosTrading::UnknownServiceType, CosTrading::IllegalConstraint, CosTrading::Lookup::IllegalPreference, CosTrading::Lookup::IllegalPolicyName, CosTrading::Lookup::PolicyTypeMismatch, CosTrading::Lookup::InvalidPolicyValue, CosTrading::IllegalPropertyName, CosTrading::DuplicatePropertyName, CosTrading::DuplicatePolicyName) |
Private Types | |
typedef ACE_Unbounded_Queue< CosTrading::Admin::OctetSeq * > | Request_Ids |
Private Member Functions | |
TAO_Offer_Iterator * | create_offer_iterator (const TAO_Property_Filter &) |
void | lookup_all_subtypes (const char *type, CosTradingRepos::ServiceTypeRepository::IncarnationNumber &inc_num, TAO_Offer_Database< MAP_LOCK_TYPE > &offer_database, CosTradingRepos::ServiceTypeRepository_ptr rep, TAO_Constraint_Interpreter &constr_inter, TAO_Preference_Interpreter &pref_inter, TAO_Offer_Filter &offer_filter) |
void | lookup_one_type (const char *type, TAO_Offer_Database< MAP_LOCK_TYPE > &offer_database, TAO_Constraint_Interpreter &constr_inter, TAO_Preference_Interpreter &pref_inter, TAO_Offer_Filter &offer_filter) |
int | fill_receptacles (const char *, CORBA::ULong how_many, const CosTrading::Lookup::SpecifiedProps &desired_props, TAO_Policies &policies, TAO_Preference_Interpreter &pref_inter, CosTrading::OfferSeq &offers, CosTrading::OfferIterator_ptr &offer_itr) throw (CosTrading::IllegalPropertyName, CosTrading::DuplicatePropertyName) |
void | forward_query (const char *next_hop, const char *type, const char *constr, const char *pref, const CosTrading::PolicySeq &policy_seq, const CosTrading::Lookup::SpecifiedProps &desired_props, CORBA::ULong how_many, CosTrading::OfferSeq_out offers, CosTrading::OfferIterator_out offer_itr, CosTrading::PolicyNameSeq_out limits_applied) throw (CORBA::SystemException, CosTrading::IllegalServiceType, CosTrading::UnknownServiceType, CosTrading::IllegalConstraint, CosTrading::Lookup::IllegalPreference, CosTrading::Lookup::IllegalPolicyName, CosTrading::Lookup::PolicyTypeMismatch, CosTrading::Lookup::InvalidPolicyValue, CosTrading::IllegalPropertyName, CosTrading::DuplicatePropertyName, CosTrading::DuplicatePolicyName) |
CORBA::Boolean | retrieve_links (TAO_Policies &policies, CORBA::ULong offer_returned, CosTrading::LinkNameSeq_out links) throw (CORBA::SystemException, CosTrading::Lookup::PolicyTypeMismatch) |
void | federated_query (const CosTrading::LinkNameSeq &links, const TAO_Policies &policies, const CosTrading::Admin::OctetSeq &request_id, TAO_Preference_Interpreter &pref_inter, const char *type, const char *constr, const char *pref, const CosTrading::Lookup::SpecifiedProps &desired_props, CORBA::ULong how_many, CosTrading::OfferSeq &offers, CosTrading::OfferIterator_ptr &offer_itr, CosTrading::PolicyNameSeq &limits_applied) throw (CORBA::SystemException, CosTrading::IllegalServiceType, CosTrading::UnknownServiceType, CosTrading::IllegalConstraint, CosTrading::Lookup::IllegalPreference, CosTrading::Lookup::IllegalPolicyName, CosTrading::Lookup::PolicyTypeMismatch, CosTrading::Lookup::InvalidPolicyValue, CosTrading::IllegalPropertyName, CosTrading::DuplicatePropertyName, CosTrading::DuplicatePolicyName) |
void | order_merged_sequence (TAO_Preference_Interpreter &pref_inter, CosTrading::OfferSeq &offers) |
Merge the results from a federated query into the collected results. | |
CORBA::Boolean | seen_request_id (TAO_Policies &policies, CosTrading::Admin::OctetSeq *&seq) throw (CORBA::SystemException, CosTrading::Lookup::PolicyTypeMismatch) |
void | operator= (const TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE > &) |
TAO_Lookup (const TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE > &) | |
Private Attributes | |
const unsigned int | IDS_SAVED |
TAO_Trader< TRADER_LOCK_TYPE, MAP_LOCK_TYPE > & | trader_ |
A reference to the trader for obtaining offer maps. | |
Request_Ids | request_ids_ |
A list of recent request_id_stems. | |
TRADER_LOCK_TYPE | lock_ |
Lock to secure the set of request ids. |
Definition at line 56 of file Trader_Interfaces.h.
|
Definition at line 299 of file Trader_Interfaces.h. |
|
Definition at line 17 of file Trader_Interfaces.cpp.
00018 : TAO_Trader_Components<POA_CosTrading::Lookup> (trader.trading_components ()), 00019 TAO_Support_Attributes<POA_CosTrading::Lookup> (trader.support_attributes ()), 00020 TAO_Import_Attributes<POA_CosTrading::Lookup> (trader.import_attributes ()), 00021 IDS_SAVED (100), 00022 trader_ (trader) 00023 { 00024 } |
|
Definition at line 27 of file Trader_Interfaces.cpp. References ACE_GUARD.
00028 { 00029 ACE_GUARD (TRADER_LOCK_TYPE, trader_mon, this->lock_); 00030 for (Request_Ids::ITERATOR riter (this->request_ids_); 00031 ! riter.done (); 00032 riter.advance ()) 00033 { 00034 CosTrading::Admin::OctetSeq** old_seq = 0; 00035 riter.next (old_seq); 00036 delete *old_seq; 00037 } 00038 } |
|
|
|
Factory method for creating an appropriate Offer Iterator based on the presence of the Register Interface. Definition at line 464 of file Trader_Interfaces.cpp. References ACE_NEW_RETURN, and CORBA::is_nil().
00465 { 00466 // This is the factory method that creates the appropriate type of 00467 // offer iterator. If there's no Register interface, then we can 00468 // just stick the offers directly into an iterator, since these 00469 // offers will never be removed from the Trader. If there's a 00470 // Register interface, then there's a chance that by the time the 00471 // importer calls the next_n method on the iterator that the offer 00472 // will have been withdrawn. So the Register_Offer_Iterator retains only 00473 // the offer ids, and will recognize when an offer id no longer 00474 // identifies an offer in the trader. 00475 00476 // We pass the property filter to the iterators, so when the iterators 00477 // return the offers, they can remove the undesirable properties 00478 // from those offers. 00479 TAO_Offer_Iterator* iterator = 0; 00480 00481 if (CORBA::is_nil (this->trader_.trading_components ().register_if ())) 00482 ACE_NEW_RETURN (iterator, 00483 TAO_Query_Only_Offer_Iterator (pfilter), 00484 0); 00485 else 00486 ACE_NEW_RETURN (iterator, 00487 TAO_Register_Offer_Iterator<MAP_LOCK_TYPE> (this->trader_.offer_database (), 00488 pfilter), 00489 0); 00490 return iterator; 00491 } |
|
Perform and pass on a query over a set of links. Merge the results of the federated queries into a single set of results suitable for returning to the user. Definition at line 569 of file Trader_Interfaces.cpp. References ACE_CATCHANY, ACE_CHECK, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_NEW, ACE_TRY, ACE_TRY_CHECK, TAO_Offer_Iterator_Collection::add_offer_iterator(), CORBA::is_nil(), CosTrading::LinkNameSeq, CosTrading::OfferSeq, CosTrading::PolicyNameSeq, and CosTrading::PolicySeq.
00593 { 00594 // The general idea here is this: We've assembled a number of links 00595 // to follow, and we'll query each of them in turn. On each query we 00596 // adjust the policies for the new trader by reducing the hop_count, 00597 // changing the link_follow_rule etc..., and merge the results from 00598 // the new query with the results from the previous queries. 00599 00600 // We'll need the link and admin interfaces for this part of the 00601 // federated query. It's ok to get the admin interface without 00602 // checking if it's nil, becase the conformance criteria dictate 00603 // that a trader can't implement the link interface without the 00604 // admin interface. 00605 CosTrading::Link_ptr link_interface 00606 = this->trader_.trading_components ().link_if (); 00607 00608 // Begin collecting all the various offer_iterators into a 00609 // collection. The end result is a distributed tree of offer 00610 // iterators, which if traversed in its entirety is probably hugely 00611 // inefficient, but oh well, I can't think of a better solution. 00612 TAO_Offer_Iterator_Collection* offer_iter_collection = 0; 00613 ACE_NEW (offer_iter_collection, 00614 TAO_Offer_Iterator_Collection); 00615 offer_iter_collection->add_offer_iterator (offer_iter); 00616 00617 CosTrading::PolicySeq policies_to_pass; 00618 policies.copy_to_pass (policies_to_pass, request_id ACE_ENV_ARG_PARAMETER); 00619 ACE_CHECK; 00620 00621 for (int i = links.length () - 1; i >= 0; i--) 00622 { 00623 CosTrading::OfferSeq *out_offers = 0; 00624 CosTrading::OfferIterator *out_offer_iter = 0; 00625 CosTrading::PolicyNameSeq *out_limits = 0; 00626 00627 ACE_TRY 00628 { 00629 // Obtain information about the link we're traversing. 00630 CosTrading::Link::LinkInfo_var link_info = 00631 link_interface->describe_link (links[i] ACE_ENV_ARG_PARAMETER); 00632 ACE_TRY_CHECK; 00633 00634 // Set the link follow policy for the query over the link. 00635 policies.copy_in_follow_option (policies_to_pass, 00636 link_info.in () 00637 ACE_ENV_ARG_PARAMETER); 00638 ACE_TRY_CHECK; 00639 00640 CosTrading::Lookup_var remote_lookup = 00641 CosTrading::Lookup::_duplicate (link_info->target.in ()); 00642 00643 // Perform the federated query. 00644 remote_lookup->query (type, 00645 constr, 00646 pref, 00647 policies_to_pass, 00648 desired_props, 00649 how_many - offers.length (), 00650 CosTrading::OfferSeq_out (out_offers), 00651 CosTrading::OfferIterator_out (out_offer_iter), 00652 CosTrading::PolicyNameSeq_out (out_limits) 00653 ACE_ENV_ARG_PARAMETER); 00654 ACE_TRY_CHECK; 00655 00656 CORBA::ULong j = 0; 00657 CosTrading::OfferSeq_var out_offers_var (out_offers); 00658 CosTrading::PolicyNameSeq_var out_limits_var (out_limits); 00659 00660 // Add another iterator to the collection. 00661 if (! CORBA::is_nil (out_offer_iter)) 00662 offer_iter_collection->add_offer_iterator (out_offer_iter); 00663 00664 // Concatenate the limits applied. 00665 CORBA::ULong source_length = out_limits->length (), 00666 target_length = limits.length (), 00667 total_length = source_length + target_length; 00668 00669 limits.length (total_length); 00670 for (j = 0; j < source_length; j++) 00671 limits[j + target_length] = out_limits_var[j]; 00672 00673 // Concatenate the sequence offers. 00674 source_length = out_offers->length (); 00675 target_length = offers.length (); 00676 total_length = source_length + target_length; 00677 00678 offers.length (total_length); 00679 for (j = 0; j < source_length; j++) 00680 offers[j + target_length] = out_offers_var[j]; 00681 } 00682 ACE_CATCHANY 00683 { 00684 // Ah, well, this query failed, move on to the next one. 00685 } 00686 ACE_ENDTRY; 00687 // ACE_CHECK; 00688 } 00689 00690 // Sort the sequence in preference order. 00691 this->order_merged_sequence (pref_inter, offers); 00692 00693 // Return the collection of offer iterators. 00694 offer_iter = offer_iter_collection->_this (ACE_ENV_SINGLE_ARG_PARAMETER); 00695 ACE_CHECK; 00696 00697 offer_iter_collection->_remove_ref (ACE_ENV_SINGLE_ARG_PARAMETER); 00698 ACE_CHECK; 00699 } |
|
This method takes the list of ordered offers and places a number of them in the sequence of returned offers and the rest into thr iterator. In addition, fill_receptacles uses the TAO_Property_Filter to ensure the returned offers contain the properties specified in the desired_props in parameter. Definition at line 355 of file Trader_Interfaces.cpp. References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, TAO_Offer_Iterator::add_offer(), TAO_Property_Filter::filter_offer(), CosTrading::OfferId, CosTrading::OfferSeq, and CORBA::string_free().
00365 { 00366 // BEGIN SPEC 00367 // The returned offers are passed back in one of two ways (or a 00368 // combination of both). ?The "offers" return result conveys a list 00369 // of offers and the "offer_itr" is a reference to an interface at 00370 // which offers can be obtained. ?The "how_many" parameter states 00371 // how many offers are to be returned via the "offers" result, any 00372 // remaining offers are available via the iterator interface. If the 00373 // "how_many" exceeds the number of offers to be returned, then the 00374 // "offer_itr" will be nil. 00375 // END SPEC 00376 00377 TAO_Property_Filter prop_filter (desired_props ACE_ENV_ARG_PARAMETER); 00378 ACE_CHECK_RETURN (0); 00379 00380 // RETURNING: Calculate how many offers go into the sequence 00381 // Calculate how many go into the iterator 00382 00383 CORBA::ULong return_card = policies.return_card (ACE_ENV_SINGLE_ARG_PARAMETER); 00384 ACE_CHECK_RETURN (0); 00385 00386 CORBA::ULong i = 0; 00387 CORBA::ULong size = static_cast<CORBA::ULong> (pref_inter.num_offers ()); 00388 CORBA::ULong offers_in_sequence = (how_many < size) ? how_many : size; 00389 CORBA::ULong offers_in_iterator = size - offers_in_sequence; 00390 00391 // Ensure the total number of offers returned doesn't exceed return_card. 00392 offers_in_sequence = offers_in_sequence > return_card 00393 ? return_card 00394 : offers_in_sequence; 00395 00396 return_card -= offers_in_sequence; 00397 00398 offers_in_iterator = offers_in_iterator > return_card 00399 ? return_card 00400 : offers_in_iterator; 00401 00402 CORBA::ULong total_offers = offers_in_sequence + offers_in_iterator; 00403 offers.length (offers_in_sequence); 00404 00405 // Add to the sequence, filtering out the undesired properties. 00406 for (i = 0; i < offers_in_sequence; i++) 00407 { 00408 CosTrading::Offer* offer = 0; 00409 CosTrading::OfferId offer_id = 0; 00410 00411 // Pull the next ordered offer out of the preference 00412 // interpreter. 00413 pref_inter.remove_offer (offer, offer_id); 00414 00415 // Filter out the undesired properties. 00416 prop_filter.filter_offer (offer, offers[i]); 00417 CORBA::string_free (offer_id); 00418 } 00419 00420 // Any remaining offers under the return_card go into iterator 00421 if (offers_in_iterator > 0) 00422 { 00423 // Create an iterator implementation 00424 TAO_Offer_Iterator *oi = 00425 this->create_offer_iterator (prop_filter); 00426 00427 // Register it with the POA. 00428 offer_itr = oi->_this (ACE_ENV_SINGLE_ARG_PARAMETER); 00429 ACE_CHECK_RETURN (total_offers - offers_in_iterator); 00430 00431 oi->_remove_ref (ACE_ENV_SINGLE_ARG_PARAMETER); 00432 ACE_CHECK_RETURN (total_offers - offers_in_iterator); 00433 00434 // Add to the iterator 00435 for (i = 0; i < offers_in_iterator; i++) 00436 { 00437 CosTrading::Offer* offer = 0; 00438 CosTrading::OfferId offer_id = 0; 00439 00440 // Pull the next ordered offer out of the preference 00441 // intrerpreter and add it to the offer iterator. 00442 pref_inter.remove_offer (offer, offer_id); 00443 oi->add_offer (offer_id, offer); 00444 } 00445 } 00446 00447 // Clear the preference intrerpreter of superfluous items. 00448 size_t num_offers = pref_inter.num_offers (); 00449 for (size_t j = 0; j < num_offers; j++) 00450 { 00451 CosTrading::Offer* offer = 0; 00452 CosTrading::OfferId offer_id = 0; 00453 00454 pref_inter.remove_offer (offer, offer_id); 00455 CORBA::string_free (offer_id); 00456 } 00457 00458 return total_offers; 00459 } |
|
If a starting_trader policy was specfied, foward the query to the next link in the sequence. Definition at line 741 of file Trader_Interfaces.cpp. References ACE_CATCHANY, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_TRY, ACE_TRY_CHECK, ACE_TRY_THROW, CosTrading::Policy::name, CosTrading::PolicySeq, and CosTrading::Policy::value.
00763 { 00764 // Forward this query to the next link in the starting_trader sequence. 00765 CosTrading::Link_ptr link_interface 00766 = this->trader_.trading_components ().link_if (); 00767 00768 ACE_TRY 00769 { 00770 CosTrading::Link::LinkInfo_var link_info = 00771 link_interface->describe_link (next_hop ACE_ENV_ARG_PARAMETER); 00772 ACE_TRY_CHECK; 00773 00774 CosTrading::Lookup_var remote_lookup = 00775 CosTrading::Lookup::_duplicate (link_info->target.in ()); 00776 00777 CORBA::Object_var us = this->_this (ACE_ENV_SINGLE_ARG_PARAMETER); 00778 ACE_TRY_CHECK; 00779 00780 CORBA::Boolean self_loop = 00781 remote_lookup->_is_equivalent (us.in () ACE_ENV_ARG_PARAMETER); 00782 ACE_TRY_CHECK; 00783 00784 if (! self_loop) 00785 { 00786 // Perform forwarding query. 00787 remote_lookup->query (type, 00788 constr, 00789 pref, 00790 policy_seq, 00791 desired_props, 00792 how_many, 00793 offers, 00794 offer_itr, 00795 limits_applied 00796 ACE_ENV_ARG_PARAMETER); 00797 ACE_TRY_CHECK; 00798 } 00799 else 00800 { 00801 this->query (type, 00802 constr, 00803 pref, 00804 policy_seq, 00805 desired_props, 00806 how_many, 00807 offers, 00808 offer_itr, 00809 limits_applied 00810 ACE_ENV_ARG_PARAMETER); 00811 ACE_TRY_CHECK; 00812 } 00813 } 00814 ACE_CATCHANY 00815 { 00816 CosTrading::Policy policy; 00817 policy.name = TAO_Policies::POLICY_NAMES[TAO_Policies::STARTING_TRADER]; 00818 policy.value <<= next_hop; 00819 ACE_TRY_THROW (CosTrading::Lookup::InvalidPolicyValue (policy)); 00820 } 00821 ACE_ENDTRY; 00822 // ACE_CHECK; 00823 } |
|
Traverse the type hierarchy to pull the matching offers from all subtypes of the root type. Definition at line 285 of file Trader_Interfaces.cpp. References ACE_CHECK, ACE_ENV_ARG_PARAMETER, CosTradingRepos::ServiceTypeRepository::SpecifiedServiceTypes::incarnation, TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::lookup_one_type(), CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq, and ACE_OS::strcmp().
00293 { 00294 // BEGIN SPEC 00295 // The trader may return a service offer of a subtype of the "type" 00296 // requested. Sub-typing of service types is discussed in "Service 00297 // Types" on page 16-4. A service subtype can be described by the 00298 // properties of its supertypes. This ensures that a well-formed query 00299 // for the "type" is also a well-formed query with respect to any 00300 // subtypes. However, if the importer specifies the policy of 00301 // exact_type_match = TRUE, then only offers with the exact (no 00302 // subtype) service type requested are returned. 00303 // END SPEC 00304 00305 CosTradingRepos::ServiceTypeRepository::SpecifiedServiceTypes sst; 00306 CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq_var all_types; 00307 00308 // Optimization: Since a subtype can't have a higher incarnation 00309 // number than a supertype, we don't need to consider those 00310 // types with lower incarnation numbers. 00311 sst.incarnation (inc_num); 00312 00313 all_types = rep->list_types (sst ACE_ENV_ARG_PARAMETER); 00314 ACE_CHECK; 00315 00316 // Scan all types inserted after the super types. If the transitive 00317 // closure of a type's super type relation includes the super type 00318 // being considered, then perform a search on that type. 00319 CORBA::ULong num_types = all_types->length (); 00320 CosTradingRepos::ServiceTypeRepository::TypeStruct_var type_struct; 00321 for (CORBA::ULong i = 0; 00322 i < num_types && offer_filter.ok_to_consider_more (); 00323 i++) 00324 { 00325 // Obtain a description of the prospective type. 00326 type_struct = rep->fully_describe_type (all_types[i] 00327 ACE_ENV_ARG_PARAMETER); 00328 ACE_CHECK; 00329 00330 CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq& 00331 super_types = type_struct->super_types; 00332 CORBA::ULong num_super_types = super_types.length (); 00333 00334 for (CORBA::ULong j = 0; j < num_super_types; j++) 00335 { 00336 if (ACE_OS::strcmp (type_struct->super_types[j], type) == 0) 00337 { 00338 // Egads, a subtype! This type has the type passed 00339 // to query in its list of super_types. 00340 offer_filter.configure_type (type_struct.ptr ()); 00341 this->lookup_one_type (all_types[i], 00342 offer_database, 00343 constr_inter, 00344 pref_inter, 00345 offer_filter); 00346 break; 00347 } 00348 } 00349 } 00350 } |
|
Check if offers of a type fit the constraints and order them according to the preferences submitted. Definition at line 233 of file Trader_Interfaces.cpp. References TAO_Constraint_Interpreter::evaluate(), TAO_Offer_Filter::matched_offer(), CosTrading::OfferId, TAO_Offer_Filter::ok_to_consider(), TAO_Offer_Filter::ok_to_consider_more(), and TAO_Preference_Interpreter::order_offer(). Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::lookup_all_subtypes().
00238 { 00239 // Retrieve an iterator over the offers for a given type. 00240 // @@ Would have used Offer_Database::offer_iterator for less 00241 // coupling between TAO_Lookup and Offer_Database, but g++ barfs on 00242 // that. 00243 #if defined(_MSC_VER) 00244 TAO_Offer_Database<MAP_LOCK_TYPE>::offer_iterator 00245 offer_iter (type, offer_database); 00246 #else 00247 // MSVC won't grok this for some reason, but it's necessary for the 00248 // HP compiler, which seriously requires the typename keyword 00249 // here. I apologize if this ifdef offends some ACE users' 00250 // sensibilities --- it certainly offends mine. 00251 ACE_TYPENAME TAO_Offer_Database<MAP_LOCK_TYPE>::offer_iterator 00252 offer_iter (type, offer_database); 00253 #endif 00254 00255 while (offer_filter.ok_to_consider_more () && 00256 offer_iter.has_more_offers ()) 00257 { 00258 // For each offer in the iterator, attempt to match it with 00259 // the constraints passed to the Query method. If it matches 00260 // the constraint, use the TAO_Preference_Interpreter to 00261 // order the matched offers with respect to the preference 00262 // string passed to the method. All the while the offer 00263 // filter ensures we don't exceed the match cardinality 00264 // constraints. 00265 CosTrading::Offer* offer = offer_iter.get_offer (); 00266 00267 TAO_Trader_Constraint_Evaluator evaluator (offer); 00268 if (offer_filter.ok_to_consider (offer) && 00269 constr_inter.evaluate (evaluator)) 00270 { 00271 // Shove the offer and its id into the preference 00272 // ordering object, pref_inter. 00273 CosTrading::OfferId offer_id = offer_iter.get_id (); 00274 pref_inter.order_offer (evaluator, offer, offer_id); 00275 offer_filter.matched_offer (); 00276 } 00277 00278 offer_iter.next_offer (); 00279 } 00280 } |
|
|
|
Merge the results from a federated query into the collected results.
Definition at line 704 of file Trader_Interfaces.cpp. References CosTrading::OfferSeq, TAO_Preference_Interpreter::order_offer(), and TAO_Preference_Interpreter::remove_offer().
00706 { 00707 CORBA::ULong j = 0; 00708 CORBA::ULong length = offers.length (); 00709 00710 // Grab ownership of the offers already in the target sequence. 00711 CosTrading::Offer* target_buf = offers.get_buffer (1); 00712 00713 // Order the sequence. 00714 for (j = 0; j < length; j++) 00715 pref_inter.order_offer (&target_buf[j]); 00716 //pref_inter.order_offer (&offers[j]); 00717 00718 // Reallocate the sequence. 00719 offers.length (length); 00720 00721 // CosTrading::OfferSeq copy; 00722 // copy.length (length); 00723 00724 // Copy in the ordered offers. 00725 for (j = 0; j < length; j++) 00726 { 00727 CosTrading::Offer* offer = 0; 00728 pref_inter.remove_offer (offer); 00729 //copy[j] = *offer; 00730 offers[j] = *offer; 00731 } 00732 00733 // Release the orphaned memory. 00734 CosTrading::OfferSeq::freebuf (target_buf); 00735 // offers = copy 00736 } |
|
Definition at line 42 of file Trader_Interfaces.cpp. References ACE_CHECK, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_NEW, TAO_Offer_Filter::configure_type(), TAO_Policies::copy_to_forward(), TAO_Policies::exact_type_match(), CORBA::is_nil(), TAO_Offer_Filter::limits_applied(), CosTrading::OfferSeq, CosTrading::PolicyNameSeq, CosTrading::PolicySeq, TAO_Support_Attributes_i::service_type_repos(), TAO_Policies::starting_trader(), and CosTrading::TraderName.
00063 { 00064 // Instantiate a class to help interpret query policies. 00065 TAO_Policies policies (this->trader_, in_policies ACE_ENV_ARG_PARAMETER); 00066 ACE_CHECK; 00067 00068 // If a federated query returns to us, ignore it to prevent 00069 // redundant results and infinite loops. 00070 CosTrading::Admin::OctetSeq* request_id = 0; 00071 int check = this->seen_request_id (policies, request_id ACE_ENV_ARG_PARAMETER); 00072 ACE_CHECK; 00073 00074 if (check) 00075 { 00076 returned_offers = new CosTrading::OfferSeq; 00077 returned_limits_applied = new CosTrading::PolicyNameSeq; 00078 return; 00079 } 00080 00081 // The presence of a link interface determines whether we should 00082 // attempt to forward or propagate queries. 00083 CosTrading::Link_ptr link_if = 00084 this->trader_.trading_components ().link_if (); 00085 00086 // If the importer has specified a starting trader, foward the 00087 // query. 00088 CosTrading::TraderName* trader_name = 00089 policies.starting_trader (ACE_ENV_SINGLE_ARG_PARAMETER); 00090 ACE_CHECK; 00091 00092 if (! CORBA::is_nil (link_if) && trader_name != 0) 00093 { 00094 CosTrading::PolicySeq policies_to_forward; 00095 policies.copy_to_forward (policies_to_forward, *trader_name); 00096 const char* next_hop = (*trader_name)[0]; 00097 this->forward_query (next_hop, 00098 type, 00099 constraint, 00100 preferences, 00101 policies_to_forward, 00102 desired_props, 00103 how_many, 00104 returned_offers, 00105 returned_offer_iterator, 00106 returned_limits_applied 00107 ACE_ENV_ARG_PARAMETER); 00108 ACE_CHECK; 00109 return; 00110 } 00111 00112 // Retrieve the type description struct from the Service Type Repos. 00113 const TAO_Support_Attributes_i& support_attrs = 00114 this->trader_.support_attributes (); 00115 CosTradingRepos::ServiceTypeRepository_ptr rep = 00116 support_attrs.service_type_repos (); 00117 CosTradingRepos::ServiceTypeRepository::TypeStruct_var type_struct = 00118 rep->fully_describe_type (type ACE_ENV_ARG_PARAMETER); 00119 ACE_CHECK; 00120 00121 // @@ Should throw a NO_MEMORY exception here... 00122 ACE_NEW (returned_offers, 00123 CosTrading::OfferSeq); 00124 00125 // Obtain a reference to the offer database. 00126 TAO_Offer_Database<MAP_LOCK_TYPE>& offer_database = 00127 this->trader_.offer_database (); 00128 00129 // TAO_Offer_Filter -- ensures that we don't consider offers with 00130 // modifiable or dynamic properties if the Trader doesn't support 00131 // them, or the importer has turned them off using policies. 00132 // TAO_Constraint_Validator -- validates the constraint with the 00133 // property types in the supplied type. TAO_Constraint_Interpreter 00134 // -- parses the constraint string, and determines whether an offer 00135 // meets those constraints. TAO_Preference_Interpreter -- parses 00136 // the preference string and orders offers according to those 00137 // constraints. 00138 TAO_Offer_Filter offer_filter (policies 00139 ACE_ENV_ARG_PARAMETER); 00140 ACE_CHECK; 00141 TAO_Trader_Constraint_Validator validator (type_struct.in ()); 00142 TAO_Constraint_Interpreter constr_inter (validator, 00143 constraint 00144 ACE_ENV_ARG_PARAMETER); 00145 ACE_CHECK; 00146 TAO_Preference_Interpreter pref_inter (validator, 00147 preferences 00148 ACE_ENV_ARG_PARAMETER); 00149 ACE_CHECK; 00150 00151 // Try to find the map of offers of desired service type. 00152 offer_filter.configure_type (type_struct.ptr ()); 00153 this->lookup_one_type (type, 00154 offer_database, 00155 constr_inter, 00156 pref_inter, 00157 offer_filter); 00158 00159 CORBA::Boolean result = policies.exact_type_match (ACE_ENV_SINGLE_ARG_PARAMETER); 00160 ACE_CHECK; 00161 00162 if (!result) 00163 { 00164 // If the importer hasn't demanded an exact match search, we 00165 // search all the subtypes of the supplied type. NOTE: Only the 00166 // properties belonging to the provided type are considered on 00167 // subtypes. Additional properties on the subtype are generally 00168 // ignored. This is as it should be, consistent with the notions 00169 // of type inheritence. 00170 this->lookup_all_subtypes (type, 00171 type_struct->incarnation, 00172 offer_database, 00173 rep, 00174 constr_inter, 00175 pref_inter, 00176 offer_filter 00177 ACE_ENV_ARG_PARAMETER); 00178 ACE_CHECK; 00179 } 00180 00181 // Take note of the limits applied in this query. 00182 returned_limits_applied = offer_filter.limits_applied (); 00183 00184 // Fill the return sequence and iterator with the bountiful results. 00185 CORBA::ULong offers_returned = 00186 this->fill_receptacles (type, 00187 how_many, 00188 desired_props, 00189 policies, 00190 pref_inter, 00191 *returned_offers.ptr (), 00192 returned_offer_iterator 00193 ACE_ENV_ARG_PARAMETER); 00194 ACE_CHECK; 00195 00196 // The following steps are only appropriate for a linked trader. 00197 if (! CORBA::is_nil (link_if)) 00198 { 00199 // Determine if we should perform a federated query, and if so 00200 // construct a sequence of links to follow. 00201 CosTrading::LinkNameSeq_var links; 00202 CORBA::Boolean should_follow = 00203 this->retrieve_links (policies, 00204 offers_returned, 00205 CosTrading::LinkNameSeq_out (links.out ()) 00206 ACE_ENV_ARG_PARAMETER); 00207 ACE_CHECK; 00208 00209 if (should_follow && links->length () != 0) 00210 { 00211 // Query those links we've accumulated! 00212 this->federated_query (links.in (), 00213 policies, 00214 *request_id, 00215 pref_inter, 00216 type, 00217 constraint, 00218 preferences, 00219 desired_props, 00220 how_many, 00221 *returned_offers.ptr (), 00222 returned_offer_iterator.ptr (), 00223 *returned_limits_applied.ptr () 00224 ACE_ENV_ARG_PARAMETER); 00225 ACE_CHECK; 00226 } 00227 } 00228 } |
|
Assemble a sequence of links that the federate_query method should follow. Use the starting_trader policy, if one's provided, otherwise use the Link interface to determine which of the registered links should be followed in this query. Definition at line 496 of file Trader_Interfaces.cpp. References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, and ACE_ENV_SINGLE_ARG_PARAMETER.
00502 { 00503 CORBA::Boolean should_follow = 0; 00504 CosTrading::FollowOption follow_rule = policies.link_follow_rule (ACE_ENV_SINGLE_ARG_PARAMETER); 00505 ACE_CHECK_RETURN (should_follow); 00506 00507 // Determine whether or not a federated query is warranted. A query 00508 // is waranted if the follow_rule governing this query is 'always' 00509 // or if_no_local and the local query returned nothing. 00510 if ((follow_rule == CosTrading::always || 00511 (follow_rule == CosTrading::if_no_local && offers_returned == 0))) 00512 { 00513 CORBA::ULong hc = policies.hop_count (ACE_ENV_SINGLE_ARG_PARAMETER); 00514 ACE_CHECK_RETURN (0); 00515 00516 if (hc > 0) 00517 should_follow = 1; 00518 } 00519 00520 if (should_follow) 00521 { 00522 // Grab the names of all the links in the trader, and push 00523 // the suitable ones onto <valid_links>. 00524 CosTrading::Link_ptr link_if = 00525 this->trader_.trading_components ().link_if (); 00526 00527 links = link_if->list_links (ACE_ENV_SINGLE_ARG_PARAMETER); 00528 ACE_CHECK_RETURN (0); 00529 00530 // Determine which of the links registered with the Link 00531 // interface are suitable to follow. 00532 CORBA::ULong i = 0, j = 0, 00533 length = links->length (); 00534 00535 for (i = 0; i < length; i++) 00536 { 00537 // Grab the link information. 00538 CosTrading::Link::LinkInfo_var 00539 link_info (link_if->describe_link (links[i] ACE_ENV_ARG_PARAMETER)); 00540 ACE_CHECK_RETURN (should_follow); 00541 00542 // Compute the link follow rule. 00543 CosTrading::FollowOption link_rule = 00544 policies.link_follow_rule (link_info.in () ACE_ENV_ARG_PARAMETER); 00545 ACE_CHECK_RETURN (should_follow); 00546 00547 // Determine if the link follow rule applies. 00548 if (link_rule == CosTrading::always 00549 || (link_rule == CosTrading::if_no_local 00550 && offers_returned == 0)) 00551 { 00552 // Add the link to the list of links to follow. 00553 if (i > j) 00554 links[j] = links[i]; 00555 00556 j++; 00557 } 00558 } 00559 00560 links->length (j); 00561 } 00562 00563 return should_follow; 00564 } |
|
Definition at line 828 of file Trader_Interfaces.cpp. References ACE_CHECK_RETURN, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_GUARD_RETURN, and ACE_NEW_THROW_EX.
00833 { 00834 CORBA::Boolean return_value = 0; 00835 00836 seq = policies.request_id (ACE_ENV_SINGLE_ARG_PARAMETER); 00837 ACE_CHECK_RETURN (1); 00838 00839 if (seq == 0) 00840 { 00841 CosTrading::Admin_ptr admin_if = 00842 this->trader_.trading_components ().admin_if (); 00843 seq = admin_if->request_id_stem (ACE_ENV_SINGLE_ARG_PARAMETER); 00844 ACE_CHECK_RETURN (1); 00845 } 00846 else 00847 { 00848 // Allocate memory so memory mangement is the same for both 00849 // cases. 00850 ACE_NEW_THROW_EX (seq, 00851 CosTrading::Admin::OctetSeq (*seq), 00852 CORBA::NO_MEMORY ()); 00853 ACE_CHECK_RETURN (1); 00854 } 00855 00856 ACE_GUARD_RETURN (TRADER_LOCK_TYPE, trader_mon, this->lock_, 1); 00857 00858 for (Request_Ids::ITERATOR riter (this->request_ids_); 00859 ! riter.done (); 00860 riter.advance ()) 00861 { 00862 CosTrading::Admin::OctetSeq** old_seq = 0; 00863 riter.next (old_seq); 00864 00865 if (**old_seq == *seq) 00866 { 00867 return_value = 1; 00868 break; 00869 } 00870 } 00871 00872 if (return_value == 0) 00873 { 00874 if (this->request_ids_.size () == IDS_SAVED) 00875 { 00876 CosTrading::Admin::OctetSeq* octet_seq = 0; 00877 this->request_ids_.dequeue_head (octet_seq); 00878 delete octet_seq; 00879 } 00880 00881 this->request_ids_.enqueue_tail (seq); 00882 } 00883 00884 return return_value; 00885 } |
|
Definition at line 294 of file Trader_Interfaces.h. |
|
Lock to secure the set of request ids.
Definition at line 305 of file Trader_Interfaces.h. |
|
A list of recent request_id_stems.
Definition at line 302 of file Trader_Interfaces.h. |
|
A reference to the trader for obtaining offer maps.
Definition at line 297 of file Trader_Interfaces.h. |