2 #include "tao/Strategies/Optimized_Connection_Endpoint_Selector.h"
6 #include "tao/Profile.h"
7 #include "tao/Endpoint.h"
8 #include "tao/Base_Transport_Property.h"
9 #include "tao/ORB_Core.h"
10 #include "tao/Transport.h"
11 #include "tao/Profile_Transport_Resolver.h"
12 #include "tao/SystemException.h"
14 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
16 // ****************************************************************
18 ACE_Time_Value
TAO_Optimized_Connection_Endpoint_Selector::timeout_
;
20 TAO_Optimized_Connection_Endpoint_Selector::
21 TAO_Optimized_Connection_Endpoint_Selector (const ACE_Time_Value
&tv
)
23 TAO_Optimized_Connection_Endpoint_Selector::timeout_
= tv
;
26 TAOLIB_DEBUG ((LM_DEBUG
,
27 ACE_TEXT ("TAO(%P|%t) Optimized Connection Enpoint Selector: ")
28 ACE_TEXT ("Initializing timeout hook tv = %d sec, %d usec\n"),
29 tv
.sec(), tv
.usec()));
31 if (tv
> ACE_Time_Value::zero
)
33 TAO_ORB_Core::connection_timeout_hook
34 (TAO_Optimized_Connection_Endpoint_Selector::hook
);
38 TAO_Optimized_Connection_Endpoint_Selector::
39 ~TAO_Optimized_Connection_Endpoint_Selector ()
45 TAO_Optimized_Connection_Endpoint_Selector::hook (TAO_ORB_Core
*,
51 TAO_Optimized_Connection_Endpoint_Selector::
52 timeout_
> ACE_Time_Value::zero
;
54 tv
= TAO_Optimized_Connection_Endpoint_Selector::timeout_
;
58 TAO_Optimized_Connection_Endpoint_Selector::check_profile (TAO_Profile
*p
,
59 TAO::Profile_Transport_Resolver
*r
)
61 TAO_Endpoint
*effective_endpoint
= 0;
64 effective_endpoint
= p
->endpoint ();
65 size_t endpoint_count
= p
->endpoint_count();
66 for (size_t i
= 0; i
< endpoint_count
; ++i
)
68 TAO_Base_Transport_Property
desc (effective_endpoint
);
69 if (r
->find_transport(&desc
))
71 // Go to the next endpoint in this profile
72 effective_endpoint
= effective_endpoint
->next();
78 TAO_Optimized_Connection_Endpoint_Selector::select_endpoint
79 (TAO::Profile_Transport_Resolver
*r
,
80 ACE_Time_Value
*max_wait_time
)
82 TAO_Stub
*stub
= r
->stub();
83 TAO_Profile
*p
= stub
->profile_in_use();
85 // first, look for the endpoints for the current profile in use.
86 // if that is available then go for it.
88 if (this->check_profile (p
, r
) != 0)
91 // next, look for any other profiles. If the stub has any forward profiles,
92 // use those, otherwise look at the base profiles. This separation is
93 // necessary to avoid re-using a corbaloc or other previously forwarded
96 const TAO_MProfile
*profiles
= stub
->forward_profiles();
99 for (CORBA::ULong count
= 0; count
< profiles
->profile_count(); count
++)
101 p
= const_cast<TAO_Profile
*>(profiles
->get_profile(count
));
102 if (this->check_profile (p
, r
) != 0)
104 if (stub
->profile_in_use() != p
)
106 // thread-safe way to coerse stub to this profile.
107 stub
->reset_profiles();
108 while (stub
->profile_in_use() != p
)
109 if (stub
->next_profile_retry() == 0)
120 p
= stub
->profile_in_use();
121 if (this->check_profile(p
, r
) != 0)
124 while (stub
->next_profile_retry () != 0);
128 // at this point, we do not have an existing transport, so we must
129 // reset the profile list and try establishing connections via the
134 r
->profile (r
->stub ()->profile_in_use ());
136 // Check whether we need to do a blocked wait or we have a
137 // non-blocked wait and we support that. If this is not the
138 // case we can't use this profile so try the next.
139 if (r
->blocked_connect () ||
140 (!r
->blocked_connect () && r
->profile ()->supports_non_blocking_oneways ()))
142 const size_t endpoint_count
= r
->profile ()->endpoint_count ();
144 TAO_Endpoint
*ep
= r
->profile ()->endpoint ();
146 for (size_t i
= 0; i
< endpoint_count
; ++i
)
148 TAO_Base_Transport_Property
desc (ep
);
149 const bool retval
= r
->try_connect (&desc
, max_wait_time
);
151 // Check if the connect has completed.
155 // Go to the next endpoint in this profile.
160 while (r
->stub ()->next_profile_retry () != 0);
162 // If we get here, we completely failed to find an endpoint
163 // that we know how to use. We used to throw an exception
164 // but that would prevent any request interception points
165 // being called. They may know how to fix the problem so
166 // we wait to throw the exception in
167 // Synch_Twoway_Invocation::remote_twoway and
168 // Synch_Oneway_Invocation::remote_oneway instead.
171 TAO_END_VERSIONED_NAMESPACE_DECL