TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE > Class Template Reference

This class implements CosTrading::Lookup IDL interface. More...

#include <Trader_Interfaces.h>

Inheritance diagram for TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >:

Inheritance graph
[legend]
Collaboration diagram for TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >:

Collaboration graph
[legend]
List of all members.

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)

Private Types

typedef ACE_Unbounded_Queue<
CosTrading::Admin::OctetSeq * > 
Request_Ids

Private Member Functions

TAO_Offer_Iteratorcreate_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)
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)
CORBA::Boolean retrieve_links (TAO_Policies &policies, CORBA::ULong offer_returned, CosTrading::LinkNameSeq_out links)
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)
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)
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.

Detailed Description

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
class TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >

This class implements CosTrading::Lookup IDL interface.

Definition at line 56 of file Trader_Interfaces.h.


Member Typedef Documentation

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
typedef ACE_Unbounded_Queue<CosTrading::Admin::OctetSeq*> TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::Request_Ids [private]

Definition at line 253 of file Trader_Interfaces.h.


Constructor & Destructor Documentation

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::TAO_Lookup ( TAO_Trader< TRADER_LOCK_TYPE, MAP_LOCK_TYPE > &  trader  ) 

Definition at line 17 of file Trader_Interfaces.cpp.

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::~TAO_Lookup ( void   ) 

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 }

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::TAO_Lookup ( const TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE > &   )  [private]


Member Function Documentation

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
TAO_Offer_Iterator * TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::create_offer_iterator ( const TAO_Property_Filter  )  [private]

Factory method for creating an appropriate Offer Iterator based on the presence of the Register Interface.

Definition at line 420 of file Trader_Interfaces.cpp.

References ACE_NEW_RETURN, and CORBA::is_nil().

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::fill_receptacles().

00421 {
00422   // This is the factory method that creates the appropriate type of
00423   // offer iterator. If there's no Register interface, then we can
00424   // just stick the offers directly into an iterator, since these
00425   // offers will never be removed from the Trader. If there's a
00426   // Register interface, then there's a chance that by the time the
00427   // importer calls the next_n method on the iterator that the offer
00428   // will have been withdrawn. So the Register_Offer_Iterator retains only
00429   // the offer ids, and will recognize when an offer id no longer
00430   // identifies an offer in the trader.
00431 
00432   // We pass the property filter to the iterators, so when the iterators
00433   // return the offers, they can remove the undesirable properties
00434   // from those offers.
00435   TAO_Offer_Iterator* iterator = 0;
00436 
00437   if (CORBA::is_nil (this->trader_.trading_components ().register_if ()))
00438     ACE_NEW_RETURN (iterator,
00439                     TAO_Query_Only_Offer_Iterator (pfilter),
00440                     0);
00441   else
00442     ACE_NEW_RETURN (iterator,
00443                     TAO_Register_Offer_Iterator<MAP_LOCK_TYPE> (this->trader_.offer_database (),
00444                                                                 pfilter),
00445                     0);
00446   return iterator;
00447 }

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
void TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::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 
) [private]

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 517 of file Trader_Interfaces.cpp.

References ACE_NEW, TAO_Offer_Iterator_Collection::add_offer_iterator(), TAO_Policies::copy_in_follow_option(), TAO_Policies::copy_to_pass(), CORBA::is_nil(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::order_merged_sequence(), and TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::trader_.

00529 {
00530   // The general idea here is this: We've assembled a number of links
00531   // to follow, and we'll query each of them in turn. On each query we
00532   // adjust the policies for the new trader by reducing the hop_count,
00533   // changing the link_follow_rule etc..., and merge the results from
00534   // the new query with the results from the previous queries.
00535 
00536   // We'll need the link and admin interfaces for this part of the
00537   // federated query. It's ok to get the admin interface without
00538   // checking if it's nil, becase the conformance criteria dictate
00539   // that a trader can't implement the link interface without the
00540   // admin interface.
00541   CosTrading::Link_ptr link_interface
00542     = this->trader_.trading_components ().link_if ();
00543 
00544   // Begin collecting all the various offer_iterators into a
00545   // collection. The end result is a distributed tree of offer
00546   // iterators, which if traversed in its entirety is probably hugely
00547   // inefficient, but oh well, I can't think of a better solution.
00548   TAO_Offer_Iterator_Collection* offer_iter_collection = 0;
00549   ACE_NEW (offer_iter_collection,
00550            TAO_Offer_Iterator_Collection);
00551   offer_iter_collection->add_offer_iterator (offer_iter);
00552 
00553   CosTrading::PolicySeq policies_to_pass;
00554   policies.copy_to_pass (policies_to_pass, request_id);
00555 
00556   for (int i = links.length () - 1; i >= 0; i--)
00557     {
00558       CosTrading::OfferSeq *out_offers = 0;
00559       CosTrading::OfferIterator *out_offer_iter = 0;
00560       CosTrading::PolicyNameSeq *out_limits = 0;
00561 
00562       try
00563         {
00564           // Obtain information about the link we're traversing.
00565           CosTrading::Link::LinkInfo_var link_info =
00566             link_interface->describe_link (links[i]);
00567 
00568           // Set the link follow policy for the query over the link.
00569           policies.copy_in_follow_option (policies_to_pass,
00570                                           link_info.in ());
00571 
00572           CosTrading::Lookup_var remote_lookup =
00573             CosTrading::Lookup::_duplicate (link_info->target.in ());
00574 
00575           // Perform the federated query.
00576           remote_lookup->query (type,
00577                                 constr,
00578                                 pref,
00579                                 policies_to_pass,
00580                                 desired_props,
00581                                 how_many - offers.length (),
00582                                 CosTrading::OfferSeq_out (out_offers),
00583                                 CosTrading::OfferIterator_out (out_offer_iter),
00584                                 CosTrading::PolicyNameSeq_out (out_limits));
00585 
00586           CORBA::ULong j = 0;
00587           CosTrading::OfferSeq_var out_offers_var (out_offers);
00588           CosTrading::PolicyNameSeq_var out_limits_var (out_limits);
00589 
00590           // Add another iterator to the collection.
00591           if (! CORBA::is_nil (out_offer_iter))
00592             offer_iter_collection->add_offer_iterator (out_offer_iter);
00593 
00594           // Concatenate the limits applied.
00595           CORBA::ULong source_length = out_limits->length (),
00596             target_length = limits.length (),
00597             total_length = source_length + target_length;
00598 
00599           limits.length (total_length);
00600           for (j = 0; j < source_length; j++)
00601             limits[j + target_length] = out_limits_var[j];
00602 
00603           // Concatenate the sequence offers.
00604           source_length = out_offers->length ();
00605           target_length = offers.length ();
00606           total_length = source_length + target_length;
00607 
00608           offers.length (total_length);
00609           for (j = 0; j < source_length; j++)
00610             offers[j + target_length] = out_offers_var[j];
00611         }
00612       catch (const CORBA::Exception&)
00613         {
00614           // Ah, well, this query failed, move on to the next one.
00615         }
00616     }
00617 
00618   // Sort the sequence in preference order.
00619   this->order_merged_sequence (pref_inter, offers);
00620 
00621   // Return the collection of offer iterators.
00622   offer_iter = offer_iter_collection->_this ();
00623 
00624   offer_iter_collection->_remove_ref ();
00625 }

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
int TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::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 
) [private]

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 318 of file Trader_Interfaces.cpp.

References TAO_Offer_Iterator::add_offer(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::create_offer_iterator(), TAO_Property_Filter::filter_offer(), TAO_Preference_Interpreter::num_offers(), TAO_Preference_Interpreter::remove_offer(), TAO_Policies::return_card(), size, and CORBA::string_free().

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::query().

00325 {
00326   // BEGIN SPEC
00327   // The returned offers are passed back in one of two ways (or a
00328   // combination of both). ?The "offers" return result conveys a list
00329   // of offers and the "offer_itr" is a reference to an interface at
00330   // which offers can be obtained. ?The "how_many" parameter states
00331   // how many offers are to be returned via the "offers" result, any
00332   // remaining offers are available via the iterator interface. If the
00333   // "how_many" exceeds the number of offers to be returned, then the
00334   // "offer_itr" will be nil.
00335   // END SPEC
00336 
00337   TAO_Property_Filter prop_filter (desired_props);
00338 
00339   // RETURNING: Calculate how many offers go into the sequence
00340   //  Calculate how many go into the iterator
00341 
00342   CORBA::ULong return_card = policies.return_card ();
00343 
00344   CORBA::ULong i = 0;
00345   CORBA::ULong size = static_cast<CORBA::ULong> (pref_inter.num_offers ());
00346   CORBA::ULong offers_in_sequence = (how_many < size) ? how_many : size;
00347   CORBA::ULong offers_in_iterator = size - offers_in_sequence;
00348 
00349   // Ensure the total number of offers returned doesn't exceed return_card.
00350   offers_in_sequence = offers_in_sequence > return_card
00351     ? return_card
00352     : offers_in_sequence;
00353 
00354   return_card -= offers_in_sequence;
00355 
00356   offers_in_iterator = offers_in_iterator > return_card
00357     ? return_card
00358     : offers_in_iterator;
00359 
00360   CORBA::ULong total_offers = offers_in_sequence + offers_in_iterator;
00361   offers.length (offers_in_sequence);
00362 
00363   // Add to the sequence, filtering out the undesired properties.
00364   for (i = 0; i < offers_in_sequence; i++)
00365     {
00366       CosTrading::Offer* offer = 0;
00367       CosTrading::OfferId offer_id = 0;
00368 
00369       // Pull the next ordered offer out of the preference
00370       // interpreter.
00371       pref_inter.remove_offer (offer, offer_id);
00372 
00373       // Filter out the undesired properties.
00374       prop_filter.filter_offer (offer, offers[i]);
00375       CORBA::string_free (offer_id);
00376     }
00377 
00378   // Any remaining offers under the return_card go into iterator
00379   if (offers_in_iterator > 0)
00380     {
00381       // Create an iterator implementation
00382       TAO_Offer_Iterator *oi =
00383         this->create_offer_iterator (prop_filter);
00384 
00385       // Register it with the POA.
00386       offer_itr = oi->_this ();
00387 
00388       oi->_remove_ref ();
00389 
00390       // Add to the iterator
00391       for (i = 0; i < offers_in_iterator; i++)
00392         {
00393           CosTrading::Offer* offer = 0;
00394           CosTrading::OfferId offer_id = 0;
00395 
00396           // Pull the next ordered offer out of the preference
00397           // intrerpreter and add it to the offer iterator.
00398           pref_inter.remove_offer (offer, offer_id);
00399           oi->add_offer (offer_id, offer);
00400         }
00401     }
00402 
00403   // Clear the preference intrerpreter of superfluous items.
00404   size_t num_offers = pref_inter.num_offers ();
00405   for (size_t j = 0; j < num_offers; j++)
00406     {
00407       CosTrading::Offer* offer = 0;
00408       CosTrading::OfferId offer_id = 0;
00409 
00410       pref_inter.remove_offer (offer, offer_id);
00411       CORBA::string_free (offer_id);
00412     }
00413 
00414   return total_offers;
00415 }

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
void TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::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 
) [private]

If a starting_trader policy was specfied, foward the query to the next link in the sequence.

Definition at line 667 of file Trader_Interfaces.cpp.

References CosTrading::Policy::name, TAO_Policies::POLICY_NAMES, TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::query(), TAO_Policies::STARTING_TRADER, TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::trader_, and CosTrading::Policy::value.

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::query().

00677 {
00678   // Forward this query to the next link in the starting_trader sequence.
00679   CosTrading::Link_ptr link_interface
00680     = this->trader_.trading_components ().link_if ();
00681 
00682   try
00683     {
00684       CosTrading::Link::LinkInfo_var link_info =
00685         link_interface->describe_link (next_hop);
00686 
00687       CosTrading::Lookup_var remote_lookup =
00688         CosTrading::Lookup::_duplicate (link_info->target.in ());
00689 
00690       CORBA::Object_var us = this->_this ();
00691 
00692       CORBA::Boolean self_loop =
00693         remote_lookup->_is_equivalent (us.in ());
00694 
00695       if (! self_loop)
00696         {
00697           // Perform forwarding query.
00698           remote_lookup->query (type,
00699                                 constr,
00700                                 pref,
00701                                 policy_seq,
00702                                 desired_props,
00703                                 how_many,
00704                                 offers,
00705                                 offer_itr,
00706                                 limits_applied);
00707         }
00708       else
00709         {
00710           this->query (type,
00711                        constr,
00712                        pref,
00713                        policy_seq,
00714                        desired_props,
00715                        how_many,
00716                        offers,
00717                        offer_itr,
00718                        limits_applied);
00719         }
00720     }
00721   catch (const CORBA::Exception&)
00722     {
00723       CosTrading::Policy policy;
00724       policy.name = TAO_Policies::POLICY_NAMES[TAO_Policies::STARTING_TRADER];
00725       policy.value <<= next_hop;
00726       throw CosTrading::Lookup::InvalidPolicyValue (policy);
00727     }
00728 }

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
void TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::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 
) [private]

Traverse the type hierarchy to pull the matching offers from all subtypes of the root type.

Definition at line 252 of file Trader_Interfaces.cpp.

References TAO_Offer_Filter::configure_type(), CosTradingRepos::ServiceTypeRepository::SpecifiedServiceTypes::incarnation, TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::lookup_one_type(), TAO_Offer_Filter::ok_to_consider_more(), and ACE_OS::strcmp().

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::query().

00259 {
00260   // BEGIN SPEC
00261   // The trader may return a service offer of a subtype of the "type"
00262   // requested. Sub-typing of service types is discussed in "Service
00263   // Types" on page 16-4. A service subtype can be described by the
00264   // properties of its supertypes. This ensures that a well-formed query
00265   // for the "type" is also a well-formed query with respect to any
00266   // subtypes. However, if the importer specifies the policy of
00267   // exact_type_match = TRUE, then only offers with the exact (no
00268   // subtype) service type requested are returned.
00269   // END SPEC
00270 
00271   CosTradingRepos::ServiceTypeRepository::SpecifiedServiceTypes sst;
00272   CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq_var all_types;
00273 
00274   // Optimization: Since a subtype can't have a higher incarnation
00275   // number than a supertype, we don't need to consider those
00276   // types with lower incarnation numbers.
00277   sst.incarnation (inc_num);
00278 
00279   all_types = rep->list_types (sst);
00280 
00281   // Scan all types inserted after the super types. If the transitive
00282   // closure of a type's super type relation includes the super type
00283   // being considered, then perform a search on that type.
00284   CORBA::ULong num_types = all_types->length ();
00285   CosTradingRepos::ServiceTypeRepository::TypeStruct_var type_struct;
00286   for (CORBA::ULong i = 0;
00287        i < num_types && offer_filter.ok_to_consider_more ();
00288        i++)
00289     {
00290       // Obtain a description of the prospective type.
00291       type_struct = rep->fully_describe_type (all_types[i]);
00292 
00293       CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq&
00294         super_types = type_struct->super_types;
00295       CORBA::ULong num_super_types = super_types.length ();
00296 
00297       for (CORBA::ULong j = 0; j < num_super_types; j++)
00298         {
00299           if (ACE_OS::strcmp (type_struct->super_types[j], type) == 0)
00300             {
00301               // Egads, a subtype! This type has the type passed
00302               // to query in its list of super_types.
00303               offer_filter.configure_type (type_struct.ptr ());
00304               this->lookup_one_type (all_types[i],
00305                                      offer_database,
00306                                      constr_inter,
00307                                      pref_inter,
00308                                      offer_filter);
00309               break;
00310             }
00311         }
00312     }
00313 }

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
void TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::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 
) [private]

Check if offers of a type fit the constraints and order them according to the preferences submitted.

Definition at line 200 of file Trader_Interfaces.cpp.

References TAO_Constraint_Interpreter::evaluate(), TAO_Offer_Filter::matched_offer(), 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(), and TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::query().

00205 {
00206   // Retrieve an iterator over the offers for a given type.
00207   // @@ Would have used Offer_Database::offer_iterator for less
00208   // coupling between TAO_Lookup and Offer_Database, but g++ barfs on
00209   // that.
00210 #if defined(_MSC_VER)
00211   TAO_Offer_Database<MAP_LOCK_TYPE>::offer_iterator
00212     offer_iter (type, offer_database);
00213 #else
00214   // MSVC won't grok this for some reason, but it's necessary for the
00215   // HP compiler, which seriously requires the typename keyword
00216   // here. I apologize if this ifdef offends some ACE users'
00217   // sensibilities --- it certainly offends mine.
00218   typename TAO_Offer_Database<MAP_LOCK_TYPE>::offer_iterator
00219     offer_iter (type, offer_database);
00220 #endif
00221 
00222   while (offer_filter.ok_to_consider_more () &&
00223          offer_iter.has_more_offers ())
00224     {
00225       // For each offer in the iterator, attempt to match it with
00226       // the constraints passed to the Query method. If it matches
00227       // the constraint, use the TAO_Preference_Interpreter to
00228       // order the matched offers with respect to the preference
00229       // string passed to the method. All the while the offer
00230       // filter ensures we don't exceed the match cardinality
00231       // constraints.
00232       CosTrading::Offer* offer = offer_iter.get_offer ();
00233 
00234       TAO_Trader_Constraint_Evaluator evaluator (offer);
00235       if (offer_filter.ok_to_consider (offer) &&
00236           constr_inter.evaluate (evaluator))
00237         {
00238           // Shove the offer and its id into the preference
00239           // ordering object, pref_inter.
00240           CosTrading::OfferId offer_id = offer_iter.get_id ();
00241           pref_inter.order_offer (evaluator, offer, offer_id);
00242           offer_filter.matched_offer ();
00243         }
00244 
00245       offer_iter.next_offer ();
00246     }
00247 }

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
void TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::operator= ( const TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE > &   )  [private]

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
void TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::order_merged_sequence ( TAO_Preference_Interpreter pref_inter,
CosTrading::OfferSeq offers 
) [private]

Merge the results from a federated query into the collected results.

Definition at line 630 of file Trader_Interfaces.cpp.

References TAO_Preference_Interpreter::order_offer(), and TAO_Preference_Interpreter::remove_offer().

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::federated_query().

00632 {
00633   CORBA::ULong j = 0;
00634   CORBA::ULong length = offers.length ();
00635 
00636   // Grab ownership of the offers already in the target sequence.
00637   CosTrading::Offer* target_buf = offers.get_buffer (1);
00638 
00639   // Order the sequence.
00640   for (j = 0; j < length; j++)
00641     pref_inter.order_offer (&target_buf[j]);
00642   //pref_inter.order_offer (&offers[j]);
00643 
00644   // Reallocate the sequence.
00645   offers.length (length);
00646 
00647   //  CosTrading::OfferSeq copy;
00648   //  copy.length (length);
00649 
00650   // Copy in the ordered offers.
00651   for (j = 0; j < length; j++)
00652     {
00653       CosTrading::Offer* offer = 0;
00654       pref_inter.remove_offer (offer);
00655       //copy[j] = *offer;
00656       offers[j] = *offer;
00657     }
00658 
00659   // Release the orphaned memory.
00660   CosTrading::OfferSeq::freebuf (target_buf);
00661   //  offers = copy
00662 }

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
void TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::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 
) [virtual]

Definition at line 42 of file Trader_Interfaces.cpp.

References ACE_NEW, TAO_Offer_Filter::configure_type(), TAO_Policies::copy_to_forward(), TAO_Policies::exact_type_match(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::fill_receptacles(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::forward_query(), CORBA::is_nil(), TAO_Offer_Filter::limits_applied(), TAO_Trader_Components< POA_CosTrading::Lookup >::link_if(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::lookup_all_subtypes(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::lookup_one_type(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::retrieve_links(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::seen_request_id(), TAO_Support_Attributes_i::service_type_repos(), TAO_Policies::starting_trader(), and TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::trader_.

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::forward_query().

00051 {
00052   // Instantiate a class to help interpret query policies.
00053   TAO_Policies policies (this->trader_, in_policies);
00054 
00055   // If a federated query returns to us, ignore it to prevent
00056   // redundant results and infinite loops.
00057   CosTrading::Admin::OctetSeq* request_id = 0;
00058   int check = this->seen_request_id (policies, request_id);
00059 
00060   if (check)
00061     {
00062       returned_offers = new CosTrading::OfferSeq;
00063       returned_limits_applied = new CosTrading::PolicyNameSeq;
00064       return;
00065     }
00066 
00067   // The presence of a link interface determines whether we should
00068   // attempt to forward or propagate queries.
00069   CosTrading::Link_ptr link_if =
00070     this->trader_.trading_components ().link_if ();
00071 
00072   // If the importer has specified a starting trader, foward the
00073   // query.
00074   CosTrading::TraderName* trader_name =
00075     policies.starting_trader ();
00076 
00077   if (! CORBA::is_nil (link_if) && trader_name != 0)
00078     {
00079       CosTrading::PolicySeq policies_to_forward;
00080       policies.copy_to_forward (policies_to_forward, *trader_name);
00081       const char* next_hop = (*trader_name)[0];
00082       this->forward_query (next_hop,
00083                            type,
00084                            constraint,
00085                            preferences,
00086                            policies_to_forward,
00087                            desired_props,
00088                            how_many,
00089                            returned_offers,
00090                            returned_offer_iterator,
00091                            returned_limits_applied);
00092       return;
00093     }
00094 
00095   // Retrieve the type description struct from the Service Type Repos.
00096   const TAO_Support_Attributes_i& support_attrs =
00097     this->trader_.support_attributes ();
00098   CosTradingRepos::ServiceTypeRepository_ptr rep =
00099     support_attrs.service_type_repos ();
00100   CosTradingRepos::ServiceTypeRepository::TypeStruct_var type_struct =
00101     rep->fully_describe_type (type);
00102 
00103   // @@ Should throw a NO_MEMORY exception here...
00104   ACE_NEW (returned_offers,
00105            CosTrading::OfferSeq);
00106 
00107   // Obtain a reference to the offer database.
00108   TAO_Offer_Database<MAP_LOCK_TYPE>& offer_database =
00109     this->trader_.offer_database ();
00110 
00111   // TAO_Offer_Filter -- ensures that we don't consider offers with
00112   // modifiable or dynamic properties if the Trader doesn't support
00113   // them, or the importer has turned them off using policies.
00114   // TAO_Constraint_Validator -- validates the constraint with the
00115   // property types in the supplied type.  TAO_Constraint_Interpreter
00116   // -- parses the constraint string, and determines whether an offer
00117   // meets those constraints.  TAO_Preference_Interpreter -- parses
00118   // the preference string and orders offers according to those
00119   // constraints.
00120   TAO_Offer_Filter offer_filter (policies);
00121   TAO_Trader_Constraint_Validator validator (type_struct.in ());
00122   TAO_Constraint_Interpreter constr_inter (validator,
00123                                            constraint);
00124   TAO_Preference_Interpreter pref_inter (validator,
00125                                          preferences);
00126 
00127   // Try to find the map of offers of desired service type.
00128   offer_filter.configure_type (type_struct.ptr ());
00129   this->lookup_one_type (type,
00130                          offer_database,
00131                          constr_inter,
00132                          pref_inter,
00133                          offer_filter);
00134 
00135   CORBA::Boolean result = policies.exact_type_match ();
00136 
00137   if (!result)
00138     {
00139       // If the importer hasn't demanded an exact match search, we
00140       // search all the subtypes of the supplied type. NOTE: Only the
00141       // properties belonging to the provided type are considered on
00142       // subtypes. Additional properties on the subtype are generally
00143       // ignored. This is as it should be, consistent with the notions
00144       // of type inheritence.
00145       this->lookup_all_subtypes (type,
00146                                  type_struct->incarnation,
00147                                  offer_database,
00148                                  rep,
00149                                  constr_inter,
00150                                  pref_inter,
00151                                  offer_filter);
00152     }
00153 
00154   // Take note of the limits applied in this query.
00155   returned_limits_applied = offer_filter.limits_applied ();
00156 
00157   // Fill the return sequence and iterator with the bountiful results.
00158   CORBA::ULong offers_returned =
00159     this->fill_receptacles (type,
00160                             how_many,
00161                             desired_props,
00162                             policies,
00163                             pref_inter,
00164                             *returned_offers.ptr (),
00165                             returned_offer_iterator);
00166 
00167   // The following steps are only appropriate for a linked trader.
00168   if (! CORBA::is_nil (link_if))
00169     {
00170       // Determine if we should perform a federated query, and if so
00171       // construct a sequence of links to follow.
00172       CosTrading::LinkNameSeq_var links;
00173       CORBA::Boolean should_follow =
00174         this->retrieve_links (policies,
00175                               offers_returned,
00176                               CosTrading::LinkNameSeq_out (links.out ()));
00177 
00178       if (should_follow && links->length () != 0)
00179         {
00180           // Query those links we've accumulated!
00181           this->federated_query (links.in (),
00182                                  policies,
00183                                  *request_id,
00184                                  pref_inter,
00185                                  type,
00186                                  constraint,
00187                                  preferences,
00188                                  desired_props,
00189                                  how_many,
00190                                  *returned_offers.ptr (),
00191                                  returned_offer_iterator.ptr (),
00192                                  *returned_limits_applied.ptr ());
00193         }
00194     }
00195 }

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
CORBA::Boolean TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::retrieve_links ( TAO_Policies policies,
CORBA::ULong  offer_returned,
CosTrading::LinkNameSeq_out  links 
) [private]

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 452 of file Trader_Interfaces.cpp.

References CosTrading::always, TAO_Policies::hop_count(), CosTrading::if_no_local, TAO_Policies::link_follow_rule(), TAO_Trader_Components< POA_CosTrading::Lookup >::link_if(), and TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::trader_.

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::query().

00455 {
00456   CORBA::Boolean should_follow = 0;
00457   CosTrading::FollowOption follow_rule = policies.link_follow_rule ();
00458 
00459   // Determine whether or not a federated query is warranted. A query
00460   // is waranted if the follow_rule governing this query is 'always'
00461   // or if_no_local and the local query returned nothing.
00462   if ((follow_rule == CosTrading::always ||
00463        (follow_rule == CosTrading::if_no_local && offers_returned == 0)))
00464     {
00465       CORBA::ULong hc = policies.hop_count ();
00466 
00467       if (hc > 0)
00468         should_follow = 1;
00469     }
00470 
00471   if (should_follow)
00472     {
00473       // Grab the names of all the links in the trader, and push
00474       // the suitable ones onto <valid_links>.
00475       CosTrading::Link_ptr link_if =
00476         this->trader_.trading_components ().link_if ();
00477 
00478       links = link_if->list_links ();
00479 
00480       // Determine which of the links registered with the Link
00481       // interface are suitable to follow.
00482       CORBA::ULong i = 0, j = 0,
00483         length = links->length ();
00484 
00485       for (i = 0; i < length; i++)
00486         {
00487           // Grab the link information.
00488           CosTrading::Link::LinkInfo_var
00489             link_info (link_if->describe_link (links[i]));
00490 
00491           // Compute the link follow rule.
00492           CosTrading::FollowOption link_rule =
00493             policies.link_follow_rule (link_info.in ());
00494 
00495           // Determine if the link follow rule applies.
00496           if (link_rule == CosTrading::always
00497               || (link_rule == CosTrading::if_no_local
00498                   && offers_returned == 0))
00499             {
00500               // Add the link to the list of links to follow.
00501               if (i > j)
00502                 links[j] = links[i];
00503 
00504               j++;
00505             }
00506         }
00507 
00508       links->length (j);
00509     }
00510 
00511   return should_follow;
00512 }

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
CORBA::Boolean TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::seen_request_id ( TAO_Policies policies,
CosTrading::Admin::OctetSeq *&  seq 
) [private]

Definition at line 733 of file Trader_Interfaces.cpp.

References ACE_GUARD_RETURN, ACE_NEW_THROW_EX, TAO_Trader_Components< POA_CosTrading::Lookup >::admin_if(), ACE_Unbounded_Queue< T >::dequeue_head(), ACE_Unbounded_Queue< T >::enqueue_tail(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::IDS_SAVED, TAO_Policies::request_id(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::request_ids_, and TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::trader_.

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::query().

00735 {
00736   CORBA::Boolean return_value = 0;
00737 
00738   seq = policies.request_id ();
00739 
00740   if (seq == 0)
00741     {
00742       CosTrading::Admin_ptr admin_if =
00743         this->trader_.trading_components ().admin_if ();
00744       seq = admin_if->request_id_stem ();
00745     }
00746   else
00747     {
00748       // Allocate memory so memory mangement is the same for both
00749       // cases.
00750       ACE_NEW_THROW_EX (seq,
00751                         CosTrading::Admin::OctetSeq (*seq),
00752                         CORBA::NO_MEMORY ());
00753     }
00754 
00755   ACE_GUARD_RETURN (TRADER_LOCK_TYPE, trader_mon, this->lock_, 1);
00756 
00757   for (Request_Ids::ITERATOR riter (this->request_ids_);
00758        ! riter.done ();
00759        riter.advance ())
00760     {
00761       CosTrading::Admin::OctetSeq** old_seq = 0;
00762       riter.next (old_seq);
00763 
00764       if (**old_seq == *seq)
00765         {
00766           return_value = 1;
00767           break;
00768         }
00769     }
00770 
00771   if (return_value == 0)
00772     {
00773       if (this->request_ids_.size () == IDS_SAVED)
00774         {
00775           CosTrading::Admin::OctetSeq* octet_seq = 0;
00776           this->request_ids_.dequeue_head (octet_seq);
00777           delete octet_seq;
00778         }
00779 
00780       this->request_ids_.enqueue_tail (seq);
00781     }
00782 
00783   return return_value;
00784 }


Member Data Documentation

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
const unsigned int TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::IDS_SAVED [private]

Definition at line 248 of file Trader_Interfaces.h.

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::seen_request_id().

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
TRADER_LOCK_TYPE TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::lock_ [private]

Lock to secure the set of request ids.

Definition at line 259 of file Trader_Interfaces.h.

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
Request_Ids TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::request_ids_ [private]

A list of recent request_id_stems.

Definition at line 256 of file Trader_Interfaces.h.

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::seen_request_id().

template<class TRADER_LOCK_TYPE, class MAP_LOCK_TYPE>
TAO_Trader<TRADER_LOCK_TYPE,MAP_LOCK_TYPE>& TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::trader_ [private]

A reference to the trader for obtaining offer maps.

Definition at line 251 of file Trader_Interfaces.h.

Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::federated_query(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::forward_query(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::query(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::retrieve_links(), and TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::seen_request_id().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:49:32 2010 for TAO_CosTrader by  doxygen 1.4.7