00001 #include "orbsvcs/PortableGroup/PG_ObjectGroupManager.h"
00002 #include "orbsvcs/PortableGroup/PG_GenericFactory.h"
00003 #include "orbsvcs/PortableGroup/PG_conf.h"
00004 #include "orbsvcs/PortableGroup/PG_Operators.h"
00005
00006 #include "tao/debug.h"
00007 #include "tao/ORB_Constants.h"
00008
00009 #include "ace/Auto_Ptr.h"
00010 #include "ace/Reverse_Lock_T.h"
00011
00012 ACE_RCSID (PortableGroup,
00013 PG_ObjectGroupManager,
00014 "$Id: PG_ObjectGroupManager.cpp 87872 2009-12-02 18:25:48Z dai_y $")
00015
00016
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018
00019 TAO_PG_ObjectGroupManager::TAO_PG_ObjectGroupManager (void)
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 }
00027
00028 TAO_PG_ObjectGroupManager::~TAO_PG_ObjectGroupManager (void)
00029 {
00030 for (TAO_PG_Location_Map::iterator i = this->location_map_.begin ();
00031 i != this->location_map_.end ();
00032 ++i)
00033 {
00034
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
00044 delete (*j).int_id_;
00045 }
00046 (void) this->object_group_map_.close ();
00047 }
00048
00049 PortableGroup::ObjectGroup_ptr
00050 TAO_PG_ObjectGroupManager::create_member (
00051 PortableGroup::ObjectGroup_ptr ,
00052 const PortableGroup::Location & ,
00053 const char * ,
00054 const PortableGroup::Criteria & )
00055 {
00056 throw CORBA::NO_IMPLEMENT ();
00057 }
00058
00059 PortableGroup::ObjectGroup_ptr
00060 TAO_PG_ObjectGroupManager::add_member (
00061 PortableGroup::ObjectGroup_ptr object_group,
00062 const PortableGroup::Location & the_location,
00063 CORBA::Object_ptr member)
00064 {
00065 if (CORBA::is_nil (member))
00066 throw CORBA::BAD_PARAM ();
00067
00068 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00069 guard,
00070 this->lock_,
00071 PortableGroup::ObjectGroup::_nil ());
00072
00073
00074
00075 const CORBA::Boolean check_type_id = 1;
00076
00077 return this->add_member_i (object_group,
00078 the_location,
00079 member,
00080 check_type_id);
00081
00082 }
00083
00084
00085 PortableGroup::ObjectGroup_ptr
00086 TAO_PG_ObjectGroupManager::_tao_add_member (
00087 PortableGroup::ObjectGroup_ptr object_group,
00088 const PortableGroup::Location & the_location,
00089 CORBA::Object_ptr member,
00090 const char * type_id,
00091 const CORBA::Boolean propagate_member_already_present)
00092 {
00093 if (CORBA::is_nil (member))
00094 throw CORBA::BAD_PARAM ();
00095
00096 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00097 guard,
00098 this->lock_,
00099 PortableGroup::ObjectGroup::_nil ());
00100
00101 PortableGroup::ObjectGroup_var new_group;
00102
00103 try
00104 {
00105
00106 const CORBA::Boolean check_type_id = 0;
00107
00108 new_group = this->add_member_i (object_group,
00109 the_location,
00110 member,
00111 check_type_id);
00112 }
00113 catch (const PortableGroup::ObjectGroupNotFound&)
00114 {
00115 throw CORBA::INTERNAL ();
00116 }
00117 catch (const PortableGroup::MemberAlreadyPresent&)
00118 {
00119 if (propagate_member_already_present)
00120 throw;
00121 else
00122 throw CORBA::INTERNAL ();
00123 }
00124 catch (const PortableGroup::ObjectNotAdded&)
00125 {
00126 throw PortableGroup::NoFactory (the_location, type_id);
00127 }
00128
00129 return new_group._retn ();
00130 }
00131
00132 PortableGroup::ObjectGroup_ptr
00133 TAO_PG_ObjectGroupManager::add_member_i (
00134 PortableGroup::ObjectGroup_ptr object_group,
00135 const PortableGroup::Location & the_location,
00136 CORBA::Object_ptr member,
00137 const CORBA::Boolean check_type_id)
00138 {
00139 TAO_PG_ObjectGroup_Map_Entry * group_entry =
00140 this->get_group_entry (object_group);
00141
00142 if (check_type_id)
00143 {
00144 CORBA::Boolean right_type_id =
00145 this->valid_type_id (object_group,
00146 group_entry,
00147 member);
00148
00149 if (!right_type_id)
00150 {
00151
00152
00153 throw PortableGroup::ObjectNotAdded ();
00154 }
00155 }
00156
00157 TAO_PG_ObjectGroup_Array * groups = 0;
00158 if (this->location_map_.find (the_location, groups) == 0
00159 && this->member_already_present (*groups, group_entry))
00160 throw PortableGroup::MemberAlreadyPresent ();
00161
00162 TAO_PG_MemberInfo member_info;
00163 member_info.group = PortableGroup::ObjectGroup::_duplicate (object_group);
00164 member_info.member = CORBA::Object::_duplicate (member);
00165 member_info.location = the_location;
00166 member_info.is_alive = true;
00167
00168 if (groups == 0)
00169 {
00170 ACE_NEW_THROW_EX (groups,
00171 TAO_PG_ObjectGroup_Array,
00172 CORBA::NO_MEMORY (
00173 CORBA::SystemException::_tao_minor_code (
00174 TAO::VMCID,
00175 ENOMEM),
00176 CORBA::COMPLETED_NO));
00177
00178 auto_ptr<TAO_PG_ObjectGroup_Array> safe_groups (groups);
00179
00180
00181 if (this->location_map_.bind (the_location, groups) != 0)
00182 {
00183 throw PortableGroup::ObjectNotAdded ();
00184 }
00185
00186 (void) safe_groups.release ();
00187 }
00188
00189
00190
00191
00192 const size_t groups_len = groups->size ();
00193 groups->size (groups_len + 1);
00194 (*groups)[groups_len] = group_entry;
00195
00196
00197
00198 if (group_entry->member_infos.insert_tail (member_info) != 0)
00199 throw PortableGroup::ObjectNotAdded ();
00200
00201 return PortableGroup::ObjectGroup::_duplicate (object_group);
00202 }
00203
00204 PortableGroup::ObjectGroup_ptr
00205 TAO_PG_ObjectGroupManager::remove_member (
00206 PortableGroup::ObjectGroup_ptr object_group,
00207 const PortableGroup::Location & the_location)
00208 {
00209 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0);
00210
00211 TAO_PG_ObjectGroup_Map_Entry * group_entry =
00212 this->get_group_entry (object_group);
00213
00214 TAO_PG_ObjectGroup_Array * groups = 0;
00215 if (this->location_map_.find (the_location, groups) != 0)
00216 throw PortableGroup::ObjectGroupNotFound ();
00217
00218
00219
00220
00221 int to_be_removed = this->get_object_group_position (*groups, group_entry);
00222
00223 if (to_be_removed == -1)
00224 throw PortableGroup::ObjectGroupNotFound ();
00225
00226
00227 const size_t groups_len = groups->size ();
00228 size_t j;
00229 for (size_t i = to_be_removed; i < groups_len - 1; ++i)
00230 {
00231 j = i + 1;
00232 (*groups)[i] = (*groups)[j];
00233 }
00234
00235 groups->size (groups_len - 1);
00236
00237 TAO_PG_MemberInfo_Set & member_infos = group_entry->member_infos;
00238
00239 TAO_PG_MemberInfo_Set::iterator end = member_infos.end ();
00240
00241 for (TAO_PG_MemberInfo_Set::iterator iter = member_infos.begin ();
00242 iter != end;
00243 ++iter)
00244 {
00245 const TAO_PG_MemberInfo & info = *iter;
00246
00247 if (info.location == the_location)
00248 {
00249
00250
00251 if (this->generic_factory_)
00252 {
00253 CORBA::ULong group_id = group_entry->group_id;
00254
00255
00256
00257 ACE_Reverse_Lock<TAO_SYNCH_MUTEX> reverse_lock (this->lock_);
00258
00259 ACE_GUARD_RETURN (ACE_Reverse_Lock<TAO_SYNCH_MUTEX>,
00260 reverse_guard,
00261 reverse_lock,
00262 PortableGroup::ObjectGroup::_nil ());
00263
00264 this->generic_factory_->delete_member (group_id,
00265 the_location);
00266 }
00267
00268 if (member_infos.remove (info) == 0)
00269 {
00270 if (this->generic_factory_)
00271 {
00272 this->generic_factory_->check_minimum_number_members (
00273 object_group,
00274 group_entry->group_id,
00275 group_entry->type_id.in ());
00276 }
00277
00278 return PortableGroup::ObjectGroup::_duplicate (object_group);
00279 }
00280 else
00281 break;
00282 }
00283 }
00284
00285 throw PortableGroup::MemberNotFound ();
00286 }
00287
00288
00289 PortableGroup::Locations *
00290 TAO_PG_ObjectGroupManager::locations_of_members (
00291 PortableGroup::ObjectGroup_ptr object_group)
00292 {
00293 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0);
00294
00295 TAO_PG_ObjectGroup_Map_Entry * group_entry =
00296 this->get_group_entry (object_group);
00297
00298 PortableGroup::Locations *temp = 0;
00299 ACE_NEW_THROW_EX (temp,
00300 PortableGroup::Locations,
00301 CORBA::NO_MEMORY (
00302 CORBA::SystemException::_tao_minor_code (
00303 TAO::VMCID,
00304 ENOMEM),
00305 CORBA::COMPLETED_NO));
00306
00307 PortableGroup::Locations_var locations = temp;
00308
00309 TAO_PG_MemberInfo_Set & member_infos = group_entry->member_infos;
00310
00311 CORBA::ULong loc = 0;
00312 TAO_PG_MemberInfo_Set::iterator end = member_infos.end ();
00313
00314 for (TAO_PG_MemberInfo_Set::iterator i = member_infos.begin ();
00315 i != end;
00316 ++i)
00317 {
00318
00319
00320
00321
00322 if ((*i).is_alive)
00323 {
00324 locations->length (loc + 1);
00325 locations[loc++] = (*i).location;
00326 }
00327 }
00328 return locations._retn ();
00329 }
00330
00331
00332 PortableGroup::ObjectGroups *
00333 TAO_PG_ObjectGroupManager::groups_at_location (
00334 const PortableGroup::Location & the_location)
00335 {
00336 PortableGroup::ObjectGroups * ogs;
00337 ACE_NEW_THROW_EX (ogs,
00338 PortableGroup::ObjectGroups,
00339 CORBA::NO_MEMORY ());
00340
00341 PortableGroup::ObjectGroups_var object_groups = ogs;
00342
00343 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0);
00344
00345 TAO_PG_ObjectGroup_Array * groups;
00346 if (this->location_map_.find (the_location, groups) == 0)
00347 {
00348 CORBA::ULong len = static_cast<CORBA::ULong> (groups->size ());
00349
00350 ogs->length (len);
00351
00352 for (CORBA::ULong i = 0; i < len; ++i)
00353 {
00354 object_groups[i] =
00355 PortableGroup::ObjectGroup::_duplicate (
00356 (*groups)[i]->object_group.in ());
00357 }
00358 }
00359
00360 return object_groups._retn ();
00361 }
00362
00363 PortableGroup::ObjectGroupId
00364 TAO_PG_ObjectGroupManager::get_object_group_id (
00365 PortableGroup::ObjectGroup_ptr object_group)
00366 {
00367 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00368 guard,
00369 this->lock_,
00370 0);
00371
00372 TAO_PG_ObjectGroup_Map_Entry * entry =
00373 this->get_group_entry (object_group);
00374
00375 if (entry == 0)
00376 throw CORBA::INTERNAL ();
00377
00378
00379
00380 return entry->group_id;
00381 }
00382
00383 PortableGroup::ObjectGroup_ptr
00384 TAO_PG_ObjectGroupManager::get_object_group_ref (
00385 PortableGroup::ObjectGroup_ptr object_group)
00386 {
00387 TAO_PG_ObjectGroup_Map_Entry * entry = 0;
00388
00389 {
00390 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00391 guard,
00392 this->lock_,
00393 PortableGroup::ObjectGroup::_nil ());
00394
00395
00396 entry = this->get_group_entry (object_group);
00397 }
00398
00399 if (entry == 0)
00400 throw CORBA::INTERNAL ();
00401
00402
00403 return PortableGroup::ObjectGroup::_duplicate (object_group);
00404 }
00405
00406 CORBA::Object_ptr
00407 TAO_PG_ObjectGroupManager::get_member_ref (
00408 PortableGroup::ObjectGroup_ptr object_group,
00409 const PortableGroup::Location & loc)
00410 {
00411 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00412 guard,
00413 this->lock_,
00414 CORBA::Object::_nil ());
00415
00416 TAO_PG_ObjectGroup_Map_Entry * group_entry =
00417 this->get_group_entry (object_group);
00418
00419
00420
00421
00422
00423 TAO_PG_ObjectGroup_Array * groups = 0;
00424 if (this->location_map_.find (loc, groups) == 0
00425 && this->member_already_present (*groups, group_entry))
00426 {
00427 TAO_PG_MemberInfo_Set & member_infos = group_entry->member_infos;
00428
00429 TAO_PG_MemberInfo_Set::iterator end = member_infos.end ();
00430
00431
00432
00433
00434
00435 for (TAO_PG_MemberInfo_Set::iterator i = member_infos.begin ();
00436 i != end;
00437 ++i)
00438 if ((*i).location == loc)
00439 return CORBA::Object::_duplicate ((*i).member.in ());
00440 }
00441
00442
00443
00444 throw PortableGroup::MemberNotFound ();
00445 }
00446
00447 PortableGroup::ObjectGroup_ptr
00448 TAO_PG_ObjectGroupManager::get_object_group_ref_from_id (
00449 PortableGroup::ObjectGroupId group_id
00450 )
00451 {
00452
00453
00454
00455
00456 TAO_PG_ObjectGroup_Map_Entry * group_entry = 0;
00457 {
00458 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00459 guard,
00460 this->lock_,
00461 PortableGroup::ObjectGroup::_nil ());
00462
00463 if (this->object_group_map_.find (ACE_U64_TO_U32 (group_id),
00464 group_entry)
00465 != 0)
00466 {
00467 throw PortableGroup::ObjectGroupNotFound ();
00468 }
00469 }
00470
00471 if (group_entry == 0)
00472 {
00473 throw CORBA::INTERNAL ();
00474 }
00475
00476 return
00477 PortableGroup::ObjectGroup::_duplicate (group_entry->object_group.in ());
00478 }
00479
00480 PortableGroup::ObjectGroup_ptr
00481 TAO_PG_ObjectGroupManager::create_object_group (
00482 CORBA::ULong group_id,
00483 const PortableServer::ObjectId &oid,
00484 const char * type_id,
00485 const PortableGroup::Criteria & the_criteria)
00486 {
00487 if (CORBA::is_nil (this->poa_.in ()))
00488 throw CORBA::INTERNAL ();
00489
00490
00491
00492 CORBA::Object_var object_group =
00493 this->poa_->create_reference_with_id (oid,
00494 type_id);
00495
00496 TAO_PG_ObjectGroup_Map_Entry * group_entry = 0;
00497 ACE_NEW_THROW_EX (group_entry,
00498 TAO_PG_ObjectGroup_Map_Entry,
00499 CORBA::NO_MEMORY (
00500 CORBA::SystemException::_tao_minor_code (
00501 TAO::VMCID,
00502 ENOMEM),
00503 CORBA::COMPLETED_NO));
00504
00505 auto_ptr<TAO_PG_ObjectGroup_Map_Entry> safe_group_entry (group_entry);
00506
00507
00508
00509 group_entry->type_id = CORBA::string_dup (type_id);
00510
00511 group_entry->group_id = group_id;
00512
00513 group_entry->object_group = object_group;
00514
00515 CORBA::ULong len = the_criteria.length ();
00516 group_entry->properties.length (len);
00517 for (CORBA::ULong i = 0; i < len; ++i)
00518 group_entry->properties[i] = the_criteria[i];
00519
00520 {
00521 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00522 guard,
00523 this->lock_,
00524 0);
00525
00526 if (this->object_group_map_.bind (oid, group_entry) != 0)
00527 throw PortableGroup::ObjectNotCreated ();
00528 }
00529
00530 (void) safe_group_entry.release ();
00531
00532 return object_group._retn ();
00533 }
00534
00535 void
00536 TAO_PG_ObjectGroupManager::destroy_object_group (
00537 const PortableServer::ObjectId & oid)
00538 {
00539 ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->lock_);
00540
00541 TAO_PG_ObjectGroup_Map_Entry * group_entry = 0;
00542 if (this->object_group_map_.unbind (oid, group_entry) != 0)
00543 throw PortableGroup::ObjectNotFound ();
00544
00545 delete group_entry;
00546 }
00547
00548 char *
00549 TAO_PG_ObjectGroupManager::type_id (
00550 PortableGroup::ObjectGroup_ptr object_group)
00551 {
00552 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00553 guard,
00554 this->lock_,
00555 0);
00556
00557 TAO_PG_ObjectGroup_Map_Entry * group_entry =
00558 this->get_group_entry (object_group);
00559
00560 return CORBA::string_dup (group_entry->type_id.in ());
00561 }
00562
00563 PortableGroup::ObjectGroup_ptr
00564 TAO_PG_ObjectGroupManager::object_group (const PortableServer::ObjectId & oid)
00565 {
00566 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00567 guard,
00568 this->lock_,
00569 PortableGroup::ObjectGroup::_nil ());
00570
00571 TAO_PG_ObjectGroup_Map_Entry * group_entry = 0;
00572 if (this->object_group_map_.find (oid, group_entry) == 0)
00573 return
00574 PortableGroup::ObjectGroup::_duplicate (group_entry->object_group.in ());
00575 else
00576 return PortableGroup::ObjectGroup::_nil ();
00577 }
00578
00579 CORBA::ULong
00580 TAO_PG_ObjectGroupManager::member_count (
00581 PortableGroup::ObjectGroup_ptr group)
00582 {
00583
00584
00585
00586
00587
00588 TAO_PG_ObjectGroup_Map_Entry * group_entry =
00589 this->get_group_entry (group);
00590
00591 return static_cast<CORBA::ULong> (group_entry->member_infos.size ());
00592 }
00593
00594 void
00595 TAO_PG_ObjectGroupManager::poa (PortableServer::POA_ptr p)
00596 {
00597 this->poa_ = PortableServer::POA::_duplicate (p);
00598 }
00599
00600
00601 PortableGroup::Properties *
00602 TAO_PG_ObjectGroupManager::get_properties (
00603 PortableGroup::ObjectGroup_ptr object_group)
00604 {
00605 PortableGroup::Properties * properties = 0;
00606 ACE_NEW_THROW_EX (properties,
00607 PortableGroup::Properties,
00608 CORBA::NO_MEMORY (
00609 CORBA::SystemException::_tao_minor_code (
00610 TAO::VMCID,
00611 ENOMEM),
00612 CORBA::COMPLETED_NO));
00613
00614 PortableGroup::Properties_var safe_properties = properties;
00615
00616 {
00617 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00618 guard,
00619 this->lock_,
00620 0);
00621
00622 TAO_PG_ObjectGroup_Map_Entry * group_entry =
00623 this->get_group_entry (object_group);
00624
00625 *properties = group_entry->properties;
00626 }
00627
00628 return safe_properties._retn ();
00629 }
00630
00631 TAO_PG_ObjectGroup_Map_Entry *
00632 TAO_PG_ObjectGroupManager::get_group_entry (
00633 CORBA::Object_ptr object_group)
00634 {
00635 if (CORBA::is_nil (this->poa_.in ()))
00636 throw CORBA::INTERNAL ();
00637
00638 PortableServer::ObjectId_var oid;
00639 try
00640 {
00641 oid = this->poa_->reference_to_id (object_group);
00642 }
00643 catch (const PortableServer::POA::WrongAdapter& ex)
00644 {
00645 if (TAO_debug_level > 0)
00646 ex._tao_print_exception ("TAO_PG (%P|%t) Unexpected exception\n");
00647
00648 throw CORBA::INTERNAL ();
00649 }
00650 catch (const PortableServer::POA::WrongPolicy& ex)
00651 {
00652 if (TAO_debug_level > 0)
00653 ex._tao_print_exception ("TAO_PG (%P|%t) Unexpected exception\n");
00654
00655 throw CORBA::INTERNAL ();
00656 }
00657
00658 TAO_PG_ObjectGroup_Map_Entry * group_entry = 0;
00659 if (this->object_group_map_.find (oid.in (), group_entry) != 0)
00660 throw PortableGroup::ObjectGroupNotFound ();
00661
00662 return group_entry;
00663 }
00664
00665 CORBA::Boolean
00666 TAO_PG_ObjectGroupManager::member_already_present (
00667 const TAO_PG_ObjectGroup_Array &groups,
00668 TAO_PG_ObjectGroup_Map_Entry * group_entry)
00669 {
00670
00671
00672
00673 size_t len = groups.size ();
00674 for (size_t i = 0; i < len; ++i)
00675 {
00676
00677
00678
00679 if (groups[i]->group_id == group_entry->group_id)
00680 {
00681
00682
00683 return 1;
00684 }
00685 }
00686
00687
00688 return 0;
00689 }
00690
00691
00692 int
00693 TAO_PG_ObjectGroupManager::get_object_group_position (
00694 const TAO_PG_ObjectGroup_Array &groups,
00695 TAO_PG_ObjectGroup_Map_Entry * group_entry)
00696 {
00697
00698
00699
00700 size_t len = groups.size ();
00701 for (size_t i = 0; i < len; ++i)
00702 {
00703
00704
00705
00706 if (groups[i]->group_id == group_entry->group_id)
00707 {
00708
00709
00710 return (int)i;
00711 }
00712 }
00713
00714
00715 return -1;
00716 }
00717
00718 CORBA::Boolean
00719 TAO_PG_ObjectGroupManager::valid_type_id (
00720 PortableGroup::ObjectGroup_ptr object_group,
00721 TAO_PG_ObjectGroup_Map_Entry * group_entry,
00722 CORBA::Object_ptr member)
00723 {
00724
00725
00726 if (CORBA::is_nil (member))
00727 throw CORBA::BAD_PARAM ();
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739 CORBA::String_var type_id =
00740 CORBA::string_dup (group_entry->type_id.in ());
00741
00742 CORBA::Boolean right_type_id = 0;
00743 {
00744
00745
00746 ACE_Reverse_Lock<TAO_SYNCH_MUTEX> reverse_lock (this->lock_);
00747
00748 ACE_GUARD_RETURN (ACE_Reverse_Lock<TAO_SYNCH_MUTEX>,
00749 reverse_guard,
00750 reverse_lock,
00751 right_type_id);
00752
00753
00754
00755
00756
00757 right_type_id =
00758 member->_is_a (type_id.in ());
00759 }
00760
00761
00762
00763 group_entry = this->get_group_entry (object_group);
00764
00765 return right_type_id;
00766 }
00767
00768 void
00769 TAO_PG_ObjectGroupManager::generic_factory (
00770 TAO_PG_GenericFactory * generic_factory)
00771 {
00772 this->generic_factory_ = generic_factory;
00773 }
00774
00775
00776 size_t
00777 TAO_PG_ObjectGroupManager::member_count (
00778 const PortableServer::ObjectId & oid,
00779 bool is_alive)
00780 {
00781 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0);
00782
00783 TAO_PG_ObjectGroup_Map_Entry * group_entry = 0;
00784 if (this->object_group_map_.find (oid, group_entry) != 0)
00785 throw PortableGroup::ObjectGroupNotFound ();
00786
00787 int count = 0;
00788 TAO_PG_MemberInfo_Set & member_infos = group_entry->member_infos;
00789
00790 TAO_PG_MemberInfo_Set::iterator end = member_infos.end ();
00791
00792 for (TAO_PG_MemberInfo_Set::iterator i = member_infos.begin ();
00793 i != end;
00794 ++i)
00795 {
00796 if ((*i).is_alive == is_alive)
00797 {
00798 ++count;
00799 }
00800 }
00801
00802 return count;
00803 }
00804
00805
00806 bool
00807 TAO_PG_ObjectGroupManager::is_alive (
00808 const PortableServer::ObjectId & oid,
00809 CORBA::Object_ptr member)
00810 {
00811 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0);
00812
00813 TAO_PG_ObjectGroup_Map_Entry * group_entry = 0;
00814 if (this->object_group_map_.find (oid, group_entry) != 0)
00815 throw PortableGroup::ObjectGroupNotFound ();
00816
00817 TAO_PG_MemberInfo_Set & member_infos = group_entry->member_infos;
00818
00819 TAO_PG_MemberInfo_Set::iterator end = member_infos.end ();
00820
00821 for (TAO_PG_MemberInfo_Set::iterator i = member_infos.begin ();
00822 i != end;
00823 ++i)
00824 {
00825 if ((*i).member->_is_equivalent (member))
00826 {
00827 return (*i).is_alive;
00828 }
00829 }
00830
00831 throw PortableGroup::MemberNotFound ();
00832 }
00833
00834
00835 void TAO_PG_ObjectGroupManager::remove_inactive_members ()
00836 {
00837 TAO_PG_MemberInfo_Set inactive_members;
00838
00839 {
00840 ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->lock_);
00841 inactive_members = this->inactive_members_;
00842 this->inactive_members_.reset ();
00843 }
00844
00845 TAO_PG_MemberInfo_Set::iterator end = inactive_members.end ();
00846 for (TAO_PG_MemberInfo_Set::iterator i = inactive_members.begin ();
00847 i != end;
00848 ++i)
00849 {
00850 this->remove_member ((*i).group.in (), (*i).location);
00851 }
00852 }
00853
00854 TAO_PG_MemberInfo_Set
00855 TAO_PG_ObjectGroupManager::get_members (bool is_alive)
00856 {
00857 TAO_PG_MemberInfo_Set members;
00858 {
00859 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, TAO_PG_MemberInfo_Set());
00860
00861 for (TAO_PG_ObjectGroup_Map::iterator j = this->object_group_map_.begin ();
00862 j != this->object_group_map_.end ();
00863 ++j)
00864 {
00865 TAO_PG_MemberInfo_Set & member_infos = j->int_id_->member_infos;
00866 TAO_PG_MemberInfo_Set::iterator end = member_infos.end ();
00867
00868 for (TAO_PG_MemberInfo_Set::iterator i = member_infos.begin ();
00869 i != end;
00870 ++i)
00871 {
00872 if ((*i).is_alive == is_alive)
00873 {
00874 if (members.insert_tail (*i) !=0)
00875 {
00876 throw CORBA::INTERNAL ();
00877 }
00878 }
00879 }
00880 }
00881 }
00882
00883 return members;
00884 }
00885
00886 void
00887 TAO_PG_ObjectGroupManager::validate_members (CORBA::ORB_ptr orb,
00888 const TimeBase::TimeT& timeout)
00889 {
00890 if (TAO_debug_level > 0)
00891 ACE_DEBUG ((LM_DEBUG,
00892 ACE_TEXT ("(%P|%t)TAO_PG_ObjectGroupManager::validate_members start\n")));
00893
00894
00895 TAO_PG_MemberInfo_Set active_members = this->get_members (true);
00896
00897
00898
00899 TAO_PG_MemberInfo_Set inactive_members;
00900 for (TAO_PG_MemberInfo_Set::iterator j = active_members.begin ();
00901 j != active_members.end ();
00902 ++j)
00903 {
00904 if (! this->ping (orb, (*j).member, timeout))
00905 {
00906 if (inactive_members.insert_tail (*j) !=0)
00907 {
00908 throw CORBA::INTERNAL ();
00909 }
00910 }
00911 }
00912
00913 {
00914 ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->lock_);
00915 for (TAO_PG_MemberInfo_Set::iterator i = inactive_members.begin ();
00916 i != inactive_members.end ();
00917 ++i)
00918 {
00919 TAO_PG_ObjectGroup_Map_Entry * group_entry =
00920 this->get_group_entry ((*i).group.in ());
00921
00922 TAO_PG_MemberInfo_Set & members = group_entry->member_infos;
00923 for (TAO_PG_MemberInfo_Set::iterator j = members.begin ();
00924 j != members.end ();
00925 ++j)
00926 {
00927 if ((*j) == (*i))
00928 (*j).is_alive = false;
00929 }
00930 }
00931
00932
00933 this->inactive_members_ = inactive_members;
00934 }
00935
00936 if (TAO_debug_level > 0)
00937 ACE_DEBUG ((LM_DEBUG,
00938 ACE_TEXT ("(%P|%t)TAO_PG_ObjectGroupManager::validate_members end\n")));
00939 }
00940
00941 bool
00942 TAO_PG_ObjectGroupManager::ping (CORBA::ORB_ptr orb,
00943 CORBA::Object_var& obj,
00944 const TimeBase::TimeT& tt)
00945 {
00946 bool status = true;
00947 if (CORBA::is_nil (obj.in ()))
00948 throw CORBA::OBJECT_NOT_EXIST ();
00949
00950
00951
00952
00953
00954
00955
00956
00957 TimeBase::TimeT timeout = tt;
00958 CORBA::Any timeout_any;
00959 timeout_any <<= timeout;
00960
00961 CORBA::PolicyList policy_list (1);
00962 policy_list.length (1);
00963 policy_list[0] = orb->
00964 create_policy (
00965 Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
00966 timeout_any);
00967 CORBA::Object_var rtt_obj =
00968 obj->_set_policy_overrides (policy_list,
00969 CORBA::ADD_OVERRIDE);
00970
00971
00972 for (CORBA::ULong i = 0; i < policy_list.length (); i++)
00973 policy_list[i]->destroy ();
00974
00975 try {
00976 status = ! rtt_obj->_non_existent ();
00977 }
00978 catch (CORBA::TIMEOUT& ex)
00979 {
00980 if (TAO_debug_level > 8)
00981 {
00982 ex._tao_print_exception ("TAO_PG_ObjectGroupManager::ping");
00983 }
00984 }
00985 catch (CORBA::Exception& ex)
00986 {
00987 if (TAO_debug_level > 8)
00988 {
00989 ex._tao_print_exception ("TAO_PG_ObjectGroupManager::ping");
00990 }
00991
00992 status = false;
00993 }
00994
00995 return status;
00996 }
00997
00998
00999 TAO_END_VERSIONED_NAMESPACE_DECL