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
00021 #if !defined (__ACE_INLINE__)
00022 # include "tao/Profile_Transport_Resolver.inl"
00023 #endif
00024
00025 ACE_RCSID (tao,
00026 Profile_Transport_Resolver,
00027 "Profile_Transport_Resolver.cpp,v 1.18 2006/04/30 14:25:48 mesnier_p Exp")
00028
00029
00030 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00031
00032 namespace TAO
00033 {
00034
00035 Profile_Transport_Resolver::~Profile_Transport_Resolver (void)
00036 {
00037 if (this->profile_)
00038 {
00039 this->profile_->_decr_refcnt ();
00040 }
00041
00042 if (this->transport_)
00043 {
00044 if (this->is_released_ == false)
00045 {
00046 this->transport_->make_idle ();
00047 }
00048
00049 this->transport_->remove_reference ();
00050 }
00051
00052 delete this->inconsistent_policies_;
00053 }
00054
00055 void
00056 Profile_Transport_Resolver::profile (TAO_Profile *p)
00057 {
00058
00059 if (p)
00060 {
00061
00062
00063
00064
00065 TAO_Profile *tmp = this->profile_;
00066
00067 (void) p->_incr_refcnt ();
00068 this->profile_ = p;
00069
00070 if (tmp)
00071 {
00072 (void) tmp->_decr_refcnt ();
00073 }
00074 }
00075 }
00076
00077
00078 void
00079 Profile_Transport_Resolver::resolve (ACE_Time_Value *max_time_val
00080 ACE_ENV_ARG_DECL)
00081 ACE_THROW_SPEC ((CORBA::SystemException))
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 ACE_ENV_SINGLE_ARG_PARAMETER);
00088 ACE_CHECK;
00089
00090
00091 es->select_endpoint (this,
00092 max_time_val
00093 ACE_ENV_ARG_PARAMETER);
00094 ACE_CHECK;
00095
00096 if (this->transport_ == 0)
00097 {
00098 ACE_THROW (CORBA::INTERNAL ());
00099 }
00100
00101 const TAO_GIOP_Message_Version& version =
00102 this->profile_->version ();
00103
00104
00105 if (this->transport_->messaging_init (version.major, version.minor) == -1)
00106 {
00107 ACE_THROW (CORBA::INTERNAL (
00108 CORBA::SystemException::_tao_minor_code (
00109 0,
00110 EINVAL),
00111 CORBA::COMPLETED_NO));
00112 }
00113
00114 if (!this->transport_->is_tcs_set ())
00115 {
00116 TAO_Codeset_Manager * const tcm =
00117 this->stub_->orb_core ()->codeset_manager ();
00118 if (tcm)
00119 tcm->set_tcs (*this->profile_, *this->transport_);
00120 }
00121 }
00122
00123 bool
00124 Profile_Transport_Resolver::try_connect (
00125 TAO_Transport_Descriptor_Interface *desc,
00126 ACE_Time_Value *max_time_value
00127 ACE_ENV_ARG_DECL
00128 )
00129 {
00130 return this->try_connect_i (desc,max_time_value,0 ACE_ENV_ARG_PARAMETER);
00131 }
00132
00133 bool
00134 Profile_Transport_Resolver::try_parallel_connect (
00135 TAO_Transport_Descriptor_Interface *desc,
00136 ACE_Time_Value *max_time_value
00137 ACE_ENV_ARG_DECL
00138 )
00139 {
00140 return this->try_connect_i (desc,max_time_value,1 ACE_ENV_ARG_PARAMETER);
00141 }
00142
00143
00144 bool
00145 Profile_Transport_Resolver::try_connect_i (
00146 TAO_Transport_Descriptor_Interface *desc,
00147 ACE_Time_Value *max_time_value,
00148 bool parallel
00149 ACE_ENV_ARG_DECL
00150 )
00151 {
00152 TAO_Connector_Registry *conn_reg =
00153 this->stub_->orb_core ()->connector_registry (
00154 ACE_ENV_SINGLE_ARG_PARAMETER);
00155 ACE_CHECK_RETURN (false);
00156
00157 if (conn_reg == 0)
00158 {
00159 ACE_THROW_RETURN (CORBA::INTERNAL (
00160 CORBA::SystemException::_tao_minor_code (
00161 0,
00162 EINVAL),
00163 CORBA::COMPLETED_NO),
00164 false);
00165 }
00166
00167 ACE_Time_Value connection_timeout;
00168
00169 bool const is_conn_timeout =
00170 this->get_connection_timeout (connection_timeout);
00171
00172 ACE_Time_Value *max_wait_time =
00173 is_conn_timeout ? &connection_timeout : max_time_value;
00174
00175 if (parallel)
00176 {
00177 this->transport_ =
00178 conn_reg->get_connector (desc->endpoint ()->tag ())->
00179 parallel_connect (this,
00180 desc,
00181 max_wait_time
00182 ACE_ENV_ARG_PARAMETER);
00183 ACE_CHECK_RETURN (false);
00184 }
00185 else
00186 {
00187
00188 this->transport_ =
00189 conn_reg->get_connector (desc->endpoint ()->tag ())->
00190 connect (this,
00191 desc,
00192 max_wait_time
00193 ACE_ENV_ARG_PARAMETER);
00194 ACE_CHECK_RETURN (false);
00195 }
00196
00197
00198
00199
00200 if (this->transport_ == 0
00201 && is_conn_timeout == false
00202 && errno == ETIME)
00203 {
00204 ACE_THROW_RETURN (CORBA::TIMEOUT (
00205 CORBA::SystemException::_tao_minor_code (
00206 TAO_TIMEOUT_CONNECT_MINOR_CODE,
00207 errno),
00208 CORBA::COMPLETED_NO),
00209 false);
00210 }
00211 else if (this->transport_ == 0)
00212 {
00213 return false;
00214 }
00215
00216 return true;
00217 }
00218
00219 bool
00220 Profile_Transport_Resolver::use_parallel_connect (void) const
00221 {
00222 TAO_ORB_Core *oc = this->stub_->orb_core();
00223 return (oc->orb_params()->use_parallel_connects()
00224 #if 0
00225
00226
00227 oc->client_factory()->connect_strategy() !=
00228 TAO_Client_Strategy_Factory::TAO_BLOCKED_CONNECT
00229 #endif
00230 );
00231 }
00232
00233 bool
00234 Profile_Transport_Resolver::get_connection_timeout (
00235 ACE_Time_Value &max_wait_time)
00236 {
00237 bool is_conn_timeout = false;
00238
00239
00240 this->stub_->orb_core ()->connection_timeout (this->stub_,
00241 is_conn_timeout,
00242 max_wait_time);
00243
00244 return is_conn_timeout;
00245 }
00246
00247
00248 void
00249 Profile_Transport_Resolver::init_inconsistent_policies (
00250 ACE_ENV_SINGLE_ARG_DECL)
00251 ACE_THROW_SPEC ((CORBA::SystemException))
00252 {
00253 ACE_NEW_THROW_EX (this->inconsistent_policies_,
00254 CORBA::PolicyList (0),
00255 CORBA::NO_MEMORY (
00256 CORBA::SystemException::_tao_minor_code (
00257 0,
00258 ENOMEM),
00259 CORBA::COMPLETED_NO));
00260 }
00261
00262
00263 int
00264 Profile_Transport_Resolver::find_transport (TAO_Transport_Descriptor_Interface *desc)
00265 {
00266 TAO::Transport_Cache_Manager & cache =
00267 this->profile_->orb_core()->lane_resources ().transport_cache();
00268
00269
00270
00271
00272 return (cache.find_transport(desc,this->transport_) == 0);
00273 }
00274
00275
00276 }
00277
00278 TAO_END_VERSIONED_NAMESPACE_DECL