Active_Object_Map.cpp

Go to the documentation of this file.
00001 // $Id: Active_Object_Map.cpp 81691 2008-05-14 11:09:21Z johnnyw $
00002 
00003 #include "tao/PortableServer/Active_Object_Map.h"
00004 #include "tao/PortableServer/Active_Object_Map_Entry.h"
00005 
00006 #if !defined (__ACE_INLINE__)
00007 # include "tao/PortableServer/Active_Object_Map.inl"
00008 #endif /* __ACE_INLINE__ */
00009 
00010 #include "tao/SystemException.h"
00011 
00012 #include "ace/Auto_Ptr.h"
00013 #include "ace/CORBA_macros.h"
00014 
00015 ACE_RCSID(PortableServer,
00016           Active_Object_Map,
00017           "$Id: Active_Object_Map.cpp 81691 2008-05-14 11:09:21Z johnnyw $")
00018 
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020 
00021 /* static */
00022 size_t TAO_Active_Object_Map::system_id_size_ = 0;
00023 
00024 void
00025 TAO_Active_Object_Map::set_system_id_size (
00026   const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &creation_parameters)
00027 {
00028   if (TAO_Active_Object_Map::system_id_size_ == 0)
00029     {
00030       if (creation_parameters.allow_reactivation_of_system_ids_)
00031         {
00032           switch (creation_parameters.object_lookup_strategy_for_system_id_policy_)
00033             {
00034 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
00035             case TAO_LINEAR:
00036               TAO_Active_Object_Map::system_id_size_ = sizeof (CORBA::ULong);
00037               break;
00038 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
00039 
00040             case TAO_DYNAMIC_HASH:
00041             default:
00042               TAO_Active_Object_Map::system_id_size_ = sizeof (CORBA::ULong);
00043               break;
00044             }
00045 
00046           size_t hint_size = 0;
00047 
00048           if (creation_parameters.use_active_hint_in_ids_)
00049             hint_size = ACE_Active_Map_Manager_Key::size ();
00050 
00051           TAO_Active_Object_Map::system_id_size_ += hint_size;
00052         }
00053       else
00054         {
00055           switch (creation_parameters.object_lookup_strategy_for_system_id_policy_)
00056             {
00057 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
00058             case TAO_LINEAR:
00059               TAO_Active_Object_Map::system_id_size_ = sizeof (CORBA::ULong);
00060               break;
00061 
00062             case TAO_DYNAMIC_HASH:
00063               TAO_Active_Object_Map::system_id_size_ = sizeof (CORBA::ULong);
00064               break;
00065 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
00066 
00067             case TAO_ACTIVE_DEMUX:
00068             default:
00069               TAO_Active_Object_Map::system_id_size_ =
00070                 ACE_Active_Map_Manager_Key::size ();
00071               break;
00072             }
00073         }
00074     }
00075 }
00076 
00077 TAO_Active_Object_Map::TAO_Active_Object_Map (
00078     int user_id_policy,
00079     int unique_id_policy,
00080     int persistent_id_policy,
00081     const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &
00082       creation_parameters)
00083   : user_id_map_ (0)
00084   , servant_map_ (0)
00085   , id_uniqueness_strategy_ (0)
00086   , lifespan_strategy_ (0)
00087   , id_assignment_strategy_ (0)
00088   , id_hint_strategy_ (0)
00089   , using_active_maps_ (false)
00090 {
00091   TAO_Active_Object_Map::set_system_id_size (creation_parameters);
00092 
00093   TAO_Id_Uniqueness_Strategy *id_uniqueness_strategy = 0;
00094 
00095   if (unique_id_policy)
00096     {
00097       ACE_NEW_THROW_EX (id_uniqueness_strategy,
00098                         TAO_Unique_Id_Strategy,
00099                         CORBA::NO_MEMORY ());
00100     }
00101   else
00102     {
00103 #if !defined (CORBA_E_MICRO)
00104       ACE_NEW_THROW_EX (id_uniqueness_strategy,
00105                         TAO_Multiple_Id_Strategy,
00106                         CORBA::NO_MEMORY ());
00107 #else
00108       ACE_ERROR ((LM_ERROR,
00109                   "Multiple Id Strategy not supported with CORBA/e\n"));
00110 #endif
00111     }
00112 
00113   // Give ownership to the auto pointer.
00114   auto_ptr<TAO_Id_Uniqueness_Strategy>
00115     new_id_uniqueness_strategy (id_uniqueness_strategy);
00116 
00117   TAO_Lifespan_Strategy *lifespan_strategy = 0;
00118 
00119   if (persistent_id_policy)
00120     {
00121 #if !defined (CORBA_E_MICRO)
00122       ACE_NEW_THROW_EX (lifespan_strategy,
00123                         TAO_Persistent_Strategy,
00124                         CORBA::NO_MEMORY ());
00125 #else
00126       ACE_UNUSED_ARG (persistent_id_policy);
00127       ACE_ERROR ((LM_ERROR,
00128                   "Persistent Id Strategy not supported with CORBA/e\n"));
00129 #endif
00130     }
00131   else
00132     {
00133       ACE_NEW_THROW_EX (lifespan_strategy,
00134                         TAO_Transient_Strategy,
00135                         CORBA::NO_MEMORY ());
00136     }
00137 
00138   // Give ownership to the auto pointer.
00139   auto_ptr<TAO_Lifespan_Strategy> new_lifespan_strategy (lifespan_strategy);
00140 
00141   TAO_Id_Assignment_Strategy *id_assignment_strategy = 0;
00142 
00143   if (user_id_policy)
00144     {
00145 #if !defined (CORBA_E_MICRO)
00146       ACE_NEW_THROW_EX (id_assignment_strategy,
00147                         TAO_User_Id_Strategy,
00148                         CORBA::NO_MEMORY ());
00149 #else
00150       ACE_ERROR ((LM_ERROR,
00151                   "User Id Assignment not supported with CORBA/e\n"));
00152 #endif
00153     }
00154   else if (unique_id_policy)
00155     {
00156       ACE_NEW_THROW_EX (id_assignment_strategy,
00157                         TAO_System_Id_With_Unique_Id_Strategy,
00158                         CORBA::NO_MEMORY ());
00159     }
00160   else
00161     {
00162 #if !defined (CORBA_E_MICRO)
00163       ACE_NEW_THROW_EX (id_assignment_strategy,
00164                         TAO_System_Id_With_Multiple_Id_Strategy,
00165                         CORBA::NO_MEMORY ());
00166 #else
00167       ACE_ERROR ((LM_ERROR,
00168                   "System Id Assignment with multiple "
00169                   "not supported with CORBA/e\n"));
00170 #endif
00171     }
00172 
00173   // Give ownership to the auto pointer.
00174   auto_ptr<TAO_Id_Assignment_Strategy>
00175     new_id_assignment_strategy (id_assignment_strategy);
00176 
00177   TAO_Id_Hint_Strategy *id_hint_strategy = 0;
00178   if ((user_id_policy
00179        || creation_parameters.allow_reactivation_of_system_ids_)
00180       && creation_parameters.use_active_hint_in_ids_)
00181     {
00182       this->using_active_maps_ = true;
00183 
00184       ACE_NEW_THROW_EX (id_hint_strategy,
00185                         TAO_Active_Hint_Strategy (
00186                           creation_parameters.active_object_map_size_),
00187                         CORBA::NO_MEMORY ());
00188     }
00189   else
00190     {
00191       ACE_NEW_THROW_EX (id_hint_strategy,
00192                         TAO_No_Hint_Strategy,
00193                         CORBA::NO_MEMORY ());
00194     }
00195 
00196   // Give ownership to the auto pointer.
00197   auto_ptr<TAO_Id_Hint_Strategy> new_id_hint_strategy (id_hint_strategy);
00198 
00199   servant_map *sm = 0;
00200   if (unique_id_policy)
00201     {
00202       switch (creation_parameters.reverse_object_lookup_strategy_for_unique_id_policy_)
00203         {
00204         case TAO_LINEAR:
00205 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
00206           ACE_NEW_THROW_EX (sm,
00207                             servant_linear_map (
00208                               creation_parameters.active_object_map_size_),
00209                             CORBA::NO_MEMORY ());
00210           break;
00211 #else
00212           ACE_ERROR ((LM_ERROR,
00213                       "linear option for "
00214                       "-ORBUniqueidPolicyReverseDemuxStrategy "
00215                       "not supported with minimum POA maps. "
00216                       "Ingoring option to use default... \n"));
00217           /* FALL THROUGH */
00218 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
00219 
00220         case TAO_DYNAMIC_HASH:
00221         default:
00222           ACE_NEW_THROW_EX (sm,
00223                             servant_hash_map (
00224                               creation_parameters.active_object_map_size_),
00225                             CORBA::NO_MEMORY ());
00226           break;
00227         }
00228     }
00229 
00230   // Give ownership to the auto pointer.
00231   auto_ptr<servant_map> new_servant_map (sm);
00232 
00233   user_id_map *uim = 0;
00234   if (user_id_policy
00235       || creation_parameters.allow_reactivation_of_system_ids_)
00236     {
00237       switch (creation_parameters.object_lookup_strategy_for_user_id_policy_)
00238         {
00239         case TAO_LINEAR:
00240 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
00241           ACE_NEW_THROW_EX (uim,
00242                             user_id_linear_map (
00243                               creation_parameters.active_object_map_size_),
00244                             CORBA::NO_MEMORY ());
00245           break;
00246 #else
00247           ACE_ERROR ((LM_ERROR,
00248                       "linear option for -ORBUseridPolicyDemuxStrategy "
00249                       "not supported with minimum POA maps. "
00250                       "Ingoring option to use default... \n"));
00251           /* FALL THROUGH */
00252 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
00253 
00254         case TAO_DYNAMIC_HASH:
00255         default:
00256           ACE_NEW_THROW_EX (uim,
00257                             user_id_hash_map (creation_parameters.active_object_map_size_),
00258                             CORBA::NO_MEMORY ());
00259           break;
00260         }
00261     }
00262   else
00263     {
00264       switch (creation_parameters.object_lookup_strategy_for_system_id_policy_)
00265         {
00266 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
00267         case TAO_LINEAR:
00268           ACE_NEW_THROW_EX (uim,
00269                             user_id_linear_map (creation_parameters.active_object_map_size_),
00270                             CORBA::NO_MEMORY ());
00271           break;
00272 
00273         case TAO_DYNAMIC_HASH:
00274           ACE_NEW_THROW_EX (uim,
00275                             user_id_hash_map (creation_parameters.active_object_map_size_),
00276                             CORBA::NO_MEMORY ());
00277           break;
00278 #else
00279         case TAO_LINEAR:
00280         case TAO_DYNAMIC_HASH:
00281           ACE_ERROR ((LM_ERROR,
00282                       "linear and dynamic options for -ORBSystemidPolicyDemuxStrategy "
00283                       "are not supported with minimum POA maps. "
00284                       "Ingoring option to use default... \n"));
00285           /* FALL THROUGH */
00286 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
00287 
00288         case TAO_ACTIVE_DEMUX:
00289         default:
00290 
00291           this->using_active_maps_ = true;
00292 
00293           ACE_NEW_THROW_EX (uim,
00294                             user_id_active_map (creation_parameters.active_object_map_size_),
00295                             CORBA::NO_MEMORY ());
00296           break;
00297         }
00298     }
00299 
00300   // Give ownership to the auto pointer.
00301   auto_ptr<user_id_map> new_user_id_map (uim);
00302 
00303   id_uniqueness_strategy->set_active_object_map (this);
00304   lifespan_strategy->set_active_object_map (this);
00305   id_assignment_strategy->set_active_object_map (this);
00306 
00307   // Finally everything is fine.  Make sure to take ownership away
00308   // from the auto pointer.
00309   this->id_uniqueness_strategy_ = new_id_uniqueness_strategy;
00310   this->lifespan_strategy_ =  new_lifespan_strategy;
00311   this->id_assignment_strategy_ = new_id_assignment_strategy;
00312   this->id_hint_strategy_ = new_id_hint_strategy;
00313   this->servant_map_ = new_servant_map;
00314   this->user_id_map_ = new_user_id_map;
00315 
00316 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
00317   ACE_NEW (this->monitor_,
00318            ACE::Monitor_Control::Size_Monitor);
00319 #endif /* TAO_HAS_MONITOR_POINTS==1 */
00320 }
00321 
00322 TAO_Active_Object_Map::~TAO_Active_Object_Map (void)
00323 {
00324   user_id_map::iterator iterator = this->user_id_map_->begin ();
00325   user_id_map::iterator end = this->user_id_map_->end ();
00326 
00327   for (;
00328        iterator != end;
00329        ++iterator)
00330     {
00331       user_id_map::value_type map_entry = *iterator;
00332       delete map_entry.second ();
00333     }
00334 
00335 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
00336   this->monitor_->remove_from_registry ();
00337   this->monitor_->remove_ref ();
00338 #endif /* TAO_HAS_MONITOR_POINTS==1 */
00339 }
00340 
00341 bool
00342 TAO_Active_Object_Map::is_user_id_in_map (
00343   const PortableServer::ObjectId &user_id,
00344   CORBA::Short priority,
00345   bool &priorities_match,
00346   bool &deactivated)
00347 {
00348   TAO_Active_Object_Map_Entry *entry = 0;
00349   bool result = false;
00350   int const find_result = this->user_id_map_->find (user_id, entry);
00351 
00352   if (find_result == 0)
00353     {
00354       if (entry->servant_ == 0)
00355         {
00356           if (entry->priority_ != priority)
00357             {
00358               priorities_match = false;
00359             }
00360         }
00361       else
00362         {
00363           result = true;
00364 
00365           if (entry->deactivated_)
00366             {
00367               deactivated = true;
00368             }
00369         }
00370     }
00371 
00372   return result;
00373 }
00374 
00375 ////////////////////////////////////////////////////////////////////////////////
00376 
00377 TAO_Id_Uniqueness_Strategy::~TAO_Id_Uniqueness_Strategy (void)
00378 {
00379 }
00380 
00381 void
00382 TAO_Id_Uniqueness_Strategy::set_active_object_map (
00383   TAO_Active_Object_Map *active_object_map)
00384 {
00385   this->active_object_map_ = active_object_map;
00386 }
00387 
00388 int
00389 TAO_Unique_Id_Strategy::is_servant_in_map (PortableServer::Servant servant,
00390                                            bool &deactivated)
00391 {
00392   TAO_Active_Object_Map_Entry *entry = 0;
00393   int result = this->active_object_map_->servant_map_->find (servant,
00394                                                              entry);
00395   if (result == 0)
00396     {
00397       result = 1;
00398 
00399       if (entry->deactivated_)
00400         {
00401           deactivated = true;
00402         }
00403     }
00404   else
00405     {
00406       result = 0;
00407     }
00408 
00409   return result;
00410 }
00411 
00412 int
00413 TAO_Unique_Id_Strategy::bind_using_user_id (
00414   PortableServer::Servant servant,
00415   const PortableServer::ObjectId &user_id,
00416   CORBA::Short priority,
00417   TAO_Active_Object_Map_Entry *&entry)
00418 {
00419   int result =
00420     this->active_object_map_->user_id_map_->find (user_id, entry);
00421 
00422   if (result == 0)
00423     {
00424       if (servant != 0)
00425         {
00426           entry->servant_ = servant;
00427 
00428           result =
00429             this->active_object_map_->servant_map_->bind (entry->servant_,
00430                                                           entry);
00431 
00432 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
00433           if (result == 0)
00434             {
00435               this->active_object_map_->monitor_->receive (
00436                 this->active_object_map_->servant_map_->current_size ());
00437             }
00438 #endif /* TAO_HAS_MONITOR_POINTS==1 */
00439         }
00440     }
00441   else
00442     {
00443       ACE_NEW_RETURN (entry,
00444                       TAO_Active_Object_Map_Entry,
00445                       -1);
00446       entry->user_id_ = user_id;
00447       entry->servant_ = servant;
00448       entry->priority_ = priority;
00449 
00450       result = this->active_object_map_->id_hint_strategy_->bind (*entry);
00451 
00452       if (result == 0)
00453         {
00454           result =
00455             this->active_object_map_->user_id_map_->bind (entry->user_id_,
00456                                                           entry);
00457           if (result == 0)
00458             {
00459               if (servant != 0)
00460                 {
00461                   result =
00462                     this->active_object_map_->servant_map_->bind (
00463                       entry->servant_,
00464                       entry);
00465                 }
00466 
00467               if (result != 0)
00468                 {
00469                   this->active_object_map_->user_id_map_->unbind (
00470                     entry->user_id_);
00471                   this->active_object_map_->id_hint_strategy_->unbind (
00472                     *entry);
00473                   delete entry;
00474                 }
00475               else
00476                 {
00477 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
00478                   this->active_object_map_->monitor_->receive (
00479                     this->active_object_map_->servant_map_->current_size ());
00480 #endif /* TAO_HAS_MONITOR_POINTS==1 */
00481                 }
00482             }
00483           else
00484             {
00485               this->active_object_map_->id_hint_strategy_->unbind (*entry);
00486               delete entry;
00487             }
00488         }
00489       else
00490         {
00491           delete entry;
00492         }
00493     }
00494 
00495   return result;
00496 }
00497 
00498 int
00499 TAO_Unique_Id_Strategy::unbind_using_user_id (
00500   const PortableServer::ObjectId &user_id)
00501 {
00502   TAO_Active_Object_Map_Entry *entry = 0;
00503   int result = this->active_object_map_->user_id_map_->unbind (user_id,
00504                                                                entry);
00505   if (result == 0)
00506     {
00507       if (entry->servant_ != 0)
00508         {
00509           result =
00510             this->active_object_map_->servant_map_->unbind (entry->servant_);
00511         }
00512 
00513       if (result == 0)
00514         {
00515           result =
00516             this->active_object_map_->id_hint_strategy_->unbind (*entry);
00517 
00518 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
00519           this->active_object_map_->monitor_->receive (
00520             this->active_object_map_->servant_map_->current_size ());
00521 #endif /* TAO_HAS_MONITOR_POINTS==1 */
00522         }
00523 
00524       if (result == 0)
00525         {
00526           delete entry;
00527         }
00528     }
00529 
00530   return result;
00531 }
00532 
00533 int
00534 TAO_Unique_Id_Strategy::find_user_id_using_servant (
00535   PortableServer::Servant servant,
00536   PortableServer::ObjectId_out user_id)
00537 {
00538   TAO_Active_Object_Map_Entry *entry = 0;
00539   int result = this->active_object_map_->servant_map_->find (servant, entry);
00540 
00541   if (result == 0)
00542     {
00543       if (entry->deactivated_)
00544         {
00545           result = -1;
00546         }
00547       else
00548         {
00549           ACE_NEW_RETURN (user_id,
00550                           PortableServer::ObjectId (entry->user_id_),
00551                           -1);
00552         }
00553     }
00554 
00555   return result;
00556 }
00557 
00558 int
00559 TAO_Unique_Id_Strategy::find_system_id_using_servant (
00560   PortableServer::Servant servant,
00561   PortableServer::ObjectId_out system_id,
00562   CORBA::Short &priority)
00563 {
00564   TAO_Active_Object_Map_Entry *entry = 0;
00565   int result = this->active_object_map_->servant_map_->find (servant,
00566                                                              entry);
00567   if (result == 0)
00568     {
00569       if (entry->deactivated_)
00570         {
00571           result = -1;
00572         }
00573       else
00574         {
00575           result =
00576             this->active_object_map_->id_hint_strategy_->system_id (
00577               system_id,
00578               *entry);
00579           if (result == 0)
00580             {
00581               priority = entry->priority_;
00582             }
00583         }
00584     }
00585 
00586   return result;
00587 }
00588 
00589 CORBA::Boolean
00590 TAO_Unique_Id_Strategy::remaining_activations (
00591   PortableServer::Servant servant)
00592 {
00593   ACE_UNUSED_ARG (servant);
00594 
00595   // Since servant are always unique here, return false.
00596   return 0;
00597 }
00598 
00599 ////////////////////////////////////////////////////////////////////////////////
00600 
00601 #if !defined (CORBA_E_MICRO)
00602 int
00603 TAO_Multiple_Id_Strategy::is_servant_in_map (PortableServer::Servant, bool &)
00604 {
00605   return -1;
00606 }
00607 
00608 int
00609 TAO_Multiple_Id_Strategy::bind_using_user_id (
00610   PortableServer::Servant servant,
00611   const PortableServer::ObjectId &user_id,
00612   CORBA::Short priority,
00613   TAO_Active_Object_Map_Entry *&entry)
00614 {
00615   int result =
00616     this->active_object_map_->user_id_map_->find (user_id, entry);
00617 
00618   if (result == 0)
00619     {
00620       if (servant != 0)
00621         {
00622           entry->servant_ = servant;
00623         }
00624     }
00625   else
00626     {
00627       ACE_NEW_RETURN (entry,
00628                       TAO_Active_Object_Map_Entry,
00629                       -1);
00630       entry->user_id_ = user_id;
00631       entry->servant_ = servant;
00632       entry->priority_ = priority;
00633 
00634       result =
00635         this->active_object_map_->id_hint_strategy_->bind (*entry);
00636 
00637       if (result == 0)
00638         {
00639           result =
00640             this->active_object_map_->user_id_map_->bind (entry->user_id_,
00641                                                           entry);
00642           if (result != 0)
00643             {
00644               this->active_object_map_->id_hint_strategy_->unbind (*entry);
00645               delete entry;
00646             }
00647           else
00648             {
00649 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
00650               this->active_object_map_->monitor_->receive (
00651                 this->active_object_map_->user_id_map_->current_size ());
00652 #endif /* TAO_HAS_MONITOR_POINTS==1 */
00653             }
00654         }
00655       else
00656         {
00657           delete entry;
00658         }
00659     }
00660 
00661   return result;
00662 }
00663 
00664 int
00665 TAO_Multiple_Id_Strategy::unbind_using_user_id (
00666   const PortableServer::ObjectId &user_id)
00667 {
00668   TAO_Active_Object_Map_Entry *entry = 0;
00669   int result = this->active_object_map_->user_id_map_->unbind (user_id,
00670                                                                entry);
00671   if (result == 0)
00672     {
00673       result = this->active_object_map_->id_hint_strategy_->unbind (*entry);
00674 
00675       if (result == 0)
00676         {
00677           delete entry;
00678         }
00679 
00680 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
00681               this->active_object_map_->monitor_->receive (
00682                 this->active_object_map_->user_id_map_->current_size ());
00683 #endif /* TAO_HAS_MONITOR_POINTS==1 */
00684     }
00685 
00686   return result;
00687 }
00688 
00689 int
00690 TAO_Multiple_Id_Strategy::find_user_id_using_servant (
00691   PortableServer::Servant,
00692   PortableServer::ObjectId_out)
00693 {
00694   return -1;
00695 }
00696 
00697 int
00698 TAO_Multiple_Id_Strategy::find_system_id_using_servant (
00699   PortableServer::Servant,
00700   PortableServer::ObjectId_out,
00701   CORBA::Short &)
00702 {
00703   return -1;
00704 }
00705 
00706 CORBA::Boolean
00707 TAO_Multiple_Id_Strategy::remaining_activations (
00708   PortableServer::Servant servant)
00709 {
00710   TAO_Active_Object_Map::user_id_map::iterator end =
00711     this->active_object_map_->user_id_map_->end ();
00712 
00713   for (TAO_Active_Object_Map::user_id_map::iterator iter =
00714          this->active_object_map_->user_id_map_->begin ();
00715        iter != end;
00716        ++iter)
00717     {
00718       TAO_Active_Object_Map::user_id_map::value_type map_pair = *iter;
00719       TAO_Active_Object_Map_Entry *entry = map_pair.second ();
00720 
00721       if (entry->servant_ == servant)
00722         {
00723           return 1;
00724         }
00725     }
00726 
00727   return 0;
00728 }
00729 #endif
00730 
00731 TAO_Lifespan_Strategy::~TAO_Lifespan_Strategy (void)
00732 {
00733 }
00734 
00735 void
00736 TAO_Lifespan_Strategy::set_active_object_map (
00737   TAO_Active_Object_Map *active_object_map)
00738 {
00739   this->active_object_map_ = active_object_map;
00740 }
00741 
00742 int
00743 TAO_Transient_Strategy::find_servant_using_system_id_and_user_id (
00744   const PortableServer::ObjectId &system_id,
00745   const PortableServer::ObjectId &user_id,
00746   PortableServer::Servant &servant,
00747   TAO_Active_Object_Map_Entry *&entry)
00748 {
00749   int result = this->active_object_map_->id_hint_strategy_->find (system_id,
00750                                                                   entry);
00751   if (result == 0)
00752     {
00753       if (entry->deactivated_)
00754         {
00755           result = -1;
00756         }
00757       else if (entry->servant_ == 0)
00758         {
00759           result = -1;
00760         }
00761       else
00762         {
00763           servant = entry->servant_;
00764         }
00765     }
00766   else
00767     {
00768       result = this->active_object_map_->user_id_map_->find (user_id,
00769                                                              entry);
00770       if (result == 0)
00771         {
00772           if (entry->deactivated_)
00773             {
00774               result = -1;
00775             }
00776           else if (entry->servant_ == 0)
00777             {
00778               result = -1;
00779             }
00780           else
00781             {
00782               servant = entry->servant_;
00783             }
00784         }
00785     }
00786 
00787   if (result == -1)
00788     {
00789       entry = 0;
00790     }
00791 
00792   return result;
00793 }
00794 
00795 ////////////////////////////////////////////////////////////////////////////////
00796 
00797 #if !defined (CORBA_E_MICRO)
00798 int
00799 TAO_Persistent_Strategy::find_servant_using_system_id_and_user_id (
00800   const PortableServer::ObjectId &system_id,
00801   const PortableServer::ObjectId &user_id,
00802   PortableServer::Servant &servant,
00803 TAO_Active_Object_Map_Entry *&entry)
00804 {
00805   int result =
00806     this->active_object_map_->id_hint_strategy_->find (system_id,
00807                                                        entry);
00808   if (result == 0 && user_id == entry->user_id_)
00809     {
00810       if (entry->deactivated_)
00811         {
00812           result = -1;
00813         }
00814       else if (entry->servant_ == 0)
00815         {
00816           result = -1;
00817         }
00818       else
00819         {
00820           servant = entry->servant_;
00821         }
00822     }
00823   else
00824     {
00825       result =
00826         this->active_object_map_->user_id_map_->find (user_id, entry);
00827 
00828       if (result == 0)
00829         {
00830           if (entry->deactivated_)
00831             {
00832               result = -1;
00833             }
00834           else if (entry->servant_ == 0)
00835             {
00836               result = -1;
00837             }
00838           else
00839             {
00840               servant = entry->servant_;
00841             }
00842         }
00843     }
00844 
00845   if (result == -1)
00846     {
00847       entry = 0;
00848     }
00849 
00850   return result;
00851 }
00852 #endif
00853 
00854 TAO_Id_Assignment_Strategy::~TAO_Id_Assignment_Strategy (void)
00855 {
00856 }
00857 
00858 void
00859 TAO_Id_Assignment_Strategy::set_active_object_map (
00860   TAO_Active_Object_Map *active_object_map)
00861 {
00862   this->active_object_map_ = active_object_map;
00863 }
00864 
00865 #if !defined (CORBA_E_MICRO)
00866 int
00867 TAO_User_Id_Strategy::bind_using_system_id (PortableServer::Servant,
00868                                             CORBA::Short,
00869                                             TAO_Active_Object_Map_Entry *&)
00870 {
00871   return -1;
00872 }
00873 #endif
00874 
00875 int
00876 TAO_System_Id_With_Unique_Id_Strategy::bind_using_system_id (
00877   PortableServer::Servant servant,
00878   CORBA::Short priority,
00879   TAO_Active_Object_Map_Entry *&entry)
00880 {
00881   ACE_NEW_RETURN (entry,
00882                   TAO_Active_Object_Map_Entry,
00883                   -1);
00884 
00885   int result =
00886     this->active_object_map_->user_id_map_->bind_create_key (entry,
00887                                                              entry->user_id_);
00888   if (result == 0)
00889     {
00890       entry->servant_ = servant;
00891       entry->priority_ = priority;
00892 
00893       result = this->active_object_map_->id_hint_strategy_->bind (*entry);
00894 
00895       if (result == 0)
00896         {
00897           if (servant != 0)
00898             {
00899               result =
00900                 this->active_object_map_->servant_map_->bind (entry->servant_,
00901                                                               entry);
00902             }
00903 
00904           if (result != 0)
00905             {
00906               this->active_object_map_->user_id_map_->unbind (entry->user_id_);
00907               this->active_object_map_->id_hint_strategy_->unbind (*entry);
00908               delete entry;
00909             }
00910           else
00911             {
00912 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
00913               this->active_object_map_->monitor_->receive (
00914                 this->active_object_map_->servant_map_->current_size ());
00915 #endif /* TAO_HAS_MONITOR_POINTS==1 */
00916             }
00917         }
00918       else
00919         {
00920           this->active_object_map_->user_id_map_->unbind (entry->user_id_);
00921           delete entry;
00922         }
00923     }
00924   else
00925     {
00926       delete entry;
00927     }
00928 
00929   return result;
00930 }
00931 
00932 #if !defined (CORBA_E_MICRO)
00933 int
00934 TAO_System_Id_With_Multiple_Id_Strategy::bind_using_system_id (
00935   PortableServer::Servant servant,
00936   CORBA::Short priority,
00937   TAO_Active_Object_Map_Entry *&entry)
00938 {
00939   ACE_NEW_RETURN (entry,
00940                   TAO_Active_Object_Map_Entry,
00941                   -1);
00942   int result =
00943     this->active_object_map_->user_id_map_->bind_create_key (entry,
00944                                                              entry->user_id_);
00945   if (result == 0)
00946     {
00947       entry->servant_ = servant;
00948       entry->priority_ = priority;
00949 
00950       result = this->active_object_map_->id_hint_strategy_->bind (*entry);
00951 
00952       if (result != 0)
00953         {
00954           this->active_object_map_->user_id_map_->unbind (entry->user_id_);
00955           delete entry;
00956         }
00957 
00958 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
00959       this->active_object_map_->monitor_->receive (
00960         this->active_object_map_->user_id_map_->current_size ());
00961 #endif /* TAO_HAS_MONITOR_POINTS==1 */
00962     }
00963   else
00964     {
00965       delete entry;
00966     }
00967 
00968   return result;
00969 }
00970 #endif
00971 
00972 ////////////////////////////////////////////////////////////////////////////////
00973 
00974 TAO_Id_Hint_Strategy::~TAO_Id_Hint_Strategy (void)
00975 {
00976 }
00977 
00978 ////////////////////////////////////////////////////////////////////////////////
00979 
00980 TAO_Active_Hint_Strategy::TAO_Active_Hint_Strategy (CORBA::ULong map_size)
00981   : system_id_map_ (map_size)
00982 {
00983 }
00984 
00985 TAO_Active_Hint_Strategy::~TAO_Active_Hint_Strategy (void)
00986 {
00987 }
00988 
00989 int
00990 TAO_Active_Hint_Strategy::recover_key (
00991   const PortableServer::ObjectId &system_id,
00992   PortableServer::ObjectId &user_id)
00993 {
00994   return this->system_id_map_.recover_key (system_id, user_id);
00995 }
00996 
00997 int
00998 TAO_Active_Hint_Strategy::bind (TAO_Active_Object_Map_Entry &entry)
00999 {
01000   entry.system_id_ = entry.user_id_;
01001 
01002   return this->system_id_map_.bind_modify_key (&entry,
01003                                                entry.system_id_);
01004 }
01005 
01006 int
01007 TAO_Active_Hint_Strategy::unbind (TAO_Active_Object_Map_Entry &entry)
01008 {
01009   return this->system_id_map_.unbind (entry.system_id_);
01010 }
01011 
01012 int
01013 TAO_Active_Hint_Strategy::find (const PortableServer::ObjectId &system_id,
01014                                 TAO_Active_Object_Map_Entry *&entry)
01015 {
01016   return this->system_id_map_.find (system_id,
01017                                     entry);
01018 }
01019 
01020 size_t
01021 TAO_Active_Hint_Strategy::hint_size (void)
01022 {
01023   return ACE_Active_Map_Manager_Key::size ();
01024 }
01025 
01026 int
01027 TAO_Active_Hint_Strategy::system_id (PortableServer::ObjectId_out system_id,
01028                                      TAO_Active_Object_Map_Entry &entry)
01029 {
01030   ACE_NEW_RETURN (system_id,
01031                   PortableServer::ObjectId (entry.system_id_),
01032                   -1);
01033   return 0;
01034 }
01035 
01036 ////////////////////////////////////////////////////////////////////////////////
01037 
01038 TAO_No_Hint_Strategy::~TAO_No_Hint_Strategy (void)
01039 {
01040 }
01041 
01042 int
01043 TAO_No_Hint_Strategy::recover_key (const PortableServer::ObjectId &system_id,
01044                                    PortableServer::ObjectId &user_id)
01045 {
01046   // Smartly copy all the data; <user_id does not own the data>.
01047   user_id.replace (system_id.maximum (),
01048                    system_id.length (),
01049                    const_cast<CORBA::Octet *> (system_id.get_buffer ()),
01050                    0);
01051 
01052   return 0;
01053 }
01054 
01055 int
01056 TAO_No_Hint_Strategy::bind (TAO_Active_Object_Map_Entry &)
01057 {
01058   return 0;
01059 }
01060 
01061 int
01062 TAO_No_Hint_Strategy::unbind (TAO_Active_Object_Map_Entry &)
01063 {
01064   return 0;
01065 }
01066 
01067 int
01068 TAO_No_Hint_Strategy::find (const PortableServer::ObjectId &,
01069                             TAO_Active_Object_Map_Entry *&)
01070 {
01071   return -1;
01072 }
01073 
01074 size_t
01075 TAO_No_Hint_Strategy::hint_size (void)
01076 {
01077   return 0;
01078 }
01079 
01080 int
01081 TAO_No_Hint_Strategy::system_id (PortableServer::ObjectId_out system_id,
01082                                  TAO_Active_Object_Map_Entry &entry)
01083 {
01084   ACE_NEW_RETURN (system_id,
01085                   PortableServer::ObjectId (entry.user_id_),
01086                   -1);
01087   return 0;
01088 }
01089 
01090 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:40:53 2010 for TAO_PortableServer by  doxygen 1.4.7