2 #include "tao/Profile_Transport_Resolver.h"
3 #include "tao/Profile.h"
5 #include "tao/Transport.h"
6 #include "tao/Invocation_Endpoint_Selectors.h"
7 #include "tao/ORB_Core.h"
8 #include "tao/Thread_Lane_Resources.h"
9 #include "tao/Transport_Cache_Manager.h"
10 #include "tao/Transport_Descriptor_Interface.h"
11 #include "tao/Endpoint_Selector_Factory.h"
12 #include "tao/Codeset_Manager.h"
13 #include "tao/Connector_Registry.h"
14 #include "tao/Transport_Connector.h"
15 #include "tao/Endpoint.h"
16 #include "tao/SystemException.h"
17 #include "tao/Client_Strategy_Factory.h"
19 #include "tao/ORB_Time_Policy.h"
20 #include "ace/CORBA_macros.h"
22 #if !defined (__ACE_INLINE__)
23 # include "tao/Profile_Transport_Resolver.inl"
24 #endif /* __ACE_INLINE__ */
26 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
30 Profile_Transport_Resolver::~Profile_Transport_Resolver ()
34 this->profile_
->_decr_refcnt ();
37 if (this->transport_
.get ())
39 if (this->is_released_
== false)
41 this->transport_
->make_idle ();
44 this->transport_
->remove_reference ();
47 delete this->inconsistent_policies_
;
51 Profile_Transport_Resolver::profile (TAO_Profile
*p
)
53 // Dont do anything if the incoming profile is null
56 // @note This is just a workaround for a more serious problem
57 // with profile management. This would cover some potential
58 // issues that Ossama is working on. Ossama, please remove
59 // them when you are done.
60 TAO_Profile
*tmp
= this->profile_
;
62 (void) p
->_incr_refcnt ();
67 (void) tmp
->_decr_refcnt ();
74 Profile_Transport_Resolver::resolve (ACE_Time_Value
*max_time_val
)
76 TAO::ORB_Countdown_Time
countdown (max_time_val
);
78 TAO_Invocation_Endpoint_Selector
*es
=
79 this->stub_
->orb_core ()->endpoint_selector_factory ()->get_selector ();
81 // Select the endpoint
82 es
->select_endpoint (this, max_time_val
);
84 if (this->transport_
.get () == nullptr)
86 // No useable endpoint could be found. We will not
87 // be able to send the message. Wait to throw an exception until
88 // after the send_request interception point has been called.
92 TAO_GIOP_Message_Version
const & version
= this->profile_
->version ();
94 // Initialize the messaging object
95 this->transport_
->messaging_init (version
);
97 if (!this->transport_
->is_tcs_set ())
99 TAO_Codeset_Manager
* const tcm
=
100 this->stub_
->orb_core ()->codeset_manager ();
102 tcm
->set_tcs (*this->profile_
, *this->transport_
);
107 Profile_Transport_Resolver::try_connect (
108 TAO_Transport_Descriptor_Interface
*desc
,
109 ACE_Time_Value
*timeout
)
111 return this->try_connect_i (desc
, timeout
, false);
115 Profile_Transport_Resolver::try_parallel_connect (
116 TAO_Transport_Descriptor_Interface
*desc
,
117 ACE_Time_Value
*timeout
)
119 return this->try_connect_i (desc
, timeout
, true);
124 Profile_Transport_Resolver::try_connect_i (
125 TAO_Transport_Descriptor_Interface
*desc
,
126 ACE_Time_Value
*timeout
,
129 TAO_Connector_Registry
*conn_reg
=
130 this->stub_
->orb_core ()->connector_registry ();
132 if (conn_reg
== nullptr)
134 throw ::CORBA::INTERNAL (
135 CORBA::SystemException::_tao_minor_code (
138 CORBA::COMPLETED_NO
);
141 ACE_Time_Value connection_timeout
;
142 bool has_con_timeout
= this->get_connection_timeout (connection_timeout
);
144 if (has_con_timeout
&& !this->blocked_
)
146 timeout
= &connection_timeout
;
148 else if (has_con_timeout
)
150 if (timeout
== nullptr || connection_timeout
< *timeout
)
151 timeout
= &connection_timeout
;
153 has_con_timeout
= false;
155 else if (!this->blocked_
)
160 TAO_Connector
*con
= conn_reg
->get_connector (desc
->endpoint ()->tag ());
161 ACE_ASSERT(con
!= nullptr);
164 this->transport_
.set (con
->parallel_connect (this, desc
, timeout
));
168 this->transport_
.set (con
->connect (this, desc
, timeout
));
170 // A timeout error occurred.
171 // If the user has set a roundtrip timeout policy, throw a timeout
172 // exception. Otherwise, just fall through and return false to
173 // look at the next endpoint.
174 if (this->transport_
.get () == nullptr &&
175 has_con_timeout
== false &&
178 throw ::CORBA::TIMEOUT (
179 CORBA::SystemException::_tao_minor_code (
180 TAO_TIMEOUT_CONNECT_MINOR_CODE
,
182 CORBA::COMPLETED_NO
);
184 else if (this->transport_
.get () == nullptr)
190 // Determine the sync scope (if any)
191 Messaging::SyncScope sync_scope
;
192 bool has_synchronization
= false;
193 this->stub_
->orb_core ()->call_sync_scope_hook (this->stub_
,
202 Profile_Transport_Resolver::use_parallel_connect () const
204 TAO_ORB_Core
*oc
= this->stub_
->orb_core();
205 return (oc
->orb_params()->use_parallel_connects()
206 #if 0 // it was decided that even with blocked connects
207 // parallel connects could be useful, at least for cache
209 oc
->client_factory()->connect_strategy() !=
210 TAO_Client_Strategy_Factory::TAO_BLOCKED_CONNECT
216 Profile_Transport_Resolver::get_connection_timeout (
217 ACE_Time_Value
&max_wait_time
)
219 bool is_conn_timeout
= false;
221 // Check for the connection timout policy in the ORB
222 this->stub_
->orb_core ()->connection_timeout (this->stub_
,
226 return is_conn_timeout
;
231 Profile_Transport_Resolver::init_inconsistent_policies ()
233 ACE_NEW_THROW_EX (this->inconsistent_policies_
,
234 CORBA::PolicyList (0),
236 CORBA::SystemException::_tao_minor_code (
239 CORBA::COMPLETED_NO
));
244 Profile_Transport_Resolver::find_transport (TAO_Transport_Descriptor_Interface
*desc
)
246 TAO::Transport_Cache_Manager
& cache
=
247 this->profile_
->orb_core()->lane_resources ().transport_cache();
249 // the cache increments the reference count on the transport if
250 // the find is successful. We want to return a "boolean" of 0 for
251 // failure, 1 for success.
253 TAO_Transport
* tmp
= this->transport_
.get ();
254 if (cache
.find_transport(desc
, tmp
, busy_count
) !=
255 Transport_Cache_Manager::CACHE_FOUND_AVAILABLE
)
258 this->transport_
.set (tmp
);
264 TAO_END_VERSIONED_NAMESPACE_DECL