diff options
Diffstat (limited to 'TAO/tao/RTPortableServer/RT_Policy_Validator.cpp')
-rw-r--r-- | TAO/tao/RTPortableServer/RT_Policy_Validator.cpp | 298 |
1 files changed, 197 insertions, 101 deletions
diff --git a/TAO/tao/RTPortableServer/RT_Policy_Validator.cpp b/TAO/tao/RTPortableServer/RT_Policy_Validator.cpp index c5560a9901f..cdea3350ccd 100644 --- a/TAO/tao/RTPortableServer/RT_Policy_Validator.cpp +++ b/TAO/tao/RTPortableServer/RT_Policy_Validator.cpp @@ -14,16 +14,12 @@ #include "tao/Policy_Set.h" #include "tao/Transport_Acceptor.h" - - ACE_RCSID (RTPortableServer, RT_Policy_Validator, "$Id$") - TAO_POA_RT_Policy_Validator::TAO_POA_RT_Policy_Validator (TAO_ORB_Core &orb_core) : TAO_Policy_Validator (orb_core), - acceptor_registry_ (0), thread_pool_ (0) { // No-Op. @@ -34,16 +30,6 @@ TAO_POA_RT_Policy_Validator::~TAO_POA_RT_Policy_Validator (void) // No-Op. } -TAO_Acceptor_Registry * -TAO_POA_RT_Policy_Validator::acceptor_registry (void) -{ - if (this->acceptor_registry_ == 0) - this->acceptor_registry_ = - TAO_POA_RT_Policy_Validator::extract_acceptor_registry (this->orb_core_, - this->thread_pool_); - return this->acceptor_registry_; -} - void TAO_POA_RT_Policy_Validator::validate_impl (TAO_Policy_Set &policies ACE_ENV_ARG_DECL) @@ -51,9 +37,6 @@ TAO_POA_RT_Policy_Validator::validate_impl (TAO_Policy_Set &policies this->validate_thread_pool (policies ACE_ENV_ARG_PARAMETER); ACE_CHECK; - this->validate_lifespan (policies ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - this->validate_server_protocol (policies ACE_ENV_ARG_PARAMETER); ACE_CHECK; @@ -79,7 +62,26 @@ TAO_POA_RT_Policy_Validator::validate_server_protocol (TAO_Policy_Set &policies // specified in the RTCORBA::ServerProtocolPolicy. This ensure we // will be able to create non-nil object references. CORBA::Policy_var protocol = - policies.get_cached_policy (TAO_CACHED_POLICY_RT_SERVER_PROTOCOL); + policies.get_cached_policy (TAO_CACHED_POLICY_RT_SERVER_PROTOCOL + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + if (CORBA::is_nil (protocol.in ())) + { + // If the server protocol policy has not been specified, then + // add a server policy that reflects the protocols supported by + // the acceptor registries of the POA's thread pool. + protocol = + TAO_POA_RT_Policy_Validator::server_protocol_policy_from_thread_pool (this->thread_pool_, + this->orb_core_); + + if (!CORBA::is_nil (protocol.in ())) + { + // If so, we'll use that policy. + policies.set_policy (protocol.in () ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } + } RTCORBA::ServerProtocolPolicy_var server_protocol_policy = RTCORBA::ServerProtocolPolicy::_narrow (protocol.in () @@ -93,28 +95,64 @@ TAO_POA_RT_Policy_Validator::validate_server_protocol (TAO_Policy_Set &policies RTCORBA::ProtocolList &protocols = server_protocol->protocols_rep (); - TAO_Acceptor_Registry *acceptor_registry = - this->acceptor_registry (); - for (CORBA::ULong j = 0; j < protocols.length (); ++j) { int found = 0; CORBA::ULong protocol_type = protocols[j].protocol_type; - for (TAO_AcceptorSetIterator a = acceptor_registry->begin (); - a != acceptor_registry->end (); - ++a) + + if (this->thread_pool_) { - if ((*a)->tag () == protocol_type) + TAO_Thread_Lane **lanes = + this->thread_pool_->lanes (); + + for (CORBA::ULong i = 0; + i != this->thread_pool_->number_of_lanes (); + ++i) { - found = 1; - break; + TAO_Thread_Lane_Resources &resources = + lanes[i]->resources (); + + TAO_Acceptor_Registry &acceptor_registry = + resources.acceptor_registry (); + + for (TAO_AcceptorSetIterator a = acceptor_registry.begin (); + a != acceptor_registry.end (); + ++a) + { + if ((*a)->tag () == protocol_type) + { + found = 1; + break; + } + } + } + } + else + { + TAO_Thread_Lane_Resources_Manager &thread_lane_resources_manager = + this->orb_core_.thread_lane_resources_manager (); + + TAO_Thread_Lane_Resources &resources = + thread_lane_resources_manager.default_lane_resources (); + + TAO_Acceptor_Registry &acceptor_registry = + resources.acceptor_registry (); + + for (TAO_AcceptorSetIterator a = acceptor_registry.begin (); + a != acceptor_registry.end (); + ++a) + { + if ((*a)->tag () == protocol_type) + { + found = 1; + break; + } } } if (!found) ACE_THROW (PortableServer::POA::InvalidPolicy ()); } - } void @@ -128,7 +166,9 @@ TAO_POA_RT_Policy_Validator::validate_priorities (TAO_Policy_Set &policies TAO_POA_Cached_Policies::NOT_SPECIFIED; CORBA::Policy_var policy = - policies.get_cached_policy (TAO_CACHED_POLICY_PRIORITY_MODEL); + policies.get_cached_policy (TAO_CACHED_POLICY_PRIORITY_MODEL + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; RTCORBA::PriorityModelPolicy_var priority_model = RTCORBA::PriorityModelPolicy::_narrow (policy.in () @@ -166,7 +206,9 @@ TAO_POA_RT_Policy_Validator::validate_priorities (TAO_Policy_Set &policies } policy = - policies.get_cached_policy (TAO_CACHED_POLICY_RT_PRIORITY_BANDED_CONNECTION); + policies.get_cached_policy (TAO_CACHED_POLICY_RT_PRIORITY_BANDED_CONNECTION + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; RTCORBA::PriorityBandedConnectionPolicy_var priority_bands = RTCORBA::PriorityBandedConnectionPolicy::_narrow (policy.in () @@ -330,46 +372,24 @@ TAO_POA_RT_Policy_Validator::validate_thread_pool (TAO_Policy_Set &policies } void -TAO_POA_RT_Policy_Validator::validate_lifespan (TAO_Policy_Set &policies - ACE_ENV_ARG_DECL) -{ - // If this POA is using a RTCORBA thread pool, make sure the - // lifespan policy is not persistent since we cannot support it - // right now. - if (this->thread_pool_ != 0) - { - CORBA::Policy_var policy = - policies.get_cached_policy (TAO_CACHED_POLICY_LIFESPAN); - PortableServer::LifespanPolicy_var lifespan_policy = - PortableServer::LifespanPolicy::_narrow (policy.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - PortableServer::LifespanPolicyValue lifespan = - lifespan_policy->value (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - if (lifespan == PortableServer::PERSISTENT) - { - ACE_THROW (PortableServer::POA::InvalidPolicy ()); - } - } -} - -void TAO_POA_RT_Policy_Validator::merge_policies_impl (TAO_Policy_Set &policies ACE_ENV_ARG_DECL) { // Check if the user has specified the priority model policy. CORBA::Policy_var priority_model = - policies.get_cached_policy (TAO_CACHED_POLICY_PRIORITY_MODEL); + policies.get_cached_policy (TAO_CACHED_POLICY_PRIORITY_MODEL + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; if (CORBA::is_nil (priority_model.in ())) { // If not, check if the priority model policy has been specified // at the ORB level. priority_model = - this->orb_core_.get_cached_policy (TAO_CACHED_POLICY_PRIORITY_MODEL); + this->orb_core_.get_cached_policy (TAO_CACHED_POLICY_PRIORITY_MODEL + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + if (!CORBA::is_nil (priority_model.in ())) { // If so, we'll use that policy. @@ -380,14 +400,20 @@ TAO_POA_RT_Policy_Validator::merge_policies_impl (TAO_Policy_Set &policies // Check if the user has specified the server protocol policy. CORBA::Policy_var server_protocol = - policies.get_cached_policy (TAO_CACHED_POLICY_RT_SERVER_PROTOCOL); + policies.get_cached_policy (TAO_CACHED_POLICY_RT_SERVER_PROTOCOL + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; if (CORBA::is_nil (server_protocol.in ())) { // If not, check if the server protocol policy has been // specified at the ORB level. server_protocol = - this->orb_core_.get_cached_policy (TAO_CACHED_POLICY_RT_SERVER_PROTOCOL); + this->orb_core_.get_cached_policy ( + TAO_CACHED_POLICY_RT_SERVER_PROTOCOL + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + if (!CORBA::is_nil (server_protocol.in ())) { // If so, we'll use that policy. @@ -398,14 +424,19 @@ TAO_POA_RT_Policy_Validator::merge_policies_impl (TAO_Policy_Set &policies // Check if the user has specified the thread pool policy. CORBA::Policy_var thread_pool = - policies.get_cached_policy (TAO_CACHED_POLICY_THREADPOOL); + policies.get_cached_policy (TAO_CACHED_POLICY_THREADPOOL + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; if (CORBA::is_nil (thread_pool.in ())) { // If not, check if the thread pool policy has been specified at // the ORB level. thread_pool = - this->orb_core_.get_cached_policy (TAO_CACHED_POLICY_THREADPOOL); + this->orb_core_.get_cached_policy (TAO_CACHED_POLICY_THREADPOOL + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + if (!CORBA::is_nil (thread_pool.in ())) { // If so, we'll use that policy. @@ -416,13 +447,115 @@ TAO_POA_RT_Policy_Validator::merge_policies_impl (TAO_Policy_Set &policies } /* static */ +RTCORBA::ServerProtocolPolicy_ptr +TAO_POA_RT_Policy_Validator::server_protocol_policy_from_thread_pool (TAO_Thread_Pool *thread_pool, + TAO_ORB_Core &orb_core) +{ + RTCORBA::ProtocolList protocols; + + if (thread_pool) + { + TAO_Thread_Lane **lanes = + thread_pool->lanes (); + + for (CORBA::ULong i = 0; + i != thread_pool->number_of_lanes (); + ++i) + { + TAO_Thread_Lane_Resources &resources = + lanes[i]->resources (); + + TAO_Acceptor_Registry &acceptor_registry = + resources.acceptor_registry (); + + TAO_POA_RT_Policy_Validator::server_protocol_policy_from_acceptor_registry (protocols, + acceptor_registry, + orb_core); + } + } + else + { + TAO_Thread_Lane_Resources_Manager &thread_lane_resources_manager = + orb_core.thread_lane_resources_manager (); + + TAO_Thread_Lane_Resources &resources = + thread_lane_resources_manager.default_lane_resources (); + + TAO_Acceptor_Registry &acceptor_registry = + resources.acceptor_registry (); + + TAO_POA_RT_Policy_Validator::server_protocol_policy_from_acceptor_registry (protocols, + acceptor_registry, + orb_core); + } + + // Set ServerProtocolPolicy. + TAO_ServerProtocolPolicy *server_protocol_policy = 0; + ACE_NEW_RETURN (server_protocol_policy, + TAO_ServerProtocolPolicy (protocols), + 0); + + return server_protocol_policy; +} + +/* static */ +void +TAO_POA_RT_Policy_Validator::server_protocol_policy_from_acceptor_registry (RTCORBA::ProtocolList &protocols, + TAO_Acceptor_Registry &acceptor_registry, + TAO_ORB_Core &orb_core) +{ + TAO_AcceptorSetIterator end = + acceptor_registry.end (); + + for (TAO_AcceptorSetIterator acceptor = + acceptor_registry.begin (); + acceptor != end; + ++acceptor) + { + if (*acceptor == 0) + continue; + + CORBA::ULong current_length = + protocols.length (); + + // Make sure that this protocol is not already in the protocol + // list. + bool protocol_already_present = false; + for (CORBA::ULong i = 0; + i < current_length && !protocol_already_present; + ++i) + { + if (protocols[i].protocol_type == (*acceptor)->tag ()) + protocol_already_present = true; + } + + if (protocol_already_present) + continue; + + protocols.length (current_length + 1); + + protocols[current_length].protocol_type = + (*acceptor)->tag (); + + protocols[current_length].orb_protocol_properties = + RTCORBA::ProtocolProperties::_nil (); + + protocols[current_length].transport_protocol_properties = + TAO_Protocol_Properties_Factory::create_transport_protocol_property ((*acceptor)->tag (), + &orb_core); + } +} + +/* static */ TAO_Thread_Pool * TAO_POA_RT_Policy_Validator::extract_thread_pool (TAO_ORB_Core &orb_core, TAO_Policy_Set &policies ACE_ENV_ARG_DECL) { CORBA::Policy_var policy = - policies.get_cached_policy (TAO_CACHED_POLICY_THREADPOOL); + policies.get_cached_policy (TAO_CACHED_POLICY_THREADPOOL + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (0); RTCORBA::ThreadpoolPolicy_var thread_pool_policy = RTCORBA::ThreadpoolPolicy::_narrow (policy.in () @@ -469,41 +602,4 @@ TAO_POA_RT_Policy_Validator::extract_thread_pool (TAO_ORB_Core &orb_core, return thread_pool; } -/* static */ -TAO_Acceptor_Registry * -TAO_POA_RT_Policy_Validator::extract_acceptor_registry (TAO_ORB_Core &orb_core, - TAO_Thread_Pool *thread_pool) -{ - TAO_Acceptor_Registry *acceptor_registry = 0; - - // If <thread_pool_> != 0, it means that we have a RT thread pool. - if (thread_pool) - { - TAO_Thread_Lane **lanes = - thread_pool->lanes (); - - // All the lanes have similar acceptor registries. Therefore, - // looking at the first lane should suffice. - TAO_Thread_Lane_Resources &resources = - lanes[0]->resources (); - - acceptor_registry = - &resources.acceptor_registry (); - } - else - // We are dealing with the default thread pool. - { - TAO_Thread_Lane_Resources_Manager &thread_lane_resources_manager = - orb_core.thread_lane_resources_manager (); - - TAO_Thread_Lane_Resources &resources = - thread_lane_resources_manager.default_lane_resources (); - - acceptor_registry = - &resources.acceptor_registry (); - } - - return acceptor_registry; -} - #endif /* TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0 */ |