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