Updated logging to include the class/method so that it is more obvious where these...
[ACE_TAO.git] / TAO / tao / Profile_Transport_Resolver.cpp
blob860a3283295bb8bac2df527d80bc09625a42e014
1 // -*- C++ -*-
2 #include "tao/Profile_Transport_Resolver.h"
3 #include "tao/Profile.h"
4 #include "tao/Stub.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
28 namespace TAO
31 Profile_Transport_Resolver::~Profile_Transport_Resolver ()
33 if (this->profile_)
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_;
51 void
52 Profile_Transport_Resolver::profile (TAO_Profile *p)
54 // Dont do anything if the incoming profile is null
55 if (p)
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 ();
64 this->profile_ = p;
66 if (tmp)
68 (void) tmp->_decr_refcnt ();
74 void
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.
90 return;
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 ();
102 if (tcm)
103 tcm->set_tcs (*this->profile_, *this->transport_);
107 bool
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);
115 bool
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);
124 bool
125 Profile_Transport_Resolver::try_connect_i (
126 TAO_Transport_Descriptor_Interface *desc,
127 ACE_Time_Value *timeout,
128 bool parallel)
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 (
138 EINVAL),
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;
153 else
154 has_con_timeout = false;
156 else if (!this->blocked_)
158 timeout = nullptr;
161 TAO_Connector *con = conn_reg->get_connector (desc->endpoint ()->tag ());
162 ACE_ASSERT(con != nullptr);
163 if (parallel)
165 this->transport_.set (con->parallel_connect (this, desc, timeout));
167 else
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 &&
177 errno == ETIME)
179 throw ::CORBA::TIMEOUT (
180 CORBA::SystemException::_tao_minor_code (
181 TAO_TIMEOUT_CONNECT_MINOR_CODE,
182 errno),
183 CORBA::COMPLETED_NO);
185 else if (this->transport_.get () == nullptr)
187 return false;
189 else
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_,
195 has_synchronization,
196 sync_scope);
199 return true;
202 bool
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
209 // processing.
210 oc->client_factory()->connect_strategy() !=
211 TAO_Client_Strategy_Factory::TAO_BLOCKED_CONNECT
212 #endif /* 0 */
216 bool
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_,
224 is_conn_timeout,
225 max_wait_time);
227 return is_conn_timeout;
231 void
232 Profile_Transport_Resolver::init_inconsistent_policies ()
234 ACE_NEW_THROW_EX (this->inconsistent_policies_,
235 CORBA::PolicyList (0),
236 CORBA::NO_MEMORY (
237 CORBA::SystemException::_tao_minor_code (
239 ENOMEM),
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.
253 size_t busy_count;
254 TAO_Transport* tmp = this->transport_.get ();
255 if (cache.find_transport(desc, tmp, busy_count) !=
256 Transport_Cache_Manager::CACHE_FOUND_AVAILABLE)
257 return 0;
259 this->transport_.set (tmp);
260 return 1;
265 TAO_END_VERSIONED_NAMESPACE_DECL