Go to the documentation of this file.00001
00002
00003 #include "tao/Profile_Transport_Resolver.h"
00004 #include "tao/Profile.h"
00005 #include "tao/Stub.h"
00006 #include "tao/Transport.h"
00007 #include "tao/Invocation_Endpoint_Selectors.h"
00008 #include "tao/ORB_Core.h"
00009 #include "tao/Thread_Lane_Resources.h"
00010 #include "tao/Transport_Cache_Manager.h"
00011 #include "tao/Transport_Descriptor_Interface.h"
00012 #include "tao/Endpoint_Selector_Factory.h"
00013 #include "tao/Codeset_Manager.h"
00014 #include "tao/Connector_Registry.h"
00015 #include "tao/Transport_Connector.h"
00016 #include "tao/Endpoint.h"
00017 #include "tao/SystemException.h"
00018 #include "tao/Client_Strategy_Factory.h"
00019
00020 #include "ace/Countdown_Time.h"
00021 #include "ace/CORBA_macros.h"
00022
00023 #if !defined (__ACE_INLINE__)
00024 # include "tao/Profile_Transport_Resolver.inl"
00025 #endif
00026
00027 ACE_RCSID (tao,
00028 Profile_Transport_Resolver,
00029 "$Id: Profile_Transport_Resolver.cpp 84272 2009-01-30 11:58:40Z johnnyw $")
00030
00031
00032 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00033
00034 namespace TAO
00035 {
00036
00037 Profile_Transport_Resolver::~Profile_Transport_Resolver (void)
00038 {
00039 if (this->profile_)
00040 {
00041 this->profile_->_decr_refcnt ();
00042 }
00043
00044 if (this->transport_.get ())
00045 {
00046 if (this->is_released_ == false)
00047 {
00048 this->transport_->make_idle ();
00049 }
00050
00051 this->transport_->remove_reference ();
00052 }
00053
00054 delete this->inconsistent_policies_;
00055 }
00056
00057 void
00058 Profile_Transport_Resolver::profile (TAO_Profile *p)
00059 {
00060
00061 if (p)
00062 {
00063
00064
00065
00066
00067 TAO_Profile *tmp = this->profile_;
00068
00069 (void) p->_incr_refcnt ();
00070 this->profile_ = p;
00071
00072 if (tmp)
00073 {
00074 (void) tmp->_decr_refcnt ();
00075 }
00076 }
00077 }
00078
00079
00080 void
00081 Profile_Transport_Resolver::resolve (ACE_Time_Value *max_time_val)
00082 {
00083 ACE_Countdown_Time countdown (max_time_val);
00084
00085 TAO_Invocation_Endpoint_Selector *es =
00086 this->stub_->orb_core ()->endpoint_selector_factory ()->get_selector ();
00087
00088
00089 es->select_endpoint (this, max_time_val);
00090
00091 if (this->transport_.get () == 0)
00092 {
00093
00094
00095
00096 return;
00097 }
00098
00099 TAO_GIOP_Message_Version const & version = this->profile_->version ();
00100
00101
00102 this->transport_->messaging_init (version);
00103
00104 if (!this->transport_->is_tcs_set ())
00105 {
00106 TAO_Codeset_Manager * const tcm =
00107 this->stub_->orb_core ()->codeset_manager ();
00108 if (tcm)
00109 tcm->set_tcs (*this->profile_, *this->transport_);
00110 }
00111 }
00112
00113 bool
00114 Profile_Transport_Resolver::try_connect (
00115 TAO_Transport_Descriptor_Interface *desc,
00116 ACE_Time_Value *timeout)
00117 {
00118 return this->try_connect_i (desc, timeout, false);
00119 }
00120
00121 bool
00122 Profile_Transport_Resolver::try_parallel_connect (
00123 TAO_Transport_Descriptor_Interface *desc,
00124 ACE_Time_Value *timeout)
00125 {
00126 return this->try_connect_i (desc, timeout, true);
00127 }
00128
00129
00130 bool
00131 Profile_Transport_Resolver::try_connect_i (
00132 TAO_Transport_Descriptor_Interface *desc,
00133 ACE_Time_Value *timeout,
00134 bool parallel)
00135 {
00136 TAO_Connector_Registry *conn_reg =
00137 this->stub_->orb_core ()->connector_registry ();
00138
00139 if (conn_reg == 0)
00140 {
00141 throw ::CORBA::INTERNAL (
00142 CORBA::SystemException::_tao_minor_code (
00143 0,
00144 EINVAL),
00145 CORBA::COMPLETED_NO);
00146 }
00147
00148 ACE_Time_Value connection_timeout;
00149 bool has_con_timeout = this->get_connection_timeout (connection_timeout);
00150
00151 if (has_con_timeout && !this->blocked_)
00152 {
00153 timeout = &connection_timeout;
00154 }
00155 else if (has_con_timeout)
00156 {
00157 if (timeout == 0 || connection_timeout < *timeout)
00158 timeout = &connection_timeout;
00159 else
00160 has_con_timeout = false;
00161 }
00162 else if (!this->blocked_)
00163 {
00164 timeout = 0;
00165 }
00166
00167 TAO_Connector *con = conn_reg->get_connector (desc->endpoint ()->tag ());
00168 ACE_ASSERT(con != 0);
00169 if (parallel)
00170 {
00171 this->transport_.set (con->parallel_connect (this, desc, timeout));
00172 }
00173 else
00174 {
00175 this->transport_.set (con->connect (this, desc, timeout));
00176 }
00177
00178
00179
00180
00181 if (this->transport_.get () == 0 &&
00182 has_con_timeout == false &&
00183 errno == ETIME)
00184 {
00185 throw ::CORBA::TIMEOUT (
00186 CORBA::SystemException::_tao_minor_code (
00187 TAO_TIMEOUT_CONNECT_MINOR_CODE,
00188 errno),
00189 CORBA::COMPLETED_NO);
00190 }
00191 else if (this->transport_.get () == 0)
00192 {
00193 return false;
00194 }
00195 else
00196 {
00197
00198 Messaging::SyncScope sync_scope;
00199 bool has_synchronization = false;
00200 this->stub_->orb_core ()->call_sync_scope_hook (this->stub_,
00201 has_synchronization,
00202 sync_scope);
00203
00204
00205
00206 if (has_synchronization && sync_scope != Messaging::SYNC_NONE)
00207 {
00208 this->transport_->set_flush_in_post_open ();
00209 }
00210 }
00211
00212 return true;
00213 }
00214
00215 bool
00216 Profile_Transport_Resolver::use_parallel_connect (void) const
00217 {
00218 TAO_ORB_Core *oc = this->stub_->orb_core();
00219 return (oc->orb_params()->use_parallel_connects()
00220 #if 0 // it was decided that even with blocked connects
00221
00222
00223 oc->client_factory()->connect_strategy() !=
00224 TAO_Client_Strategy_Factory::TAO_BLOCKED_CONNECT
00225 #endif
00226 );
00227 }
00228
00229 bool
00230 Profile_Transport_Resolver::get_connection_timeout (
00231 ACE_Time_Value &max_wait_time)
00232 {
00233 bool is_conn_timeout = false;
00234
00235
00236 this->stub_->orb_core ()->connection_timeout (this->stub_,
00237 is_conn_timeout,
00238 max_wait_time);
00239
00240 return is_conn_timeout;
00241 }
00242
00243
00244 void
00245 Profile_Transport_Resolver::init_inconsistent_policies (void)
00246 {
00247 ACE_NEW_THROW_EX (this->inconsistent_policies_,
00248 CORBA::PolicyList (0),
00249 CORBA::NO_MEMORY (
00250 CORBA::SystemException::_tao_minor_code (
00251 0,
00252 ENOMEM),
00253 CORBA::COMPLETED_NO));
00254 }
00255
00256
00257 int
00258 Profile_Transport_Resolver::find_transport (TAO_Transport_Descriptor_Interface *desc)
00259 {
00260 TAO::Transport_Cache_Manager & cache =
00261 this->profile_->orb_core()->lane_resources ().transport_cache();
00262
00263
00264
00265
00266 size_t busy_count;
00267 TAO_Transport* tmp = this->transport_.get ();
00268 if (cache.find_transport(desc, tmp, busy_count) !=
00269 Transport_Cache_Manager::CACHE_FOUND_AVAILABLE)
00270 return 0;
00271
00272 this->transport_.set (tmp);
00273 return 1;
00274 }
00275
00276 }
00277
00278 TAO_END_VERSIONED_NAMESPACE_DECL