00001
00002
00003 #include "tao/RTPortableServer/RT_POA.h"
00004
00005 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00006
00007 #include "tao/RTPortableServer/RT_Acceptor_Filters.h"
00008
00009 #include "tao/ORB_Core.h"
00010 #include "tao/ORB.h"
00011 #include "tao/Server_Strategy_Factory.h"
00012 #include "tao/Exception.h"
00013 #include "tao/Stub.h"
00014 #include "tao/Policy_Manager.h"
00015 #include "tao/debug.h"
00016 #include "tao/RTCORBA/Thread_Pool.h"
00017 #include "tao/Thread_Lane_Resources.h"
00018 #include "tao/Acceptor_Registry.h"
00019 #include "tao/Thread_Lane_Resources.h"
00020 #include "tao/Thread_Lane_Resources_Manager.h"
00021
00022 #include "tao/RTCORBA/RT_Policy_i.h"
00023
00024 #include "tao/PortableServer/Default_Acceptor_Filter.h"
00025 #include "tao/RTPortableServer/RT_Policy_Validator.h"
00026
00027 #include "ace/Auto_Ptr.h"
00028
00029 #if !defined (__ACE_INLINE__)
00030 # include "tao/RTPortableServer/RT_POA.inl"
00031 #endif
00032
00033 ACE_RCSID (RTPortableServer,
00034 RT_POA,
00035 "$Id: RT_POA.cpp 77155 2007-02-15 15:23:19Z johnnyw $")
00036
00037 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00038
00039 TAO_RT_POA::TAO_RT_POA (const TAO_Root_POA::String &name,
00040 PortableServer::POAManager_ptr poa_manager,
00041 const TAO_POA_Policy_Set &policies,
00042 TAO_Root_POA *parent,
00043 ACE_Lock &lock,
00044 TAO_SYNCH_MUTEX &thread_lock,
00045 TAO_ORB_Core &orb_core,
00046 TAO_Object_Adapter *object_adapter
00047 )
00048 : TAO_Regular_POA (name,
00049 poa_manager,
00050 policies,
00051 parent,
00052 lock,
00053 thread_lock,
00054 orb_core,
00055 object_adapter),
00056 thread_pool_ (0)
00057 {
00058
00059 this->parse_rt_policies (this->policies ());
00060 }
00061
00062 TAO_RT_POA::~TAO_RT_POA (void)
00063 {
00064 }
00065
00066 TAO_Root_POA *
00067 TAO_RT_POA::new_POA (const String &name,
00068 PortableServer::POAManager_ptr poa_manager,
00069 const TAO_POA_Policy_Set &policies,
00070 TAO_Root_POA *parent,
00071 ACE_Lock &lock,
00072 TAO_SYNCH_MUTEX &thread_lock,
00073 TAO_ORB_Core &orb_core,
00074 TAO_Object_Adapter *object_adapter)
00075 {
00076 TAO_RT_POA *poa = 0;
00077
00078 ACE_NEW_THROW_EX (poa,
00079 TAO_RT_POA (name,
00080 poa_manager,
00081 policies,
00082 parent,
00083 lock,
00084 thread_lock,
00085 orb_core,
00086 object_adapter
00087 ),
00088 CORBA::NO_MEMORY ());
00089
00090 return poa;
00091 }
00092
00093 void
00094 TAO_RT_POA::parse_rt_policies (TAO_POA_Policy_Set &policies)
00095 {
00096 {
00097 CORBA::Policy_var policy =
00098 policies.get_cached_policy (TAO_CACHED_POLICY_PRIORITY_MODEL);
00099
00100 RTCORBA::PriorityModelPolicy_var priority_model =
00101 RTCORBA::PriorityModelPolicy::_narrow (policy.in ());
00102
00103 if (!CORBA::is_nil (priority_model.in ()))
00104 {
00105 RTCORBA::PriorityModel rt_priority_model =
00106 priority_model->priority_model ();
00107
00108 this->cached_policies_.priority_model (
00109 TAO::Portable_Server::Cached_Policies::PriorityModel (rt_priority_model));
00110
00111 RTCORBA::Priority priority =
00112 priority_model->server_priority ();
00113
00114 this->cached_policies_.server_priority (priority);
00115 }
00116 }
00117
00118 this->thread_pool_ =
00119 TAO_POA_RT_Policy_Validator::extract_thread_pool (this->orb_core_,
00120 policies.policies ());
00121 }
00122
00123 void
00124 TAO_RT_POA::validate_priority (RTCORBA::Priority priority)
00125 {
00126 if (priority < RTCORBA::minPriority
00127
00128
00129
00130
00131 )
00132 {
00133 throw ::CORBA::BAD_PARAM ();
00134 }
00135
00136
00137
00138
00139
00140
00141 if (this->thread_pool_ != 0 && this->thread_pool_->with_lanes ())
00142 {
00143 TAO_Thread_Lane **lanes = this->thread_pool_->lanes ();
00144
00145 for (CORBA::ULong i = 0;
00146 i != this->thread_pool_->number_of_lanes ();
00147 ++i)
00148 {
00149 if (lanes[i]->lane_priority () == priority)
00150 return;
00151 }
00152
00153 throw ::CORBA::BAD_PARAM ();
00154 }
00155 else
00156
00157 {
00158
00159 CORBA::Policy_var bands =
00160 this->policies ().get_cached_policy (
00161 TAO_CACHED_POLICY_RT_PRIORITY_BANDED_CONNECTION);
00162
00163 RTCORBA::PriorityBandedConnectionPolicy_var priority_bands
00164 = RTCORBA::PriorityBandedConnectionPolicy::_narrow (bands.in ());
00165
00166 TAO_PriorityBandedConnectionPolicy *priority_bands_i =
00167 dynamic_cast <TAO_PriorityBandedConnectionPolicy *>
00168 (priority_bands.in ());
00169
00170 if (priority_bands_i)
00171 {
00172
00173
00174 RTCORBA::PriorityBands &bands =
00175 priority_bands_i->priority_bands_rep ();
00176
00177 for (CORBA::ULong i = 0;
00178 i < bands.length ();
00179 ++i)
00180 {
00181 if (bands[i].low <= priority &&
00182 bands[i].high >= priority)
00183 return;
00184 }
00185
00186 throw ::CORBA::BAD_PARAM ();
00187 }
00188 }
00189 }
00190
00191 void
00192 TAO_RT_POA::validate_policies (void)
00193 {
00194
00195
00196
00197
00198
00199
00200 if (this->cached_policies_.implicit_activation () ==
00201 PortableServer::IMPLICIT_ACTIVATION)
00202 {
00203 throw PortableServer::POA::WrongPolicy ();
00204 }
00205
00206
00207
00208
00209 if (this->cached_policies_.priority_model () !=
00210 TAO::Portable_Server::Cached_Policies::SERVER_DECLARED)
00211 {
00212 throw PortableServer::POA::WrongPolicy ();
00213 }
00214
00215
00216
00217
00218
00219 }
00220
00221 TAO_Stub *
00222 TAO_RT_POA::key_to_stub_i (const TAO::ObjectKey &object_key,
00223 const char *type_id,
00224 CORBA::Short priority)
00225 {
00226
00227 CORBA::PolicyList_var client_exposed_policies =
00228 this->client_exposed_policies (priority);
00229
00230
00231 CORBA::Policy_var protocol =
00232 this->policies ().get_cached_policy (TAO_CACHED_POLICY_RT_SERVER_PROTOCOL);
00233
00234 RTCORBA::ServerProtocolPolicy_var server_protocol_policy =
00235 RTCORBA::ServerProtocolPolicy::_narrow (protocol.in ());
00236
00237 TAO_ServerProtocolPolicy *server_protocol =
00238 dynamic_cast <TAO_ServerProtocolPolicy *> (server_protocol_policy.in ());
00239
00240
00241 TAO_Server_Protocol_Acceptor_Filter filter (server_protocol->protocols_rep ());
00242
00243
00244
00245
00246 if (this->thread_pool_ == 0 ||
00247 !this->thread_pool_->with_lanes ())
00248 {
00249 TAO_Acceptor_Registry *acceptor_registry = 0;
00250
00251 if (this->thread_pool_ == 0)
00252 {
00253 TAO_Thread_Lane_Resources_Manager &thread_lane_resources_manager =
00254 this->orb_core_.thread_lane_resources_manager ();
00255
00256 TAO_Thread_Lane_Resources &resources =
00257 thread_lane_resources_manager.default_lane_resources ();
00258
00259 acceptor_registry = &resources.acceptor_registry ();
00260 }
00261 else
00262 {
00263 TAO_Thread_Lane **lanes = this->thread_pool_->lanes ();
00264
00265 TAO_Thread_Lane_Resources &resources = lanes[0]->resources ();
00266
00267 acceptor_registry = &resources.acceptor_registry ();
00268 }
00269
00270 return
00271 this->TAO_Regular_POA::create_stub_object (object_key,
00272 type_id,
00273 client_exposed_policies._retn (),
00274 &filter,
00275 *acceptor_registry);
00276 }
00277
00278
00279
00280
00281 if (this->cached_policies_.priority_model () ==
00282 TAO::Portable_Server::Cached_Policies::SERVER_DECLARED)
00283 {
00284 TAO_Thread_Lane **lanes =
00285 this->thread_pool_->lanes ();
00286
00287 for (CORBA::ULong i = 0;
00288 i != this->thread_pool_->number_of_lanes ();
00289 ++i)
00290 {
00291 if (lanes[i]->lane_priority () == priority)
00292 return this->TAO_Regular_POA::create_stub_object (object_key,
00293 type_id,
00294 client_exposed_policies._retn (),
00295 &filter,
00296 lanes[i]->resources ().acceptor_registry ()
00297 );
00298 }
00299
00300 ACE_ASSERT (0);
00301 }
00302
00303
00304
00305
00306 CORBA::Policy_var bands =
00307 this->policies ().get_cached_policy (
00308 TAO_CACHED_POLICY_RT_PRIORITY_BANDED_CONNECTION
00309 );
00310
00311 RTCORBA::PriorityBandedConnectionPolicy_var priority_bands
00312 = RTCORBA::PriorityBandedConnectionPolicy::_narrow (bands.in ());
00313
00314 TAO_PriorityBandedConnectionPolicy *priority_bands_i =
00315 dynamic_cast <TAO_PriorityBandedConnectionPolicy *> (priority_bands.in ());
00316
00317 return this->create_stub_object (object_key,
00318 type_id,
00319 client_exposed_policies._retn (),
00320 &filter,
00321 priority_bands_i);
00322 }
00323
00324 TAO_Stub *
00325 TAO_RT_POA::create_stub_object (const TAO::ObjectKey &object_key,
00326 const char *type_id,
00327 CORBA::PolicyList *policy_list,
00328 TAO_Acceptor_Filter *filter,
00329 TAO_PriorityBandedConnectionPolicy *priority_bands)
00330 {
00331 int error = 0;
00332
00333
00334 size_t profile_count =
00335 this->endpoint_count ();
00336
00337
00338
00339 TAO_MProfile mprofile (0);
00340
00341
00342
00343
00344 int result =
00345 mprofile.set (static_cast <CORBA::ULong> (profile_count));
00346 if (result == -1)
00347 error = 1;
00348
00349 TAO_Thread_Lane **lanes =
00350 this->thread_pool_->lanes ();
00351
00352
00353
00354 for (CORBA::ULong i = 0;
00355 i != this->thread_pool_->number_of_lanes () &&
00356 !error;
00357 ++i)
00358 {
00359 if (this->lane_required (lanes[i],
00360 priority_bands))
00361 {
00362 TAO_Acceptor_Registry &acceptor_registry =
00363 lanes[i]->resources ().acceptor_registry ();
00364
00365 result =
00366 filter->fill_profile (object_key,
00367 mprofile,
00368 acceptor_registry.begin (),
00369 acceptor_registry.end (),
00370 lanes[i]->lane_priority ());
00371 if (result == -1)
00372 error = 1;
00373 }
00374 }
00375
00376 if (!error)
00377 result = filter->encode_endpoints (mprofile);
00378 if (result == -1)
00379 error = 1;
00380
00381 if (error)
00382 throw ::CORBA::INTERNAL (
00383 CORBA::SystemException::_tao_minor_code (
00384 TAO_MPROFILE_CREATION_ERROR,
00385 0),
00386 CORBA::COMPLETED_NO);
00387
00388
00389
00390
00391 if (mprofile.profile_count () == 0)
00392 throw ::CORBA::BAD_PARAM (
00393 CORBA::SystemException::_tao_minor_code (
00394 TAO_MPROFILE_CREATION_ERROR,
00395 0),
00396 CORBA::COMPLETED_NO);
00397
00398 return
00399 this->orb_core_.create_stub_object (mprofile, type_id, policy_list);
00400 }
00401
00402 size_t
00403 TAO_RT_POA::endpoint_count (void)
00404 {
00405 size_t profile_count = 0;
00406
00407 TAO_Thread_Lane **lanes =
00408 this->thread_pool_->lanes ();
00409
00410 for (CORBA::ULong i = 0;
00411 i != this->thread_pool_->number_of_lanes ();
00412 ++i)
00413 profile_count +=
00414 lanes[i]->resources ().acceptor_registry ().endpoint_count ();
00415
00416 return profile_count;
00417 }
00418
00419 int
00420 TAO_RT_POA::lane_required (TAO_Thread_Lane *lane,
00421 TAO_PriorityBandedConnectionPolicy *priority_bands)
00422 {
00423 if (priority_bands == 0)
00424 return 1;
00425
00426 RTCORBA::PriorityBands &bands =
00427 priority_bands->priority_bands_rep ();
00428
00429 for (CORBA::ULong i = 0;
00430 i < bands.length ();
00431 ++i)
00432 {
00433 if (bands[i].low <= lane->lane_priority () &&
00434 bands[i].high >= lane->lane_priority ())
00435 return 1;
00436 }
00437
00438 return 0;
00439 }
00440
00441 CORBA::PolicyList *
00442 TAO_RT_POA::client_exposed_policies (CORBA::Short object_priority)
00443 {
00444 CORBA::PolicyList *client_exposed_policies = 0;
00445 ACE_NEW_THROW_EX (client_exposed_policies,
00446 CORBA::PolicyList (),
00447 CORBA::NO_MEMORY (TAO::VMCID,
00448 CORBA::COMPLETED_NO));
00449
00450 CORBA::PolicyList_var safe_client_exposed_policies = client_exposed_policies;
00451
00452
00453 this->policies_.add_client_exposed_fixed_policies (client_exposed_policies);
00454
00455
00456
00457 CORBA::Short poa_priority =
00458 this->cached_policies_.server_priority ();
00459
00460 if (poa_priority != TAO_INVALID_PRIORITY)
00461 {
00462 TAO::Portable_Server::Cached_Policies::PriorityModel priority_model =
00463 this->cached_policies_.priority_model ();
00464
00465
00466
00467
00468
00469 CORBA::Short priority;
00470 if (priority_model == TAO::Portable_Server::Cached_Policies::CLIENT_PROPAGATED)
00471 priority = poa_priority;
00472 else
00473 priority = object_priority;
00474
00475 const CORBA::ULong current_length =
00476 client_exposed_policies->length ();
00477 client_exposed_policies->length (current_length + 1);
00478
00479 TAO_PriorityModelPolicy *priority_model_policy;
00480 ACE_NEW_THROW_EX (priority_model_policy,
00481 TAO_PriorityModelPolicy (RTCORBA::PriorityModel (priority_model),
00482 priority),
00483 CORBA::NO_MEMORY (TAO::VMCID,
00484 CORBA::COMPLETED_NO));
00485
00486 (*client_exposed_policies)[current_length] = priority_model_policy;
00487 }
00488
00489 return safe_client_exposed_policies._retn ();
00490 }
00491
00492
00493
00494 PortableServer::POA_ptr
00495 TAO_RT_POA::create_POA (const char *adapter_name,
00496 PortableServer::POAManager_ptr poa_manager,
00497 const CORBA::PolicyList &policies)
00498 {
00499 return this->TAO_Regular_POA::create_POA (adapter_name, poa_manager, policies);
00500 }
00501
00502 PortableServer::POA_ptr
00503 TAO_RT_POA::find_POA (const char *adapter_name, CORBA::Boolean activate_it)
00504 {
00505 return this->TAO_Regular_POA::find_POA (adapter_name, activate_it);
00506 }
00507
00508 void
00509 TAO_RT_POA::destroy (CORBA::Boolean etherealize_objects,
00510 CORBA::Boolean wait_for_completion)
00511 {
00512 this->TAO_Regular_POA::destroy (etherealize_objects, wait_for_completion);
00513 }
00514
00515
00516 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00517
00518 PortableServer::ThreadPolicy_ptr
00519 TAO_RT_POA::create_thread_policy (PortableServer::ThreadPolicyValue value)
00520 {
00521 return this->TAO_Regular_POA::create_thread_policy (value);
00522 }
00523
00524 #endif
00525
00526 #if !defined (CORBA_E_MICRO)
00527 PortableServer::LifespanPolicy_ptr
00528 TAO_RT_POA::create_lifespan_policy (PortableServer::LifespanPolicyValue value)
00529 {
00530 return this->TAO_Regular_POA::create_lifespan_policy (value);
00531 }
00532 #endif
00533
00534 #if !defined (CORBA_E_MICRO)
00535 PortableServer::IdUniquenessPolicy_ptr
00536 TAO_RT_POA::create_id_uniqueness_policy (PortableServer::IdUniquenessPolicyValue value)
00537 {
00538 return this->TAO_Regular_POA::create_id_uniqueness_policy (value);
00539 }
00540 #endif
00541
00542 #if !defined (CORBA_E_MICRO)
00543 PortableServer::IdAssignmentPolicy_ptr
00544 TAO_RT_POA::create_id_assignment_policy (PortableServer::IdAssignmentPolicyValue value)
00545 {
00546 return this->TAO_Regular_POA::create_id_assignment_policy (value);
00547 }
00548 #endif
00549
00550 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00551
00552 PortableServer::ImplicitActivationPolicy_ptr
00553 TAO_RT_POA::create_implicit_activation_policy (
00554 PortableServer::ImplicitActivationPolicyValue value)
00555 {
00556 return this->TAO_Regular_POA::create_implicit_activation_policy (value);
00557 }
00558
00559 PortableServer::ServantRetentionPolicy_ptr
00560 TAO_RT_POA::create_servant_retention_policy (
00561 PortableServer::ServantRetentionPolicyValue value)
00562 {
00563 return this->TAO_Regular_POA::create_servant_retention_policy (value);
00564 }
00565
00566
00567 PortableServer::RequestProcessingPolicy_ptr
00568 TAO_RT_POA::create_request_processing_policy (
00569 PortableServer::RequestProcessingPolicyValue value)
00570 {
00571 return this->TAO_Regular_POA::create_request_processing_policy (value);
00572 }
00573
00574 #endif
00575
00576 char *
00577 TAO_RT_POA::the_name (void)
00578 {
00579 return this->TAO_Regular_POA::the_name ();
00580 }
00581
00582 PortableServer::POA_ptr
00583 TAO_RT_POA::the_parent (void)
00584 {
00585 return this->TAO_Regular_POA::the_parent ();
00586 }
00587
00588 PortableServer::POAList *
00589 TAO_RT_POA::the_children (void)
00590 {
00591 return this->TAO_Regular_POA::the_children ();
00592 }
00593
00594 PortableServer::POAManager_ptr
00595 TAO_RT_POA::the_POAManager (void)
00596 {
00597 return this->TAO_Regular_POA::the_POAManager ();
00598 }
00599
00600
00601 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00602
00603 PortableServer::AdapterActivator_ptr
00604 TAO_RT_POA::the_activator (void)
00605 {
00606 return this->TAO_Regular_POA::the_activator ();;
00607 }
00608
00609 void
00610 TAO_RT_POA::the_activator (PortableServer::AdapterActivator_ptr adapter_activator)
00611 {
00612 this->TAO_Regular_POA::the_activator (adapter_activator);
00613 }
00614
00615 PortableServer::ServantManager_ptr
00616 TAO_RT_POA::get_servant_manager (void)
00617 {
00618 return this->TAO_Regular_POA::get_servant_manager ();
00619 }
00620
00621 void
00622 TAO_RT_POA::set_servant_manager (PortableServer::ServantManager_ptr imgr)
00623 {
00624 this->TAO_Regular_POA::set_servant_manager (imgr);
00625 }
00626
00627 PortableServer::Servant
00628 TAO_RT_POA::get_servant (void)
00629 {
00630 return this->TAO_Regular_POA::get_servant ();
00631 }
00632
00633 void
00634 TAO_RT_POA::set_servant (PortableServer::Servant servant)
00635 {
00636 this->TAO_Regular_POA::set_servant (servant);
00637 }
00638
00639 #endif
00640
00641 PortableServer::ObjectId *
00642 TAO_RT_POA::activate_object (PortableServer::Servant p_servant)
00643 {
00644 return this->TAO_Regular_POA::activate_object (p_servant);
00645 }
00646
00647 #if !defined (CORBA_E_MICRO)
00648 void
00649 TAO_RT_POA::activate_object_with_id (const PortableServer::ObjectId &id,
00650 PortableServer::Servant p_servant)
00651 {
00652 this->TAO_Regular_POA::activate_object_with_id (id, p_servant);
00653 }
00654 #endif
00655
00656 void
00657 TAO_RT_POA::deactivate_object (const PortableServer::ObjectId &oid)
00658 {
00659 this->TAO_Regular_POA::deactivate_object (oid);
00660 }
00661
00662 CORBA::Object_ptr
00663 TAO_RT_POA::create_reference (const char *intf)
00664 {
00665 return this->TAO_Regular_POA::create_reference (intf);
00666 }
00667
00668 CORBA::Object_ptr
00669 TAO_RT_POA::create_reference_with_id (const PortableServer::ObjectId &oid,
00670 const char *intf)
00671 {
00672 return this->TAO_Regular_POA::create_reference_with_id (oid, intf);
00673 }
00674
00675 PortableServer::ObjectId *
00676 TAO_RT_POA::servant_to_id (PortableServer::Servant p_servant)
00677 {
00678 return this->TAO_Regular_POA::servant_to_id (p_servant);
00679 }
00680
00681 CORBA::Object_ptr
00682 TAO_RT_POA::servant_to_reference (PortableServer::Servant p_servant)
00683 {
00684 return this->TAO_Regular_POA::servant_to_reference (p_servant);
00685 }
00686
00687 PortableServer::Servant
00688 TAO_RT_POA::reference_to_servant (CORBA::Object_ptr reference)
00689 {
00690 return this->TAO_Regular_POA::reference_to_servant (reference);
00691 }
00692
00693 PortableServer::ObjectId *
00694 TAO_RT_POA::reference_to_id (CORBA::Object_ptr reference)
00695 {
00696 return this->TAO_Regular_POA::reference_to_id (reference);
00697 }
00698
00699 PortableServer::Servant
00700 TAO_RT_POA::id_to_servant (const PortableServer::ObjectId &oid)
00701 {
00702 return this->TAO_Regular_POA::id_to_servant (oid);
00703 }
00704
00705 CORBA::Object_ptr
00706 TAO_RT_POA::id_to_reference (const PortableServer::ObjectId &oid)
00707 {
00708 return this->TAO_Regular_POA::id_to_reference (oid);
00709 }
00710
00711 CORBA::OctetSeq *
00712 TAO_RT_POA::id (void)
00713 {
00714 return this->TAO_Regular_POA::id ();
00715 }
00716
00717 TAO_END_VERSIONED_NAMESPACE_DECL
00718
00719 #endif