Go to the documentation of this file.00001 #include "tao/RTCORBA/RT_Invocation_Endpoint_Selectors.h"
00002
00003 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00004
00005 #include "tao/RTCORBA/RT_Policy_i.h"
00006 #include "tao/RTCORBA/RT_Stub.h"
00007 #include "tao/RTCORBA/RT_Transport_Descriptor.h"
00008 #include "tao/RTCORBA/RT_Transport_Descriptor_Property.h"
00009 #include "tao/RTCORBA/RT_Endpoint_Utils.h"
00010 #include "tao/RTCORBA/RT_Protocols_Hooks.h"
00011 #include "tao/Stub.h"
00012 #include "tao/ORB_Core.h"
00013 #include "tao/Profile.h"
00014 #include "tao/Endpoint.h"
00015 #include "tao/debug.h"
00016 #include "tao/Profile.h"
00017 #include "tao/Endpoint.h"
00018 #include "tao/Profile_Transport_Resolver.h"
00019 #include "tao/ORB_Core.h"
00020 #include "tao/SystemException.h"
00021
00022 ACE_RCSID (RTCORBA,
00023 RT_Invocation_Endpoint_Selectors,
00024 "$Id: RT_Invocation_Endpoint_Selectors.cpp 89882 2010-04-14 09:09:31Z vzykov $")
00025
00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00027
00028 void
00029 TAO_RT_Invocation_Endpoint_Selector::select_endpoint (
00030 TAO::Profile_Transport_Resolver *r,
00031 ACE_Time_Value *val)
00032 {
00033 if (r == 0)
00034 throw ::CORBA::INTERNAL ();
00035
00036 CORBA::Policy_var client_protocol_policy_base =
00037 TAO_RT_Endpoint_Utils::policy (TAO_CACHED_POLICY_RT_CLIENT_PROTOCOL, *r);
00038
00039 if (CORBA::is_nil(client_protocol_policy_base.in ()))
00040 {
00041 do
00042 {
00043 r->profile (r->stub ()->profile_in_use ());
00044
00045 if (this->endpoint_from_profile (*r, val) == 1)
00046 return;
00047 }
00048 while (r->stub ()->next_profile_retry () != 0);
00049
00050
00051
00052
00053
00054
00055
00056
00057 }
00058 else
00059 {
00060 RTCORBA::ClientProtocolPolicy_var client_protocol_policy =
00061 RTCORBA::ClientProtocolPolicy::_narrow (
00062 client_protocol_policy_base.in ());
00063
00064
00065 TAO_ClientProtocolPolicy *tao_client_protocol_policy =
00066 static_cast<TAO_ClientProtocolPolicy *> (client_protocol_policy.in ());
00067
00068
00069 RTCORBA::ProtocolList &client_protocols =
00070 tao_client_protocol_policy->protocols_rep ();
00071
00072 this->select_endpoint_based_on_client_protocol_policy (
00073 *r,
00074 client_protocol_policy.in (),
00075 client_protocols,
00076 val);
00077 }
00078 }
00079
00080 void
00081 TAO_RT_Invocation_Endpoint_Selector::select_endpoint_based_on_client_protocol_policy (
00082 TAO::Profile_Transport_Resolver &r,
00083 RTCORBA::ClientProtocolPolicy_ptr client_protocol_policy,
00084 RTCORBA::ProtocolList &client_protocols,
00085 ACE_Time_Value *val)
00086 {
00087 CORBA::Boolean valid_profile_found = false;
00088
00089
00090
00091
00092
00093
00094
00095
00096 for (CORBA::ULong protocol_index = 0;
00097 protocol_index < client_protocols.length ();
00098 ++protocol_index)
00099 {
00100
00101 TAO_Profile *profile = 0;
00102 TAO_MProfile &mprofile = r.stub ()->base_profiles ();
00103
00104 for (TAO_PHandle i = 0;
00105 i < mprofile.profile_count ();
00106 ++i)
00107 {
00108 profile = mprofile.get_profile (i);
00109
00110 if (profile->tag () == client_protocols[protocol_index].protocol_type)
00111 {
00112 valid_profile_found = true;
00113
00114 r.profile (profile);
00115
00116 if (this->endpoint_from_profile (r, val) == 1)
00117 return;
00118
00119 }
00120 }
00121 }
00122
00123
00124
00125 if (!valid_profile_found)
00126 {
00127 CORBA::PolicyList *p = r.inconsistent_policies ();
00128 if (p)
00129 {
00130
00131 p->length (1);
00132 (*p)[0u] = CORBA::Policy::_duplicate (client_protocol_policy);
00133 }
00134 throw ::CORBA::INV_POLICY ();
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144 }
00145
00146 int
00147 TAO_RT_Invocation_Endpoint_Selector::endpoint_from_profile (
00148 TAO::Profile_Transport_Resolver &r,
00149 ACE_Time_Value *val)
00150 {
00151
00152 TAO_RT_Stub *rt_stub = dynamic_cast <TAO_RT_Stub *> (r.stub ());
00153
00154 if (!rt_stub)
00155 throw CORBA::INTERNAL ();
00156
00157
00158 CORBA::Policy_var priority_model_policy =
00159 rt_stub->get_cached_policy (TAO_CACHED_POLICY_PRIORITY_MODEL);
00160
00161
00162 CORBA::Policy_var bands_policy =
00163 TAO_RT_Endpoint_Utils::policy (
00164 TAO_CACHED_POLICY_RT_PRIORITY_BANDED_CONNECTION, r);
00165
00166 bool all_endpoints_are_valid = false;
00167 bool match_priority = false;
00168 bool match_bands = false;
00169 CORBA::Short client_thread_priority = 0;
00170 CORBA::Short min_priority = 0;
00171 CORBA::Short max_priority = 0;
00172
00173
00174 if (CORBA::is_nil (priority_model_policy.in ()))
00175 {
00176
00177 if (!CORBA::is_nil (bands_policy.in ()))
00178 {
00179 CORBA::PolicyList *p = r.inconsistent_policies ();
00180 if (p)
00181 {
00182
00183 p->length (1);
00184 (*p)[0u] = CORBA::Policy::_duplicate (bands_policy.in ());
00185 }
00186
00187 throw ::CORBA::INV_POLICY ();
00188 }
00189
00190
00191
00192 all_endpoints_are_valid = true;
00193 }
00194
00195 else
00196 {
00197
00198 TAO_Protocols_Hooks *protocol_hooks =
00199 r.stub ()->orb_core ()->get_protocols_hooks ();
00200
00201 if (protocol_hooks != 0)
00202 {
00203 CORBA::Short server_priority = 0;
00204 CORBA::Boolean is_client_propagated = false;
00205
00206
00207
00208 protocol_hooks->get_selector_hook (priority_model_policy.in (),
00209 is_client_propagated,
00210 server_priority);
00211
00212 if (!is_client_propagated)
00213 {
00214
00215 all_endpoints_are_valid = true;
00216 }
00217
00218 else
00219 {
00220
00221
00222 if (protocol_hooks->get_thread_CORBA_priority (client_thread_priority) != -1 ||
00223 protocol_hooks->get_thread_implicit_CORBA_priority (client_thread_priority) != -1)
00224 {
00225
00226 }
00227 else
00228 {
00229 if (TAO_debug_level > 0)
00230 ACE_DEBUG ((LM_DEBUG, "ERROR: TAO_RT_Invocation_Endpoint_Selector::endpoint_from_profile. "
00231 "Unable to access RT CORBA Priority in client thread "
00232 "accessing object with CLIENT_PROPAGATED priority model.\n"));
00233 throw CORBA::DATA_CONVERSION (CORBA::OMGVMCID | 2, CORBA::COMPLETED_NO);
00234
00235 }
00236
00237
00238 if (bands_policy.ptr () == 0)
00239 {
00240
00241
00242
00243 match_priority = true;
00244 }
00245
00246 else
00247 {
00248
00249 bool in_range = false;
00250 protocol_hooks->get_selector_bands_policy_hook (
00251 bands_policy.in (),
00252 client_thread_priority,
00253 min_priority,
00254 max_priority,
00255 in_range);
00256
00257
00258 if (!in_range)
00259 {
00260 CORBA::PolicyList *p = r.inconsistent_policies ();
00261 if (p)
00262 {
00263 p->length (2);
00264 (*p)[0u] = CORBA::Policy::_duplicate (bands_policy.in ());
00265 (*p)[1u] =
00266 CORBA::Policy::_duplicate (
00267 priority_model_policy.in ());
00268 }
00269
00270
00271 throw ::CORBA::INV_POLICY ();
00272 }
00273
00274
00275 match_bands = true;
00276 }
00277 }
00278 }
00279 }
00280
00281 TAO_Endpoint *ep = r.profile ()->endpoint ();
00282
00283 while (ep != 0)
00284 {
00285
00286 CORBA::Short endpoint_priority = ep->priority ();
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 if (all_endpoints_are_valid ||
00299 (match_priority &&
00300 client_thread_priority == endpoint_priority) ||
00301 (match_bands &&
00302 endpoint_priority <= max_priority &&
00303 endpoint_priority >= min_priority) ||
00304 (r.profile ()->endpoint_count () == 1 &&
00305 endpoint_priority == TAO_INVALID_PRIORITY))
00306 {
00307 TAO_RT_Transport_Descriptor_Private_Connection_Property
00308 private_connection_descriptor_property;
00309
00310 TAO_RT_Transport_Descriptor_Banded_Connection_Property
00311 banded_connection_descriptor_property;
00312
00313 TAO_RT_Transport_Descriptor rt_transport_descriptor (ep);
00314
00315 CORBA::Policy_var private_connection_policy =
00316 rt_stub->get_cached_policy (TAO_CACHED_POLICY_RT_PRIVATE_CONNECTION);
00317
00318 if (!CORBA::is_nil (private_connection_policy.in ()))
00319 {
00320 private_connection_descriptor_property.init
00321 (static_cast<long> (reinterpret_cast<ptrdiff_t> (r.stub ())));
00322 rt_transport_descriptor.insert
00323 (&private_connection_descriptor_property);
00324 }
00325
00326 if (match_bands)
00327 {
00328 banded_connection_descriptor_property.init
00329 (min_priority, max_priority);
00330
00331 rt_transport_descriptor.insert
00332 (&banded_connection_descriptor_property);
00333 }
00334
00335
00336 if (r.try_connect (&rt_transport_descriptor, val))
00337 return 1;
00338 }
00339
00340
00341 ep = ep->next();
00342 }
00343
00344 return 0;
00345 }
00346
00347 TAO_END_VERSIONED_NAMESPACE_DECL
00348
00349 #endif