Profile_Transport_Resolver.cpp

Go to the documentation of this file.
00001 // $Id: Profile_Transport_Resolver.cpp 79388 2007-08-17 16:05:00Z wilsond $
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 /* __ACE_INLINE__ */
00025 
00026 ACE_RCSID (tao,
00027            Profile_Transport_Resolver,
00028            "$Id: Profile_Transport_Resolver.cpp 79388 2007-08-17 16:05:00Z wilsond $")
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     // Dont do anything if the incoming profile is null
00060     if (p)
00061       {
00062         // @note This is just a workaround for a more serious problem
00063         // with profile management. This would cover some potential
00064         // issues that Ossama is working on.  Ossama, please remove
00065         // them when you are done.
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     // Select the endpoint
00088     es->select_endpoint (this, max_time_val);
00089 
00090     if (this->transport_.get () == 0)
00091       {
00092         throw ::CORBA::INTERNAL ();
00093       }
00094 
00095     TAO_GIOP_Message_Version const & version = this->profile_->version ();
00096 
00097     // Initialize the messaging object
00098     if (this->transport_->messaging_init (version.major, version.minor) == -1)
00099       {
00100         throw ::CORBA::INTERNAL (
00101                           CORBA::SystemException::_tao_minor_code (
00102                             0,
00103                             EINVAL),
00104                           CORBA::COMPLETED_NO);
00105       }
00106 
00107     if (!this->transport_->is_tcs_set ())
00108       {
00109         TAO_Codeset_Manager * const tcm =
00110           this->stub_->orb_core ()->codeset_manager ();
00111         if (tcm)
00112           tcm->set_tcs (*this->profile_, *this->transport_);
00113       }
00114   }
00115 
00116   bool
00117   Profile_Transport_Resolver::try_connect (
00118       TAO_Transport_Descriptor_Interface *desc,
00119       ACE_Time_Value *timeout)
00120   {
00121     return this->try_connect_i (desc, timeout, false);
00122   }
00123 
00124   bool
00125   Profile_Transport_Resolver::try_parallel_connect (
00126        TAO_Transport_Descriptor_Interface *desc,
00127        ACE_Time_Value *timeout)
00128   {
00129     return this->try_connect_i (desc, timeout, true);
00130   }
00131 
00132 
00133   bool
00134   Profile_Transport_Resolver::try_connect_i (
00135        TAO_Transport_Descriptor_Interface *desc,
00136        ACE_Time_Value *timeout,
00137        bool parallel)
00138   {
00139     TAO_Connector_Registry *conn_reg =
00140       this->stub_->orb_core ()->connector_registry ();
00141 
00142     if (conn_reg == 0)
00143       {
00144         throw ::CORBA::INTERNAL (
00145           CORBA::SystemException::_tao_minor_code (
00146             0,
00147             EINVAL),
00148           CORBA::COMPLETED_NO);
00149       }
00150 
00151     ACE_Time_Value connection_timeout;
00152     bool has_con_timeout = this->get_connection_timeout (connection_timeout);
00153 
00154     if (has_con_timeout && !this->blocked_)
00155       {
00156         timeout = &connection_timeout;
00157       }
00158     else if (has_con_timeout)
00159       {
00160         if (timeout == 0 || connection_timeout < *timeout)
00161           timeout = &connection_timeout;
00162         else
00163           has_con_timeout = false;
00164       }
00165     else if (!this->blocked_)
00166       {
00167         timeout = 0;
00168       }
00169 
00170     TAO_Connector *con = conn_reg->get_connector (desc->endpoint ()->tag ());
00171     ACE_ASSERT(con != 0);
00172     if (parallel)
00173       {
00174         this->transport_.set (con->parallel_connect (this, desc, timeout));
00175       }
00176     else
00177       {
00178         this->transport_.set (con->connect (this, desc, timeout));
00179       }
00180     // A timeout error occurred.
00181     // If the user has set a roundtrip timeout policy, throw a timeout
00182     // exception.  Otherwise, just fall through and return false to
00183     // look at the next endpoint.
00184     if (this->transport_.get () == 0 &&
00185         has_con_timeout == false &&
00186         errno == ETIME)
00187       {
00188         throw ::CORBA::TIMEOUT (
00189           CORBA::SystemException::_tao_minor_code (
00190             TAO_TIMEOUT_CONNECT_MINOR_CODE,
00191             errno),
00192           CORBA::COMPLETED_NO);
00193       }
00194     else if (this->transport_.get () == 0)
00195       {
00196         return false;
00197       }
00198 
00199     return true;
00200   }
00201 
00202   bool
00203   Profile_Transport_Resolver::use_parallel_connect (void) const
00204   {
00205     TAO_ORB_Core *oc = this->stub_->orb_core();
00206     return (oc->orb_params()->use_parallel_connects()
00207 #if 0       // it was decided that even with blocked connects
00208             // parallel connects could be useful, at least for cache
00209             // processing.
00210             oc->client_factory()->connect_strategy() !=
00211             TAO_Client_Strategy_Factory::TAO_BLOCKED_CONNECT
00212 #endif /* 0 */
00213             );
00214   }
00215 
00216   bool
00217   Profile_Transport_Resolver::get_connection_timeout (
00218     ACE_Time_Value &max_wait_time)
00219   {
00220     bool is_conn_timeout = false;
00221 
00222     // Check for the connection timout policy in the ORB
00223     this->stub_->orb_core ()->connection_timeout (this->stub_,
00224                                                   is_conn_timeout,
00225                                                   max_wait_time);
00226 
00227     return is_conn_timeout;
00228   }
00229 
00230 
00231   void
00232   Profile_Transport_Resolver::init_inconsistent_policies (void)
00233   {
00234     ACE_NEW_THROW_EX (this->inconsistent_policies_,
00235                       CORBA::PolicyList (0),
00236                       CORBA::NO_MEMORY (
00237                       CORBA::SystemException::_tao_minor_code (
00238                         0,
00239                         ENOMEM),
00240                       CORBA::COMPLETED_NO));
00241   }
00242 
00243 
00244   int
00245   Profile_Transport_Resolver::find_transport (TAO_Transport_Descriptor_Interface *desc)
00246   {
00247     TAO::Transport_Cache_Manager & cache =
00248       this->profile_->orb_core()->lane_resources ().transport_cache();
00249 
00250     // the cache increments the reference count on the transport if
00251     // the find is successful. Cache.find_transport returns 0 on success.
00252     // but we want to return a "boolean" of 0 for failure, 1 for success.
00253     TAO_Transport* tmp = this->transport_.get ();
00254     if (cache.find_transport(desc, tmp) != 0)
00255       return 0;
00256 
00257     this->transport_.set (tmp);
00258     return 1;
00259   }
00260 
00261 }
00262 
00263 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Sun Jan 27 13:07:36 2008 for TAO by doxygen 1.3.6