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 83337 2008-10-21 09:10:54Z 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 bool error = false;
00332
00333
00334 size_t const profile_count = this->endpoint_count ();
00335
00336
00337
00338 TAO_MProfile mprofile (0);
00339
00340
00341
00342
00343 int result =
00344 mprofile.set (static_cast <CORBA::ULong> (profile_count));
00345 if (result == -1)
00346 error = true;
00347
00348 TAO_Thread_Lane **lanes =
00349 this->thread_pool_->lanes ();
00350
00351
00352
00353 for (CORBA::ULong i = 0;
00354 i != this->thread_pool_->number_of_lanes () &&
00355 !error;
00356 ++i)
00357 {
00358 if (this->lane_required (lanes[i],
00359 priority_bands))
00360 {
00361 TAO_Acceptor_Registry &acceptor_registry =
00362 lanes[i]->resources ().acceptor_registry ();
00363
00364 result =
00365 filter->fill_profile (object_key,
00366 mprofile,
00367 acceptor_registry.begin (),
00368 acceptor_registry.end (),
00369 lanes[i]->lane_priority ());
00370 if (result == -1)
00371 error = true;
00372 }
00373 }
00374
00375 if (!error)
00376 result = filter->encode_endpoints (mprofile);
00377 if (result == -1)
00378 error = 1;
00379
00380 if (error)
00381 throw ::CORBA::INTERNAL (
00382 CORBA::SystemException::_tao_minor_code (
00383 TAO_MPROFILE_CREATION_ERROR,
00384 0),
00385 CORBA::COMPLETED_NO);
00386
00387
00388
00389
00390 if (mprofile.profile_count () == 0)
00391 throw ::CORBA::BAD_PARAM (
00392 CORBA::SystemException::_tao_minor_code (
00393 TAO_MPROFILE_CREATION_ERROR,
00394 0),
00395 CORBA::COMPLETED_NO);
00396
00397 return
00398 this->orb_core_.create_stub_object (mprofile, type_id, policy_list);
00399 }
00400
00401 size_t
00402 TAO_RT_POA::endpoint_count (void)
00403 {
00404 size_t profile_count = 0;
00405
00406 TAO_Thread_Lane **lanes =
00407 this->thread_pool_->lanes ();
00408
00409 for (CORBA::ULong i = 0;
00410 i != this->thread_pool_->number_of_lanes ();
00411 ++i)
00412 profile_count +=
00413 lanes[i]->resources ().acceptor_registry ().endpoint_count ();
00414
00415 return profile_count;
00416 }
00417
00418 int
00419 TAO_RT_POA::lane_required (TAO_Thread_Lane *lane,
00420 TAO_PriorityBandedConnectionPolicy *priority_bands)
00421 {
00422 if (priority_bands == 0)
00423 return 1;
00424
00425 RTCORBA::PriorityBands &bands =
00426 priority_bands->priority_bands_rep ();
00427
00428 for (CORBA::ULong i = 0;
00429 i < bands.length ();
00430 ++i)
00431 {
00432 if (bands[i].low <= lane->lane_priority () &&
00433 bands[i].high >= lane->lane_priority ())
00434 return 1;
00435 }
00436
00437 return 0;
00438 }
00439
00440 CORBA::PolicyList *
00441 TAO_RT_POA::client_exposed_policies (CORBA::Short object_priority)
00442 {
00443 CORBA::PolicyList *client_exposed_policies = 0;
00444 ACE_NEW_THROW_EX (client_exposed_policies,
00445 CORBA::PolicyList (),
00446 CORBA::NO_MEMORY (TAO::VMCID,
00447 CORBA::COMPLETED_NO));
00448
00449 CORBA::PolicyList_var safe_client_exposed_policies = client_exposed_policies;
00450
00451
00452 this->policies_.add_client_exposed_fixed_policies (client_exposed_policies);
00453
00454
00455
00456 CORBA::Short poa_priority =
00457 this->cached_policies_.server_priority ();
00458
00459 if (poa_priority != TAO_INVALID_PRIORITY)
00460 {
00461 TAO::Portable_Server::Cached_Policies::PriorityModel priority_model =
00462 this->cached_policies_.priority_model ();
00463
00464
00465
00466
00467
00468 CORBA::Short priority;
00469 if (priority_model == TAO::Portable_Server::Cached_Policies::CLIENT_PROPAGATED)
00470 priority = poa_priority;
00471 else
00472 priority = object_priority;
00473
00474 const CORBA::ULong current_length =
00475 client_exposed_policies->length ();
00476 client_exposed_policies->length (current_length + 1);
00477
00478 TAO_PriorityModelPolicy *priority_model_policy;
00479 ACE_NEW_THROW_EX (priority_model_policy,
00480 TAO_PriorityModelPolicy (RTCORBA::PriorityModel (priority_model),
00481 priority),
00482 CORBA::NO_MEMORY (TAO::VMCID,
00483 CORBA::COMPLETED_NO));
00484
00485 (*client_exposed_policies)[current_length] = priority_model_policy;
00486 }
00487
00488 return safe_client_exposed_policies._retn ();
00489 }
00490
00491
00492
00493 PortableServer::POA_ptr
00494 TAO_RT_POA::create_POA (const char *adapter_name,
00495 PortableServer::POAManager_ptr poa_manager,
00496 const CORBA::PolicyList &policies)
00497 {
00498 return this->TAO_Regular_POA::create_POA (adapter_name, poa_manager, policies);
00499 }
00500
00501 PortableServer::POA_ptr
00502 TAO_RT_POA::find_POA (const char *adapter_name, CORBA::Boolean activate_it)
00503 {
00504 return this->TAO_Regular_POA::find_POA (adapter_name, activate_it);
00505 }
00506
00507 void
00508 TAO_RT_POA::destroy (CORBA::Boolean etherealize_objects,
00509 CORBA::Boolean wait_for_completion)
00510 {
00511 this->TAO_Regular_POA::destroy (etherealize_objects, wait_for_completion);
00512 }
00513
00514
00515 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00516
00517 PortableServer::ThreadPolicy_ptr
00518 TAO_RT_POA::create_thread_policy (PortableServer::ThreadPolicyValue value)
00519 {
00520 return this->TAO_Regular_POA::create_thread_policy (value);
00521 }
00522
00523 #endif
00524
00525 #if !defined (CORBA_E_MICRO)
00526 PortableServer::LifespanPolicy_ptr
00527 TAO_RT_POA::create_lifespan_policy (PortableServer::LifespanPolicyValue value)
00528 {
00529 return this->TAO_Regular_POA::create_lifespan_policy (value);
00530 }
00531 #endif
00532
00533 #if !defined (CORBA_E_MICRO)
00534 PortableServer::IdUniquenessPolicy_ptr
00535 TAO_RT_POA::create_id_uniqueness_policy (PortableServer::IdUniquenessPolicyValue value)
00536 {
00537 return this->TAO_Regular_POA::create_id_uniqueness_policy (value);
00538 }
00539 #endif
00540
00541 #if !defined (CORBA_E_MICRO)
00542 PortableServer::IdAssignmentPolicy_ptr
00543 TAO_RT_POA::create_id_assignment_policy (PortableServer::IdAssignmentPolicyValue value)
00544 {
00545 return this->TAO_Regular_POA::create_id_assignment_policy (value);
00546 }
00547 #endif
00548
00549 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00550
00551 PortableServer::ImplicitActivationPolicy_ptr
00552 TAO_RT_POA::create_implicit_activation_policy (
00553 PortableServer::ImplicitActivationPolicyValue value)
00554 {
00555 return this->TAO_Regular_POA::create_implicit_activation_policy (value);
00556 }
00557
00558 PortableServer::ServantRetentionPolicy_ptr
00559 TAO_RT_POA::create_servant_retention_policy (
00560 PortableServer::ServantRetentionPolicyValue value)
00561 {
00562 return this->TAO_Regular_POA::create_servant_retention_policy (value);
00563 }
00564
00565
00566 PortableServer::RequestProcessingPolicy_ptr
00567 TAO_RT_POA::create_request_processing_policy (
00568 PortableServer::RequestProcessingPolicyValue value)
00569 {
00570 return this->TAO_Regular_POA::create_request_processing_policy (value);
00571 }
00572
00573 #endif
00574
00575 char *
00576 TAO_RT_POA::the_name (void)
00577 {
00578 return this->TAO_Regular_POA::the_name ();
00579 }
00580
00581 PortableServer::POA_ptr
00582 TAO_RT_POA::the_parent (void)
00583 {
00584 return this->TAO_Regular_POA::the_parent ();
00585 }
00586
00587 PortableServer::POAList *
00588 TAO_RT_POA::the_children (void)
00589 {
00590 return this->TAO_Regular_POA::the_children ();
00591 }
00592
00593 PortableServer::POAManager_ptr
00594 TAO_RT_POA::the_POAManager (void)
00595 {
00596 return this->TAO_Regular_POA::the_POAManager ();
00597 }
00598
00599
00600 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00601
00602 PortableServer::AdapterActivator_ptr
00603 TAO_RT_POA::the_activator (void)
00604 {
00605 return this->TAO_Regular_POA::the_activator ();;
00606 }
00607
00608 void
00609 TAO_RT_POA::the_activator (PortableServer::AdapterActivator_ptr adapter_activator)
00610 {
00611 this->TAO_Regular_POA::the_activator (adapter_activator);
00612 }
00613
00614 PortableServer::ServantManager_ptr
00615 TAO_RT_POA::get_servant_manager (void)
00616 {
00617 return this->TAO_Regular_POA::get_servant_manager ();
00618 }
00619
00620 void
00621 TAO_RT_POA::set_servant_manager (PortableServer::ServantManager_ptr imgr)
00622 {
00623 this->TAO_Regular_POA::set_servant_manager (imgr);
00624 }
00625
00626 PortableServer::Servant
00627 TAO_RT_POA::get_servant (void)
00628 {
00629 return this->TAO_Regular_POA::get_servant ();
00630 }
00631
00632 void
00633 TAO_RT_POA::set_servant (PortableServer::Servant servant)
00634 {
00635 this->TAO_Regular_POA::set_servant (servant);
00636 }
00637
00638 #endif
00639
00640 PortableServer::ObjectId *
00641 TAO_RT_POA::activate_object (PortableServer::Servant p_servant)
00642 {
00643 return this->TAO_Regular_POA::activate_object (p_servant);
00644 }
00645
00646 #if !defined (CORBA_E_MICRO)
00647 void
00648 TAO_RT_POA::activate_object_with_id (const PortableServer::ObjectId &id,
00649 PortableServer::Servant p_servant)
00650 {
00651 this->TAO_Regular_POA::activate_object_with_id (id, p_servant);
00652 }
00653 #endif
00654
00655 void
00656 TAO_RT_POA::deactivate_object (const PortableServer::ObjectId &oid)
00657 {
00658 this->TAO_Regular_POA::deactivate_object (oid);
00659 }
00660
00661 CORBA::Object_ptr
00662 TAO_RT_POA::create_reference (const char *intf)
00663 {
00664 return this->TAO_Regular_POA::create_reference (intf);
00665 }
00666
00667 #if !defined (CORBA_E_MICRO)
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 #endif
00675
00676 PortableServer::ObjectId *
00677 TAO_RT_POA::servant_to_id (PortableServer::Servant p_servant)
00678 {
00679 return this->TAO_Regular_POA::servant_to_id (p_servant);
00680 }
00681
00682 CORBA::Object_ptr
00683 TAO_RT_POA::servant_to_reference (PortableServer::Servant p_servant)
00684 {
00685 return this->TAO_Regular_POA::servant_to_reference (p_servant);
00686 }
00687
00688 PortableServer::Servant
00689 TAO_RT_POA::reference_to_servant (CORBA::Object_ptr reference)
00690 {
00691 return this->TAO_Regular_POA::reference_to_servant (reference);
00692 }
00693
00694 PortableServer::ObjectId *
00695 TAO_RT_POA::reference_to_id (CORBA::Object_ptr reference)
00696 {
00697 return this->TAO_Regular_POA::reference_to_id (reference);
00698 }
00699
00700 PortableServer::Servant
00701 TAO_RT_POA::id_to_servant (const PortableServer::ObjectId &oid)
00702 {
00703 return this->TAO_Regular_POA::id_to_servant (oid);
00704 }
00705
00706 CORBA::Object_ptr
00707 TAO_RT_POA::id_to_reference (const PortableServer::ObjectId &oid)
00708 {
00709 return this->TAO_Regular_POA::id_to_reference (oid);
00710 }
00711
00712 CORBA::OctetSeq *
00713 TAO_RT_POA::id (void)
00714 {
00715 return this->TAO_Regular_POA::id ();
00716 }
00717
00718 TAO_END_VERSIONED_NAMESPACE_DECL
00719
00720 #endif