TAO_PG_ObjectGroupManager Class Reference

PortableGroup::ObjectGroupManager implementation. More...

#include <PG_ObjectGroupManager.h>

Collaboration diagram for TAO_PG_ObjectGroupManager:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TAO_PG_ObjectGroupManager (void)
 Constructor.

 ~TAO_PG_ObjectGroupManager (void)
 Destructor.

PortableGroup::ObjectGroup_ptr _tao_add_member (PortableGroup::ObjectGroup_ptr object_group, const PortableGroup::Location &the_location, CORBA::Object_ptr member, const char *type_id, const CORBA::Boolean propagate_member_already_present) throw (CORBA::SystemException, PortableGroup::MemberAlreadyPresent, PortableGroup::NoFactory)
 TAO-specific member addition method.

PortableGroup::ObjectGroup_ptr create_object_group (CORBA::ULong group_id, const PortableServer::ObjectId &oid, const char *type_id, const PortableGroup::Criteria &the_criteria)
void destroy_object_group (const PortableServer::ObjectId &oid)
 Destroy the object group corresponding to the given ObjectId.

PortableGroup::Propertiesget_properties (PortableGroup::ObjectGroup_ptr object_group) throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound)
char * type_id (PortableGroup::ObjectGroup_ptr object_group)
 Return the type_id for the given object group.

PortableGroup::ObjectGroup_ptr object_group (const PortableServer::ObjectId &oid)
 Return the object group associated with the given ObjectId.

CORBA::ULong member_count (PortableGroup::ObjectGroup_ptr group) throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound)
 Return the number of members in the given object group.

void poa (PortableServer::POA_ptr p)
void generic_factory (TAO_PG_GenericFactory *generic_factory)
PortableGroup::ObjectGroupManager methods
Methods required by the PortableGroup::ObjectGroupManager interface.

virtual PortableGroup::ObjectGroup_ptr create_member (PortableGroup::ObjectGroup_ptr object_group, const PortableGroup::Location &the_location, const char *type_id, const PortableGroup::Criteria &the_criteria) throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound, PortableGroup::MemberAlreadyPresent, PortableGroup::NoFactory, PortableGroup::ObjectNotCreated, PortableGroup::InvalidCriteria, PortableGroup::CannotMeetCriteria)
 Create a member and add it to the given object group.

virtual PortableGroup::ObjectGroup_ptr add_member (PortableGroup::ObjectGroup_ptr object_group, const PortableGroup::Location &the_location, CORBA::Object_ptr member) throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound, PortableGroup::MemberAlreadyPresent, PortableGroup::ObjectNotAdded)
 Add an existing object to the ObjectGroup.

virtual PortableGroup::ObjectGroup_ptr remove_member (PortableGroup::ObjectGroup_ptr object_group, const PortableGroup::Location &the_location) throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound, PortableGroup::MemberNotFound)
virtual PortableGroup::Locationslocations_of_members (PortableGroup::ObjectGroup_ptr object_group) throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound)
 Return the locations of the members in the given ObjectGroup.

virtual PortableGroup::ObjectGroupsgroups_at_location (const PortableGroup::Location &the_location) throw (CORBA::SystemException)
 Return the locations of the members in the given ObjectGroup.

virtual PortableGroup::ObjectGroupId get_object_group_id (PortableGroup::ObjectGroup_ptr object_group) throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound)
virtual PortableGroup::ObjectGroup_ptr get_object_group_ref (PortableGroup::ObjectGroup_ptr object_group) throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound)
 Does this method make sense for load balanced objects?

virtual CORBA::Object_ptr get_member_ref (PortableGroup::ObjectGroup_ptr object_group, const PortableGroup::Location &loc) throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound, PortableGroup::MemberNotFound)
virtual PortableGroup::ObjectGroup_ptr get_object_group_ref_from_id (PortableGroup::ObjectGroupId group_id) throw ( CORBA::SystemException , PortableGroup::ObjectGroupNotFound )

Protected Member Functions

PortableGroup::ObjectGroup_ptr add_member_i (PortableGroup::ObjectGroup_ptr object_group, const PortableGroup::Location &the_location, CORBA::Object_ptr member, const CORBA::Boolean check_type_id) throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound, PortableGroup::MemberAlreadyPresent, PortableGroup::ObjectNotAdded)
TAO_PG_ObjectGroup_Map_Entryget_group_entry (PortableGroup::ObjectGroup_ptr object_group) throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound)
CORBA::Boolean member_already_present (const TAO_PG_ObjectGroup_Array &groups, TAO_PG_ObjectGroup_Map_Entry *group_entry)
size_t get_object_group_position (const TAO_PG_ObjectGroup_Array &groups, TAO_PG_ObjectGroup_Map_Entry *group_entry)
 get the position of the object_group_map_entry

CORBA::Boolean valid_type_id (PortableGroup::ObjectGroup_ptr object_group, TAO_PG_ObjectGroup_Map_Entry *group_entry, CORBA::Object_ptr member)
 Verify that the member type_id matches the object group type_id.


Private Attributes

PortableServer::POA_var poa_
 Reference to the POA that created the object group references.

TAO_PG_ObjectGroup_Map object_group_map_
TAO_PG_Location_Map location_map_
TAO_PG_GenericFactorygeneric_factory_
TAO_SYNCH_MUTEX lock_
 Lock used to synchronize access to the underlying tables.


Detailed Description

PortableGroup::ObjectGroupManager implementation.

The ObjectGroupManager provides the interface necessary to facilitate application-controlled object group membership.

Definition at line 47 of file PG_ObjectGroupManager.h.


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_PG_ObjectGroupManager::TAO_PG_ObjectGroupManager void   ) 
 

Constructor.

Definition at line 19 of file PG_ObjectGroupManager.cpp.

References TAO_PG_MAX_LOCATIONS, and TAO_PG_MAX_OBJECT_GROUPS.

00020   : poa_ (),
00021     object_group_map_ (TAO_PG_MAX_OBJECT_GROUPS),
00022     location_map_ (TAO_PG_MAX_LOCATIONS),
00023     generic_factory_ (0),
00024     lock_ ()
00025 {
00026 }

TAO_PG_ObjectGroupManager::~TAO_PG_ObjectGroupManager void   ) 
 

Destructor.

Definition at line 28 of file PG_ObjectGroupManager.cpp.

References ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::begin(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::close(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::end(), location_map_, and object_group_map_.

00029 {
00030   for (TAO_PG_Location_Map::iterator i = this->location_map_.begin ();
00031        i != this->location_map_.end ();
00032        ++i)
00033     {
00034       // Destroy the group array
00035       delete (*i).int_id_;
00036     }
00037   (void) this->location_map_.close ();
00038 
00039   for (TAO_PG_ObjectGroup_Map::iterator j = this->object_group_map_.begin ();
00040        j != this->object_group_map_.end ();
00041        ++j)
00042     {
00043       // Destroy the object group entry
00044       delete (*j).int_id_;
00045     }
00046   (void) this->object_group_map_.close ();
00047 }


Member Function Documentation

PortableGroup::ObjectGroup_ptr TAO_PG_ObjectGroupManager::_tao_add_member PortableGroup::ObjectGroup_ptr  object_group,
const PortableGroup::Location the_location,
CORBA::Object_ptr  member,
const char *  type_id,
const CORBA::Boolean  propagate_member_already_present
throw (CORBA::SystemException, PortableGroup::MemberAlreadyPresent, PortableGroup::NoFactory)
 

TAO-specific member addition method.

This method is meant to be invoked by TAO's GenericFactory implementation. It is designed to allow only certain exceptions to be propagated to the caller, and to prevent redundant remote RepositoryId checking.

Definition at line 102 of file PG_ObjectGroupManager.cpp.

References ACE_CATCH, ACE_CHECK_RETURN, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_GUARD_RETURN, ACE_RE_THROW, ACE_THROW_RETURN, ACE_TRY, ACE_TRY_CHECK, ACE_TRY_THROW, CORBA::is_nil(), PortableGroup::Location, and TAO_SYNCH_MUTEX.

00112 {
00113   if (CORBA::is_nil (member))
00114     ACE_THROW_RETURN (CORBA::BAD_PARAM (),
00115                       PortableGroup::ObjectGroup::_nil ());
00116 
00117   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00118                     guard,
00119                     this->lock_,
00120                     PortableGroup::ObjectGroup::_nil ());
00121 
00122   PortableGroup::ObjectGroup_var new_group;
00123 
00124   ACE_TRY
00125     {
00126       // TypeId already checked by GenericFactory.
00127       const CORBA::Boolean check_type_id = 0;
00128 
00129       new_group = this->add_member_i (object_group,
00130                                       the_location,
00131                                       member,
00132                                       check_type_id
00133                                       ACE_ENV_ARG_PARAMETER);
00134       ACE_TRY_CHECK;
00135     }
00136   ACE_CATCH (PortableGroup::ObjectGroupNotFound, ex)
00137     {
00138       ACE_TRY_THROW (CORBA::INTERNAL ());
00139     }
00140   ACE_CATCH (PortableGroup::MemberAlreadyPresent, ex)
00141     {
00142       if (propagate_member_already_present)
00143         ACE_RE_THROW;
00144       else
00145         ACE_TRY_THROW (CORBA::INTERNAL ());
00146     }
00147   ACE_CATCH (PortableGroup::ObjectNotAdded, ex)
00148     {
00149       ACE_TRY_THROW (PortableGroup::NoFactory (the_location,
00150                                                type_id));
00151     }
00152   ACE_ENDTRY;
00153   ACE_CHECK_RETURN (PortableGroup::ObjectGroup::_nil ());
00154 
00155   return new_group._retn ();
00156 }

PortableGroup::ObjectGroup_ptr TAO_PG_ObjectGroupManager::add_member PortableGroup::ObjectGroup_ptr  object_group,
const PortableGroup::Location the_location,
CORBA::Object_ptr  member
throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound, PortableGroup::MemberAlreadyPresent, PortableGroup::ObjectNotAdded) [virtual]
 

Add an existing object to the ObjectGroup.

Definition at line 69 of file PG_ObjectGroupManager.cpp.

References ACE_ENV_ARG_PARAMETER, ACE_GUARD_RETURN, ACE_THROW_RETURN, CORBA::is_nil(), PortableGroup::Location, and TAO_SYNCH_MUTEX.

00078 {
00079   if (CORBA::is_nil (member))
00080     ACE_THROW_RETURN (CORBA::BAD_PARAM (),
00081                       PortableGroup::ObjectGroup::_nil ());
00082 
00083   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00084                     guard,
00085                     this->lock_,
00086                     PortableGroup::ObjectGroup::_nil ());
00087 
00088   // Verify that the member's RepositoryId matches the object group's
00089   // type ID.
00090   const CORBA::Boolean check_type_id = 1;
00091 
00092   return this->add_member_i (object_group,
00093                              the_location,
00094                              member,
00095                              check_type_id
00096                              ACE_ENV_ARG_PARAMETER);
00097 
00098 }

PortableGroup::ObjectGroup_ptr TAO_PG_ObjectGroupManager::add_member_i PortableGroup::ObjectGroup_ptr  object_group,
const PortableGroup::Location the_location,
CORBA::Object_ptr  member,
const CORBA::Boolean  check_type_id
throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound, PortableGroup::MemberAlreadyPresent, PortableGroup::ObjectNotAdded) [protected]
 

Underlying and non-locking implementation of the add_member() and _tao_add_member() methods in this class.

Definition at line 159 of file PG_ObjectGroupManager.cpp.

References CORBA::Object::_duplicate(), ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_NEW_THROW_EX, ACE_THROW_RETURN, TAO_PG_MemberInfo::location, PortableGroup::Location, TAO_PG_MemberInfo::member, ACE_Auto_Basic_Ptr< X >::release(), ACE_Array_Base< T >::size(), and TAO_PG_ObjectGroup_Array.

00169 {
00170   TAO_PG_ObjectGroup_Map_Entry * group_entry =
00171     this->get_group_entry (object_group
00172                            ACE_ENV_ARG_PARAMETER);
00173   ACE_CHECK_RETURN (PortableGroup::ObjectGroup::_nil ());
00174 
00175   if (check_type_id)
00176     {
00177       CORBA::Boolean right_type_id =
00178         this->valid_type_id (object_group,
00179                              group_entry,
00180                              member
00181                              ACE_ENV_ARG_PARAMETER);
00182       ACE_CHECK_RETURN (PortableGroup::ObjectGroup::_nil ());
00183 
00184       if (!right_type_id)
00185         {
00186           // The member's type_id does not match the object group's
00187           // type_id.
00188           ACE_THROW_RETURN (PortableGroup::ObjectNotAdded (),
00189                             PortableGroup::ObjectGroup::_nil ());
00190         }
00191     }
00192 
00193   TAO_PG_ObjectGroup_Array * groups = 0;
00194   if (this->location_map_.find (the_location, groups) == 0
00195       && this->member_already_present (*groups, group_entry))
00196     ACE_THROW_RETURN (PortableGroup::MemberAlreadyPresent (),
00197                       PortableGroup::ObjectGroup::_nil ());
00198 
00199   TAO_PG_MemberInfo member_info;
00200   member_info.member   = CORBA::Object::_duplicate (member);
00201   member_info.location = the_location;
00202 
00203   if (groups == 0)
00204     {
00205       ACE_NEW_THROW_EX (groups,
00206                         TAO_PG_ObjectGroup_Array,
00207                         CORBA::NO_MEMORY (
00208                           CORBA::SystemException::_tao_minor_code (
00209                             TAO::VMCID,
00210                             ENOMEM),
00211                           CORBA::COMPLETED_NO));
00212       ACE_CHECK_RETURN (0);
00213 
00214       auto_ptr<TAO_PG_ObjectGroup_Array> safe_groups (groups);
00215 
00216       // This should not fail!
00217       if (this->location_map_.bind (the_location, groups) != 0)
00218         {
00219           ACE_THROW_RETURN (PortableGroup::ObjectNotAdded (),
00220                             PortableGroup::ObjectGroup::_nil ());
00221         }
00222 
00223       (void) safe_groups.release ();
00224     }
00225 
00226   // No object group member of the object group with the given
00227   // ObjectGroupId resides at the location.  Add the object group
00228   // entry to array of object groups residing at the location.
00229   const size_t groups_len = groups->size ();
00230   groups->size (groups_len + 1);
00231   (*groups)[groups_len] = group_entry;
00232 
00233   // Don't bother checking for duplicates since a check is already
00234   // performed when binding to the location map above.
00235   if (group_entry->member_infos.insert_tail (member_info) != 0)
00236     ACE_THROW_RETURN (PortableGroup::ObjectNotAdded (),
00237                       PortableGroup::ObjectGroup::_nil ());
00238 
00239   return PortableGroup::ObjectGroup::_duplicate (object_group);
00240 }

PortableGroup::ObjectGroup_ptr TAO_PG_ObjectGroupManager::create_member PortableGroup::ObjectGroup_ptr  object_group,
const PortableGroup::Location the_location,
const char *  type_id,
const PortableGroup::Criteria the_criteria
throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound, PortableGroup::MemberAlreadyPresent, PortableGroup::NoFactory, PortableGroup::ObjectNotCreated, PortableGroup::InvalidCriteria, PortableGroup::CannotMeetCriteria) [virtual]
 

Create a member and add it to the given object group.

Definition at line 50 of file PG_ObjectGroupManager.cpp.

References ACE_THROW_RETURN, PortableGroup::Criteria, and PortableGroup::Location.

00063 {
00064   ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (),
00065                     PortableGroup::ObjectGroup::_nil ());
00066 }

PortableGroup::ObjectGroup_ptr TAO_PG_ObjectGroupManager::create_object_group CORBA::ULong  group_id,
const PortableServer::ObjectId oid,
const char *  type_id,
const PortableGroup::Criteria the_criteria
 

Note:
This method is used mainly by the GenericFactory::create_object() method.

Definition at line 545 of file PG_ObjectGroupManager.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_GUARD_RETURN, ACE_NEW_THROW_EX, ACE_THROW_RETURN, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::bind(), PortableGroup::Criteria, TAO_PG_ObjectGroup_Map_Entry::group_id, CORBA::is_nil(), TAO_PG_ObjectGroup_Map_Entry::object_group, object_group_map_, TAO_PG_ObjectGroup_Map_Entry::properties, ACE_Auto_Basic_Ptr< X >::release(), CORBA::string_dup(), TAO_SYNCH_MUTEX, and TAO_PG_ObjectGroup_Map_Entry::type_id.

00551 {
00552   if (CORBA::is_nil (this->poa_.in ()))
00553     ACE_THROW_RETURN (CORBA::INTERNAL (), CORBA::Object::_nil ());
00554 
00555   // Create a reference for the ObjectGroup corresponding to the
00556   // RepositoryId of the object being created.
00557   CORBA::Object_var object_group =
00558     this->poa_->create_reference_with_id (oid,
00559                                           type_id
00560                                           ACE_ENV_ARG_PARAMETER);
00561   ACE_CHECK_RETURN (CORBA::Object::_nil ());
00562 
00563   TAO_PG_ObjectGroup_Map_Entry * group_entry = 0;
00564   ACE_NEW_THROW_EX (group_entry,
00565                     TAO_PG_ObjectGroup_Map_Entry,
00566                     CORBA::NO_MEMORY (
00567                       CORBA::SystemException::_tao_minor_code (
00568                         TAO::VMCID,
00569                         ENOMEM),
00570                       CORBA::COMPLETED_NO));
00571   ACE_CHECK_RETURN (CORBA::Object::_nil ());
00572 
00573   auto_ptr<TAO_PG_ObjectGroup_Map_Entry> safe_group_entry (group_entry);
00574 
00575   // Set the RepositoryId associated with the created ObjectGroup_Map
00576   // entry.
00577   group_entry->type_id = CORBA::string_dup (type_id);
00578 
00579   group_entry->group_id = group_id;
00580 
00581   group_entry->object_group = object_group;
00582 
00583   CORBA::ULong len = the_criteria.length ();
00584   group_entry->properties.length (len);
00585   for (CORBA::ULong i = 0; i < len; ++i)
00586     group_entry->properties[i] = the_criteria[i];
00587 
00588   {
00589     ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00590                       guard,
00591                       this->lock_,
00592                       0);
00593 
00594     if (this->object_group_map_.bind (oid, group_entry) != 0)
00595       ACE_THROW_RETURN (PortableGroup::ObjectNotCreated (),
00596                         PortableGroup::ObjectGroup::_nil ());
00597   }
00598 
00599   (void) safe_group_entry.release ();
00600 
00601   return object_group._retn ();
00602 }

void TAO_PG_ObjectGroupManager::destroy_object_group const PortableServer::ObjectId oid  ) 
 

Destroy the object group corresponding to the given ObjectId.

Note:
This method is used mainly by the GenericFactory::delete_object() method.

Definition at line 605 of file PG_ObjectGroupManager.cpp.

References ACE_GUARD, ACE_THROW, object_group_map_, TAO_SYNCH_MUTEX, and ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::unbind().

Referenced by TAO_PG_Group_Guard::~TAO_PG_Group_Guard().

00608 {
00609   ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->lock_);
00610 
00611   TAO_PG_ObjectGroup_Map_Entry * group_entry = 0;
00612   if (this->object_group_map_.unbind (oid, group_entry) != 0)
00613     ACE_THROW (PortableGroup::ObjectNotFound ());
00614 
00615   delete group_entry;
00616 }

void TAO_PG_ObjectGroupManager::generic_factory TAO_PG_GenericFactory generic_factory  ) 
 

The TAO_PG_GenericFactory will only be used when ObjectGroupManager::remove_member() is explicitly called so that the infrastructure may be given an opportunity to clean up any object group members it may have created.

Definition at line 865 of file PG_ObjectGroupManager.cpp.

Referenced by TAO_PG_GenericFactory::TAO_PG_GenericFactory().

00867 {
00868   this->generic_factory_ = generic_factory;
00869 }

TAO_PG_ObjectGroup_Map_Entry* TAO_PG_ObjectGroupManager::get_group_entry PortableGroup::ObjectGroup_ptr  object_group  )  throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound) [protected]
 

Obtain the ObjectGroup hash map entry corresponding to the given ObjectGroup reference.

Referenced by type_id(), and valid_type_id().

CORBA::Object_ptr TAO_PG_ObjectGroupManager::get_member_ref PortableGroup::ObjectGroup_ptr  object_group,
const PortableGroup::Location loc
throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound, PortableGroup::MemberNotFound) [virtual]
 

Return the reference corresponding to the member of a given ObjectGroup at the given location.

Definition at line 457 of file PG_ObjectGroupManager.cpp.

References CORBA::Object::_duplicate(), ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_GUARD_RETURN, ACE_THROW_RETURN, ACE_Unbounded_Set< T >::begin(), ACE_Unbounded_Set< T >::end(), PortableGroup::Location, TAO_PG_ObjectGroup_Map_Entry::member_infos, TAO_PG_MemberInfo_Set, TAO_PG_ObjectGroup_Array, and TAO_SYNCH_MUTEX.

00464 {
00465   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00466                     guard,
00467                     this->lock_,
00468                     CORBA::Object::_nil ());
00469 
00470   TAO_PG_ObjectGroup_Map_Entry * group_entry =
00471     this->get_group_entry (object_group
00472                            ACE_ENV_ARG_PARAMETER);
00473   ACE_CHECK_RETURN (PortableGroup::ObjectGroup::_nil ());
00474 
00475   // This method assumes that it is faster to check for non-existence
00476   // of an object group (and hence the member) at a given location,
00477   // instead of existence of a member at a given location.
00478 
00479   TAO_PG_ObjectGroup_Array * groups = 0;
00480   if (this->location_map_.find (loc, groups) == 0
00481       && this->member_already_present (*groups, group_entry))
00482     {
00483       TAO_PG_MemberInfo_Set & member_infos = group_entry->member_infos;
00484 
00485       TAO_PG_MemberInfo_Set::iterator end = member_infos.end ();
00486 
00487       // @todo If the object group contains a large number of members,
00488       //       this loop could take a while.  Explore potentially
00489       //       faster containers for the list of PG_MemberInfos in the
00490       //       future.
00491       for (TAO_PG_MemberInfo_Set::iterator i = member_infos.begin ();
00492            i != end;
00493            ++i)
00494         if ((*i).location == loc)
00495           return CORBA::Object::_duplicate ((*i).member.in ());
00496     }
00497 
00498   // No member of the given object group is present at the given
00499   // location.
00500   ACE_THROW_RETURN (PortableGroup::MemberNotFound (),
00501                     CORBA::Object::_nil ());
00502 }

PortableGroup::ObjectGroupId TAO_PG_ObjectGroupManager::get_object_group_id PortableGroup::ObjectGroup_ptr  object_group  )  throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound) [virtual]
 

Return the ObjectGroupId for the given ObjectGroup.

Note:
Does this method make sense for load balanced objects?

Definition at line 403 of file PG_ObjectGroupManager.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_GUARD_RETURN, ACE_THROW_RETURN, TAO_PG_ObjectGroup_Map_Entry::group_id, and TAO_SYNCH_MUTEX.

00408 {
00409   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00410                     guard,
00411                     this->lock_,
00412                     0);
00413 
00414   TAO_PG_ObjectGroup_Map_Entry * entry =
00415     this->get_group_entry (object_group
00416                            ACE_ENV_ARG_PARAMETER);
00417   ACE_CHECK_RETURN (0);
00418 
00419   if (entry == 0)
00420     ACE_THROW_RETURN (CORBA::INTERNAL (), 0);
00421 
00422   // Only the lower 32 bits of the 64 bit PortableGroup::ObjectGroupId
00423   // are ever used.
00424   return entry->group_id;
00425 }

size_t TAO_PG_ObjectGroupManager::get_object_group_position const TAO_PG_ObjectGroup_Array groups,
TAO_PG_ObjectGroup_Map_Entry group_entry
[protected]
 

get the position of the object_group_map_entry

Definition at line 784 of file PG_ObjectGroupManager.cpp.

References TAO_PG_ObjectGroup_Map_Entry::group_id, ACE_Array_Base< T >::size(), and TAO_PG_ObjectGroup_Array.

00787 {
00788   // Multiple members from different object groups may reside at the
00789   // same location.  Iterate through the list to attempt to find a
00790   // match.
00791   size_t len = groups.size ();
00792   for (size_t i = 0; i < len; ++i)
00793     {
00794       // It should be enough just to compare the group_entry pointers,
00795       // but that seems brittle.  Better to check a controlled value,
00796       // like the ObjectGroupId.
00797       if (groups[i]->group_id == group_entry->group_id)
00798         {
00799           // Member with given type ID exists at the given
00800           // location.
00801           return i;
00802         }
00803     }
00804 
00805   // No member with given type ID present at the given location.
00806   return 0;
00807 }

PortableGroup::ObjectGroup_ptr TAO_PG_ObjectGroupManager::get_object_group_ref PortableGroup::ObjectGroup_ptr  object_group  )  throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound) [virtual]
 

Does this method make sense for load balanced objects?

Definition at line 428 of file PG_ObjectGroupManager.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_GUARD_RETURN, ACE_THROW_RETURN, and TAO_SYNCH_MUTEX.

00433 {
00434   TAO_PG_ObjectGroup_Map_Entry * entry = 0;
00435 
00436   {
00437     ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00438                       guard,
00439                       this->lock_,
00440                       PortableGroup::ObjectGroup::_nil ());
00441 
00442 
00443     entry = this->get_group_entry (object_group
00444                                    ACE_ENV_ARG_PARAMETER);
00445     ACE_CHECK_RETURN (PortableGroup::ObjectGroup::_nil ());
00446   }
00447 
00448   if (entry == 0)
00449     ACE_THROW_RETURN (CORBA::INTERNAL (),
00450                       PortableGroup::ObjectGroup::_nil ());
00451 
00452   // This implemenation does not change the object group reference.
00453   return PortableGroup::ObjectGroup::_duplicate (object_group);
00454 }

PortableGroup::ObjectGroup_ptr TAO_PG_ObjectGroupManager::get_object_group_ref_from_id PortableGroup::ObjectGroupId  group_id  )  throw ( CORBA::SystemException , PortableGroup::ObjectGroupNotFound ) [virtual]
 

TAO-specific extension. Return the ObjectGroup reference for the given ObjectGroupId.

Definition at line 505 of file PG_ObjectGroupManager.cpp.

References ACE_GUARD_RETURN, ACE_THROW_RETURN, ACE_U64_TO_U32, TAO_PG_ObjectGroup_Map_Entry::object_group, and TAO_SYNCH_MUTEX.

00513 {
00514   //@@ If we change the PG's concept of ObjectGroupId from
00515   // PortableServer::ObjectId to PortableGroup::ObjectGroupId, can
00516   // just call TAO_PG_ObjectGroupManager::object_group() here.
00517 
00518   TAO_PG_ObjectGroup_Map_Entry * group_entry = 0;
00519   {
00520     ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00521                       guard,
00522                       this->lock_,
00523                       PortableGroup::ObjectGroup::_nil ());
00524 
00525     if (this->object_group_map_.find (ACE_U64_TO_U32 (group_id),
00526                                       group_entry)
00527          != 0)
00528       {
00529         ACE_THROW_RETURN (PortableGroup::ObjectGroupNotFound (),
00530                           PortableGroup::ObjectGroup::_nil ());
00531       }
00532   }
00533 
00534   if (group_entry == 0)
00535     {
00536       ACE_THROW_RETURN (CORBA::INTERNAL (),
00537                         PortableGroup::ObjectGroup::_nil ());
00538     }
00539 
00540   return
00541     PortableGroup::ObjectGroup::_duplicate (group_entry->object_group.in ());
00542 }

PortableGroup::Properties * TAO_PG_ObjectGroupManager::get_properties PortableGroup::ObjectGroup_ptr  object_group  )  throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound)
 

Return the properties set when the object group was created, and the dynamic properties that may have overridden them.

Definition at line 680 of file PG_ObjectGroupManager.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_GUARD_RETURN, ACE_NEW_THROW_EX, TAO_PG_ObjectGroup_Map_Entry::properties, PortableGroup::Properties, and TAO_SYNCH_MUTEX.

00685 {
00686   PortableGroup::Properties * properties = 0;
00687   ACE_NEW_THROW_EX (properties,
00688                     PortableGroup::Properties,
00689                     CORBA::NO_MEMORY (
00690                       CORBA::SystemException::_tao_minor_code (
00691                         TAO::VMCID,
00692                         ENOMEM),
00693                       CORBA::COMPLETED_NO));
00694   ACE_CHECK_RETURN (0);
00695 
00696   PortableGroup::Properties_var safe_properties = properties;
00697 
00698   {
00699     ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00700                       guard,
00701                       this->lock_,
00702                       0);
00703 
00704     TAO_PG_ObjectGroup_Map_Entry * group_entry =
00705       this->get_group_entry (object_group
00706                              ACE_ENV_ARG_PARAMETER);
00707     ACE_CHECK_RETURN (0);
00708 
00709     *properties = group_entry->properties;
00710   }
00711 
00712   return safe_properties._retn ();
00713 }

PortableGroup::ObjectGroups * TAO_PG_ObjectGroupManager::groups_at_location const PortableGroup::Location the_location  )  throw (CORBA::SystemException) [virtual]
 

Return the locations of the members in the given ObjectGroup.

Definition at line 369 of file PG_ObjectGroupManager.cpp.

References ACE_CHECK_RETURN, ACE_GUARD_RETURN, ACE_NEW_THROW_EX, PortableGroup::Location, PortableGroup::ObjectGroups, ACE_Array_Base< T >::size(), TAO_PG_ObjectGroup_Array, and TAO_SYNCH_MUTEX.

00373 {
00374   PortableGroup::ObjectGroups * ogs;
00375   ACE_NEW_THROW_EX (ogs,
00376                     PortableGroup::ObjectGroups,
00377                     CORBA::NO_MEMORY ());
00378   ACE_CHECK_RETURN (0);
00379 
00380   PortableGroup::ObjectGroups_var object_groups = ogs;
00381 
00382   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0);
00383 
00384   TAO_PG_ObjectGroup_Array * groups;
00385   if (this->location_map_.find (the_location, groups) == 0)
00386     {
00387       CORBA::ULong len = static_cast<CORBA::ULong> (groups->size ());
00388 
00389       ogs->length (len);
00390 
00391       for (CORBA::ULong i = 0; i < len; ++i)
00392         {
00393           object_groups[i] =
00394             PortableGroup::ObjectGroup::_duplicate (
00395               (*groups)[i]->object_group.in ());
00396         }
00397     }
00398 
00399   return object_groups._retn ();
00400 }

PortableGroup::Locations * TAO_PG_ObjectGroupManager::locations_of_members PortableGroup::ObjectGroup_ptr  object_group  )  throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound) [virtual]
 

Return the locations of the members in the given ObjectGroup.

Definition at line 328 of file PG_ObjectGroupManager.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_GUARD_RETURN, ACE_NEW_THROW_EX, ACE_Unbounded_Set< T >::begin(), ACE_Unbounded_Set< T >::end(), PortableGroup::Locations, TAO_PG_ObjectGroup_Map_Entry::member_infos, ACE_Unbounded_Set< T >::size(), TAO_PG_MemberInfo_Set, and TAO_SYNCH_MUTEX.

00333 {
00334   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0);
00335 
00336   TAO_PG_ObjectGroup_Map_Entry * group_entry =
00337     this->get_group_entry (object_group
00338                            ACE_ENV_ARG_PARAMETER);
00339   ACE_CHECK_RETURN (0);
00340 
00341   PortableGroup::Locations *temp = 0;
00342   ACE_NEW_THROW_EX (temp,
00343                     PortableGroup::Locations,
00344                     CORBA::NO_MEMORY (
00345                       CORBA::SystemException::_tao_minor_code (
00346                         TAO::VMCID,
00347                         ENOMEM),
00348                       CORBA::COMPLETED_NO));
00349   ACE_CHECK_RETURN (0);
00350 
00351   PortableGroup::Locations_var locations = temp;
00352 
00353   TAO_PG_MemberInfo_Set & member_infos = group_entry->member_infos;
00354 
00355   locations->length (static_cast<CORBA::ULong> (member_infos.size ()));
00356 
00357   CORBA::ULong loc = 0;
00358   TAO_PG_MemberInfo_Set::iterator end = member_infos.end ();
00359 
00360   for (TAO_PG_MemberInfo_Set::iterator i = member_infos.begin ();
00361        i != end;
00362        ++i)
00363     locations[loc++] = (*i).location;
00364 
00365   return locations._retn ();
00366 }

CORBA::Boolean TAO_PG_ObjectGroupManager::member_already_present const TAO_PG_ObjectGroup_Array groups,
TAO_PG_ObjectGroup_Map_Entry group_entry
[protected]
 

A member is actually represented by the object group to which it belongs. In this implementation, a pointer to a object group hash map entry is associated with a given a location.

Definition at line 758 of file PG_ObjectGroupManager.cpp.

References TAO_PG_ObjectGroup_Map_Entry::group_id, ACE_Array_Base< T >::size(), and TAO_PG_ObjectGroup_Array.

00761 {
00762   // Multiple members from different object groups may reside at the
00763   // same location.  Iterate through the list to attempt to find a
00764   // match.
00765   size_t len = groups.size ();
00766   for (size_t i = 0; i < len; ++i)
00767     {
00768       // It should be enough just to compare the group_entry pointers,
00769       // but that seems brittle.  Better to check a controlled value,
00770       // like the ObjectGroupId.
00771       if (groups[i]->group_id == group_entry->group_id)
00772         {
00773           // Member with given type ID exists at the given
00774           // location.
00775           return 1;
00776         }
00777     }
00778 
00779   // No member with given type ID present at the given location.
00780   return 0;
00781 }

CORBA::ULong TAO_PG_ObjectGroupManager::member_count PortableGroup::ObjectGroup_ptr  group  )  throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound)
 

Return the number of members in the given object group.

Definition at line 653 of file PG_ObjectGroupManager.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, TAO_PG_ObjectGroup_Map_Entry::member_infos, and ACE_Unbounded_Set< T >::size().

Referenced by TAO_PG_GenericFactory::check_minimum_number_members().

00658 {
00659 //   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00660 //                     guard,
00661 //                     this->lock_,
00662 //                     0);
00663 
00664   TAO_PG_ObjectGroup_Map_Entry * group_entry =
00665     this->get_group_entry (group
00666                            ACE_ENV_ARG_PARAMETER);
00667   ACE_CHECK_RETURN (0);
00668 
00669   return static_cast<CORBA::ULong> (group_entry->member_infos.size ());
00670 }

PortableGroup::ObjectGroup_ptr TAO_PG_ObjectGroupManager::object_group const PortableServer::ObjectId oid  ) 
 

Return the object group associated with the given ObjectId.

Returns:
Returns PortableGroup::ObjectGroup::_nil() if no object group corresponding to the given ObjectId exists.

Definition at line 637 of file PG_ObjectGroupManager.cpp.

References ACE_GUARD_RETURN, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), TAO_PG_ObjectGroup_Map_Entry::object_group, object_group_map_, and TAO_SYNCH_MUTEX.

00638 {
00639   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00640                     guard,
00641                     this->lock_,
00642                     PortableGroup::ObjectGroup::_nil ());
00643 
00644   TAO_PG_ObjectGroup_Map_Entry * group_entry = 0;
00645   if (this->object_group_map_.find (oid, group_entry) == 0)
00646     return
00647       PortableGroup::ObjectGroup::_duplicate (group_entry->object_group.in ());
00648   else
00649     return PortableGroup::ObjectGroup::_nil ();
00650 }

void TAO_PG_ObjectGroupManager::poa PortableServer::POA_ptr  p  ) 
 

Set the POA to use when converting object group references to ObjectIds.

Definition at line 673 of file PG_ObjectGroupManager.cpp.

00674 {
00675   this->poa_ = PortableServer::POA::_duplicate (p);
00676 }

PortableGroup::ObjectGroup_ptr TAO_PG_ObjectGroupManager::remove_member PortableGroup::ObjectGroup_ptr  object_group,
const PortableGroup::Location the_location
throw (CORBA::SystemException, PortableGroup::ObjectGroupNotFound, PortableGroup::MemberNotFound) [virtual]
 

Remove an object at a specific location from the given ObjectGroup. Deletion of application created objects must be deleted by the application. Objects created by the infrastructure (load balancer) will be deleted by the infrastructure.

Definition at line 243 of file PG_ObjectGroupManager.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_GUARD_RETURN, ACE_THROW_RETURN, ACE_Unbounded_Set< T >::begin(), ACE_Unbounded_Set< T >::end(), TAO_PG_ObjectGroup_Map_Entry::group_id, TAO_PG_MemberInfo::location, PortableGroup::Location, TAO_PG_ObjectGroup_Map_Entry::member_infos, ACE_Unbounded_Set< T >::remove(), ACE_Array_Base< T >::size(), TAO_PG_MemberInfo_Set, TAO_PG_ObjectGroup_Array, TAO_SYNCH_MUTEX, and TAO_PG_ObjectGroup_Map_Entry::type_id.

00250 {
00251   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0);
00252 
00253   TAO_PG_ObjectGroup_Map_Entry * group_entry =
00254     this->get_group_entry (object_group
00255                            ACE_ENV_ARG_PARAMETER);
00256   ACE_CHECK_RETURN (PortableGroup::ObjectGroup::_nil ());
00257 
00258   TAO_PG_ObjectGroup_Array * groups = 0;
00259   if (this->location_map_.find (the_location, groups) != 0)
00260     ACE_THROW_RETURN (PortableGroup::ObjectGroupNotFound (),
00261                       PortableGroup::ObjectGroup::_nil ());
00262 
00263   // Multiple members from different object groups may reside at the
00264   // same location.  Iterate through the list to attempt to find a
00265   // match for the exact object group.
00266   size_t to_be_removed = 0;
00267 
00268   // get the position of the object group in the object_group_array
00269   to_be_removed = this->get_object_group_position (*groups, group_entry);
00270 
00271   // remove the element from the array and resize the array.
00272   const size_t groups_len = groups->size ();
00273   size_t j;
00274   for (size_t i = to_be_removed; i < groups_len - 1; ++i)
00275     {
00276       j = i + 1;
00277       (*groups)[i] = (*groups)[j];
00278     }
00279 
00280   groups->size (groups_len - 1);
00281 
00282   TAO_PG_MemberInfo_Set & member_infos = group_entry->member_infos;
00283 
00284   TAO_PG_MemberInfo_Set::iterator end = member_infos.end ();
00285 
00286   for (TAO_PG_MemberInfo_Set::iterator iter = member_infos.begin ();
00287        iter != end;
00288        ++iter)
00289     {
00290       const TAO_PG_MemberInfo & info = *iter;
00291 
00292       if (info.location == the_location)
00293         {
00294           // Give the GenericFactory a chance to delete a member if
00295           // its membership is under infrastructure control.
00296           if (this->generic_factory_)
00297             {
00298               this->generic_factory_->delete_member (group_entry->group_id,
00299                                                      the_location
00300                                                      ACE_ENV_ARG_PARAMETER);
00301               ACE_CHECK_RETURN (PortableGroup::ObjectGroup::_nil ());
00302             }
00303 
00304           if (member_infos.remove (info) == 0)
00305             {
00306               if (this->generic_factory_)
00307                 {
00308                   this->generic_factory_->check_minimum_number_members (
00309                     object_group,
00310                     group_entry->group_id,
00311                     group_entry->type_id.in ()
00312                     ACE_ENV_ARG_PARAMETER);
00313                   ACE_CHECK_RETURN (PortableGroup::ObjectGroup::_nil ());
00314                 }
00315 
00316               return PortableGroup::ObjectGroup::_duplicate (object_group);
00317             }
00318           else
00319             break;
00320         }
00321     }
00322 
00323   ACE_THROW_RETURN (PortableGroup::MemberNotFound (),
00324                     PortableGroup::ObjectGroup::_nil ());
00325 }

char * TAO_PG_ObjectGroupManager::type_id PortableGroup::ObjectGroup_ptr  object_group  ) 
 

Return the type_id for the given object group.

Definition at line 619 of file PG_ObjectGroupManager.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_GUARD_RETURN, get_group_entry(), CORBA::string_dup(), TAO_SYNCH_MUTEX, and TAO_PG_ObjectGroup_Map_Entry::type_id.

00622 {
00623   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00624                     guard,
00625                     this->lock_,
00626                     0);
00627 
00628   TAO_PG_ObjectGroup_Map_Entry * group_entry =
00629     this->get_group_entry (object_group
00630                            ACE_ENV_ARG_PARAMETER);
00631   ACE_CHECK_RETURN (0);
00632 
00633   return CORBA::string_dup (group_entry->type_id.in ());
00634 }

CORBA::Boolean TAO_PG_ObjectGroupManager::valid_type_id PortableGroup::ObjectGroup_ptr  object_group,
TAO_PG_ObjectGroup_Map_Entry group_entry,
CORBA::Object_ptr  member
[protected]
 

Verify that the member type_id matches the object group type_id.

Todo:
Strategize this -- e.g. strict type checking.

Definition at line 810 of file PG_ObjectGroupManager.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_GUARD_RETURN, ACE_THROW_RETURN, get_group_entry(), CORBA::is_nil(), CORBA::string_dup(), and TAO_PG_ObjectGroup_Map_Entry::type_id.

00815 {
00816   // @todo Strategize this -- e.g. strict type checking.
00817 
00818   if (CORBA::is_nil (member))
00819     ACE_THROW_RETURN (CORBA::BAD_PARAM (), false);
00820 
00821   // Before we can use this code, i.e. the reverse lock, the
00822   // TAO_PG_ObjectGroup_Entry should be made so that it is reference
00823   // counted.  This is necessary since releasing the lock would
00824   // allow other threads to destroy/unbind the object group entry.
00825   // Another alternative is to simply attempt to reacquire the
00826   // object group map entry once the lock is reacquired, which is
00827   // easier to implement.
00828 
00829   // Copy the type_id before releasing the lock to avoid a race
00830   // condition.
00831   CORBA::String_var type_id =
00832     CORBA::string_dup (group_entry->type_id.in ());
00833 
00834   CORBA::Boolean right_type_id = 0;
00835   {
00836     // Release the lock during the type_id check.  No need to block
00837     // other threads during the invocation.
00838     ACE_Reverse_Lock<TAO_SYNCH_MUTEX> reverse_lock (this->lock_);
00839 
00840     ACE_GUARD_RETURN (ACE_Reverse_Lock<TAO_SYNCH_MUTEX>,
00841                       reverse_guard,
00842                       reverse_lock,
00843                       right_type_id);
00844 
00845     // Make sure an Object of the correct type was created.  It is
00846     // possible that an object of the wrong type was created if the
00847     // type_id parameter does not match the type of object the
00848     // GenericFactory creates.
00849     right_type_id =
00850       member->_is_a (type_id.in ()
00851                      ACE_ENV_ARG_PARAMETER);
00852     ACE_CHECK_RETURN (right_type_id);
00853   }
00854 
00855   // Make sure the group entry still exists.  It may have been
00856   // destroyed by another thread.
00857   group_entry = this->get_group_entry (object_group
00858                                        ACE_ENV_ARG_PARAMETER);
00859   ACE_CHECK_RETURN (right_type_id);
00860 
00861   return right_type_id;
00862 }


Member Data Documentation

TAO_PG_GenericFactory* TAO_PG_ObjectGroupManager::generic_factory_ [private]
 

Pointer to the TAO_PG_GenericFactory class responsible for object group creation/destruction.

Definition at line 303 of file PG_ObjectGroupManager.h.

TAO_PG_Location_Map TAO_PG_ObjectGroupManager::location_map_ [private]
 

Map that contains list of all members at a given location, in addition to the load monitor at that location.

Definition at line 299 of file PG_ObjectGroupManager.h.

Referenced by ~TAO_PG_ObjectGroupManager().

TAO_SYNCH_MUTEX TAO_PG_ObjectGroupManager::lock_ [private]
 

Lock used to synchronize access to the underlying tables.

Definition at line 306 of file PG_ObjectGroupManager.h.

TAO_PG_ObjectGroup_Map TAO_PG_ObjectGroupManager::object_group_map_ [private]
 

The underlying table that contains all object group information.

Definition at line 295 of file PG_ObjectGroupManager.h.

Referenced by create_object_group(), destroy_object_group(), object_group(), and ~TAO_PG_ObjectGroupManager().

PortableServer::POA_var TAO_PG_ObjectGroupManager::poa_ [private]
 

Reference to the POA that created the object group references.

Definition at line 291 of file PG_ObjectGroupManager.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 14:05:00 2006 for TAO_PortableGroup by doxygen 1.3.6