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
31 Profile_Transport_Resolver::~Profile_Transport_Resolver ()
35 this->profile_
->_decr_refcnt ();
38 if (this->transport_
.get ())
40 if (this->is_released_
== false)
42 this->transport_
->make_idle ();
45 this->transport_
->remove_reference ();
48 delete this->inconsistent_policies_
;
52 Profile_Transport_Resolver::profile (TAO_Profile
*p
)
54 // Dont do anything if the incoming profile is null
57 // @note This is just a workaround for a more serious problem
58 // with profile management. This would cover some potential
59 // issues that Ossama is working on. Ossama, please remove
60 // them when you are done.
61 TAO_Profile
*tmp
= this->profile_
;
63 (void) p
->_incr_refcnt ();
68 (void) tmp
->_decr_refcnt ();
75 Profile_Transport_Resolver::resolve (ACE_Time_Value
*max_time_val
)
77 TAO::ORB_Countdown_Time
countdown (max_time_val
);
79 TAO_Invocation_Endpoint_Selector
*es
=
80 this->stub_
->orb_core ()->endpoint_selector_factory ()->get_selector ();
82 // Select the endpoint
83 es
->select_endpoint (this, max_time_val
);
85 if (this->transport_
.get () == nullptr)
87 // No useable endpoint could be found. We will not
88 // be able to send the message. Wait to throw an exception until
89 // after the send_request interception point has been called.
93 TAO_GIOP_Message_Version
const & version
= this->profile_
->version ();
95 // Initialize the messaging object
96 this->transport_
->messaging_init (version
);
98 if (!this->transport_
->is_tcs_set ())
100 TAO_Codeset_Manager
* const tcm
=
101 this->stub_
->orb_core ()->codeset_manager ();
103 tcm
->set_tcs (*this->profile_
, *this->transport_
);
108 Profile_Transport_Resolver::try_connect (
109 TAO_Transport_Descriptor_Interface
*desc
,
110 ACE_Time_Value
*timeout
)
112 return this->try_connect_i (desc
, timeout
, false);
116 Profile_Transport_Resolver::try_parallel_connect (
117 TAO_Transport_Descriptor_Interface
*desc
,
118 ACE_Time_Value
*timeout
)
120 return this->try_connect_i (desc
, timeout
, true);
125 Profile_Transport_Resolver::try_connect_i (
126 TAO_Transport_Descriptor_Interface
*desc
,
127 ACE_Time_Value
*timeout
,
130 TAO_Connector_Registry
*conn_reg
=
131 this->stub_
->orb_core ()->connector_registry ();
133 if (conn_reg
== nullptr)
135 throw ::CORBA::INTERNAL (
136 CORBA::SystemException::_tao_minor_code (
139 CORBA::COMPLETED_NO
);
142 ACE_Time_Value connection_timeout
;
143 bool has_con_timeout
= this->get_connection_timeout (connection_timeout
);
145 if (has_con_timeout
&& !this->blocked_
)
147 timeout
= &connection_timeout
;
149 else if (has_con_timeout
)
151 if (timeout
== nullptr || connection_timeout
< *timeout
)
152 timeout
= &connection_timeout
;
154 has_con_timeout
= false;
156 else if (!this->blocked_
)
161 TAO_Connector
*con
= conn_reg
->get_connector (desc
->endpoint ()->tag ());
162 ACE_ASSERT(con
!= nullptr);
165 this->transport_
.set (con
->parallel_connect (this, desc
, timeout
));
169 this->transport_
.set (con
->connect (this, desc
, timeout
));
171 // A timeout error occurred.
172 // If the user has set a roundtrip timeout policy, throw a timeout
173 // exception. Otherwise, just fall through and return false to
174 // look at the next endpoint.
175 if (this->transport_
.get () == nullptr &&
176 has_con_timeout
== false &&
179 throw ::CORBA::TIMEOUT (
180 CORBA::SystemException::_tao_minor_code (
181 TAO_TIMEOUT_CONNECT_MINOR_CODE
,
183 CORBA::COMPLETED_NO
);
185 else if (this->transport_
.get () == nullptr)
191 // Determine the sync scope (if any)
192 Messaging::SyncScope sync_scope
;
193 bool has_synchronization
= false;
194 this->stub_
->orb_core ()->call_sync_scope_hook (this->stub_
,
203 Profile_Transport_Resolver::use_parallel_connect () const
205 TAO_ORB_Core
*oc
= this->stub_
->orb_core();
206 return (oc
->orb_params()->use_parallel_connects()
207 #if 0 // it was decided that even with blocked connects
208 // parallel connects could be useful, at least for cache
210 oc
->client_factory()->connect_strategy() !=
211 TAO_Client_Strategy_Factory::TAO_BLOCKED_CONNECT
217 Profile_Transport_Resolver::get_connection_timeout (
218 ACE_Time_Value
&max_wait_time
)
220 bool is_conn_timeout
= false;
222 // Check for the connection timout policy in the ORB
223 this->stub_
->orb_core ()->connection_timeout (this->stub_
,
227 return is_conn_timeout
;
232 Profile_Transport_Resolver::init_inconsistent_policies ()
234 ACE_NEW_THROW_EX (this->inconsistent_policies_
,
235 CORBA::PolicyList (0),
237 CORBA::SystemException::_tao_minor_code (
240 CORBA::COMPLETED_NO
));
245 Profile_Transport_Resolver::find_transport (TAO_Transport_Descriptor_Interface
*desc
)
247 TAO::Transport_Cache_Manager
& cache
=
248 this->profile_
->orb_core()->lane_resources ().transport_cache();
250 // the cache increments the reference count on the transport if
251 // the find is successful. We want to return a "boolean" of 0 for
252 // failure, 1 for success.
254 TAO_Transport
* tmp
= this->transport_
.get ();
255 if (cache
.find_transport(desc
, tmp
, busy_count
) !=
256 Transport_Cache_Manager::CACHE_FOUND_AVAILABLE
)
259 this->transport_
.set (tmp
);
265 TAO_END_VERSIONED_NAMESPACE_DECL