default_client.cpp

Go to the documentation of this file.
00001 // default_client.cpp,v 1.71 2006/04/26 17:12:48 mesnier_p Exp
00002 
00003 #include "tao/default_client.h"
00004 #include "tao/Wait_On_Read.h"
00005 #include "tao/Wait_On_Reactor.h"
00006 #include "tao/Wait_On_Leader_Follower.h"
00007 #include "tao/Wait_On_LF_No_Upcall.h"
00008 #include "tao/Exclusive_TMS.h"
00009 #include "tao/Muxed_TMS.h"
00010 #include "tao/Blocked_Connect_Strategy.h"
00011 #include "tao/Reactive_Connect_Strategy.h"
00012 #include "tao/LF_Connect_Strategy.h"
00013 #include "tao/orbconf.h"
00014 
00015 #include "ace/Lock_Adapter_T.h"
00016 #include "ace/Recursive_Thread_Mutex.h"
00017 
00018 #include "ace/OS_NS_strings.h"
00019 #include "ace/OS_NS_string.h"
00020 
00021 ACE_RCSID (tao,
00022            default_client,
00023            "default_client.cpp,v 1.71 2006/04/26 17:12:48 mesnier_p Exp")
00024 
00025 
00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00027 
00028 TAO_Default_Client_Strategy_Factory::TAO_Default_Client_Strategy_Factory (void)
00029   : profile_lock_type_ (TAO_THREAD_LOCK)
00030   , transport_mux_strategy_ (TAO_MUXED_TMS)
00031   , wait_strategy_ (TAO_WAIT_ON_LEADER_FOLLOWER)
00032   , connect_strategy_ (TAO_LEADER_FOLLOWER_CONNECT)
00033   , rd_table_size_ (TAO_RD_TABLE_SIZE)
00034   , muxed_strategy_lock_type_ (TAO_THREAD_LOCK)
00035   , use_cleanup_options_ (false)
00036 {
00037   // Use single thread client connection handler
00038 #if defined (TAO_USE_ST_CLIENT_CONNECTION_HANDLER)
00039   this->wait_strategy_ = TAO_WAIT_ON_REACTOR;
00040 #else
00041   this->wait_strategy_ = TAO_WAIT_ON_LEADER_FOLLOWER;
00042 #endif /* TAO_USE_ST_CLIENT_CONNECTION_HANDLER */
00043 
00044 #if TAO_USE_MUXED_TRANSPORT_MUX_STRATEGY == 1
00045   this->transport_mux_strategy_ = TAO_MUXED_TMS;
00046 #else
00047   this->transport_mux_strategy_ = TAO_EXCLUSIVE_TMS;
00048 #endif /* TAO_USE_MUXED_TRANSPORT_MUX_STRATEGY */
00049 
00050   // @@todo: will be changed when other strategies are implemented.
00051   this->connect_strategy_ = TAO_LEADER_FOLLOWER_CONNECT;
00052 }
00053 
00054 TAO_Default_Client_Strategy_Factory::~TAO_Default_Client_Strategy_Factory (void)
00055 {
00056 }
00057 
00058 int
00059 TAO_Default_Client_Strategy_Factory::init (int argc, ACE_TCHAR* argv[])
00060 {
00061   return this->parse_args (argc, argv);
00062 }
00063 
00064 int
00065 TAO_Default_Client_Strategy_Factory::parse_args (int argc, ACE_TCHAR* argv[])
00066 {
00067   ACE_TRACE ("TAO_Default_Client_Strategy_Factory::parse_args");
00068 
00069   int curarg;
00070 
00071   for (curarg = 0; curarg < argc && argv[curarg]; ++curarg)
00072     {
00073       if (ACE_OS::strcasecmp (argv[curarg],
00074                               ACE_TEXT("-ORBProfileLock")) == 0)
00075         {
00076         curarg++;
00077         if (curarg < argc)
00078           {
00079             ACE_TCHAR* name = argv[curarg];
00080 
00081             if (ACE_OS::strcasecmp (name,
00082                                     ACE_TEXT("thread")) == 0)
00083               this->profile_lock_type_ = TAO_THREAD_LOCK;
00084             else if (ACE_OS::strcasecmp (name,
00085                                          ACE_TEXT("null")) == 0)
00086               this->profile_lock_type_ = TAO_NULL_LOCK;
00087             else
00088               this->report_option_value_error (ACE_TEXT("-ORBProfileLock"), name);
00089           }
00090         }
00091       else if (ACE_OS::strcasecmp (argv[curarg],
00092                                    ACE_TEXT("-ORBIIOPProfileLock")) == 0)
00093         {
00094           ACE_DEBUG ((LM_DEBUG,
00095                       ACE_TEXT ("WARNING: The -ORBIIOPProfileLock option")
00096                       ACE_TEXT (" is deprecated and will be removed.\n")
00097                       ACE_TEXT ("         Please use -ORBProfileLock instead\n")));
00098           curarg++;
00099           if (curarg < argc)
00100             {
00101               ACE_TCHAR* name = argv[curarg];
00102 
00103               if (ACE_OS::strcasecmp (name,
00104                                       ACE_TEXT("thread")) == 0)
00105                 this->profile_lock_type_ = TAO_THREAD_LOCK;
00106               else if (ACE_OS::strcasecmp (name,
00107                                            ACE_TEXT("null")) == 0)
00108                 this->profile_lock_type_ = TAO_NULL_LOCK;
00109               else
00110                 this->report_option_value_error (ACE_TEXT("-ORBIIOPProfileLock"), name);
00111             }
00112         }
00113 
00114       else if (ACE_OS::strcasecmp (argv[curarg],
00115                                    ACE_TEXT("-ORBClientConnectionHandler")) == 0
00116                ||
00117                ACE_OS::strcasecmp (argv[curarg],
00118                                    ACE_TEXT("-ORBWaitStrategy")) == 0)
00119         {
00120           curarg++;
00121           if (curarg < argc)
00122             {
00123               ACE_TCHAR* name = argv[curarg];
00124 
00125               if (ACE_OS::strcasecmp (name,
00126                                       ACE_TEXT("MT")) == 0)
00127                 this->wait_strategy_ = TAO_WAIT_ON_LEADER_FOLLOWER;
00128               else if (ACE_OS::strcasecmp (name,
00129                                            ACE_TEXT("ST")) == 0)
00130                 this->wait_strategy_ = TAO_WAIT_ON_REACTOR;
00131               else if (ACE_OS::strcasecmp (name,
00132                                            ACE_TEXT("RW")) == 0)
00133                 this->wait_strategy_ = TAO_WAIT_ON_READ;
00134               else if (ACE_OS::strcasecmp (name,
00135                                            ACE_TEXT("MT_NOUPCALL")) == 0)
00136                 this->wait_strategy_ = TAO_WAIT_ON_LF_NO_UPCALL;
00137               else
00138                 this->report_option_value_error (ACE_TEXT("-ORBClientConnectionHandler"), name);
00139             }
00140         }
00141       else if (ACE_OS::strcasecmp (argv[curarg],
00142                                    ACE_TEXT("-ORBTransportMuxStrategy")) == 0)
00143         {
00144           curarg++;
00145           if (curarg < argc)
00146             {
00147               ACE_TCHAR* name = argv[curarg];
00148 
00149               if (ACE_OS::strcasecmp (name,
00150                                       ACE_TEXT("MUXED")) == 0)
00151                 this->transport_mux_strategy_ = TAO_MUXED_TMS;
00152               else if (ACE_OS::strcasecmp (name,
00153                                            ACE_TEXT("EXCLUSIVE")) == 0)
00154                 this->transport_mux_strategy_ = TAO_EXCLUSIVE_TMS;
00155               else
00156                 this->report_option_value_error (ACE_TEXT("-ORBTransportMuxStrategy"), name);
00157             }
00158         }
00159       else if (ACE_OS::strcasecmp (argv[curarg],
00160                                    ACE_TEXT("-ORBTransportMuxStrategyLock")) == 0)
00161         {
00162           curarg++;
00163           if (curarg < argc)
00164             {
00165               ACE_TCHAR* name = argv[curarg];
00166 
00167               if (ACE_OS::strcasecmp (name,
00168                                       ACE_TEXT("null")) == 0)
00169                 this->muxed_strategy_lock_type_ = TAO_NULL_LOCK;
00170               else if (ACE_OS::strcasecmp (name,
00171                                            ACE_TEXT("thread")) == 0)
00172                 this->muxed_strategy_lock_type_ = TAO_THREAD_LOCK;
00173               else
00174                 this->report_option_value_error (ACE_TEXT("-ORBTransportMuxStrategyLock"), name);
00175             }
00176         }
00177       else if (ACE_OS::strcasecmp (argv[curarg],
00178                                    ACE_TEXT("-ORBConnectStrategy")) == 0)
00179         {
00180           curarg++;
00181           if (curarg < argc)
00182             {
00183               ACE_TCHAR* name = argv[curarg];
00184 
00185               if (ACE_OS::strcasecmp (name,
00186                                       ACE_TEXT("Blocked")) == 0)
00187                 this->connect_strategy_ = TAO_BLOCKED_CONNECT;
00188               else if (ACE_OS::strcasecmp (name,
00189                                            ACE_TEXT("Reactive")) == 0)
00190                 this->connect_strategy_ = TAO_REACTIVE_CONNECT;
00191               else if (ACE_OS::strcasecmp (name,
00192                                            ACE_TEXT("LF")) == 0)
00193                 this->connect_strategy_ = TAO_LEADER_FOLLOWER_CONNECT;
00194               else
00195                 this->report_option_value_error (ACE_TEXT("-ORBConnectStrategy"), name);
00196             }
00197         }
00198       else if (ACE_OS::strcasecmp (argv[curarg],
00199                                    ACE_TEXT("-ORBReplyDispatcherTableSize")) == 0)
00200         {
00201           curarg++;
00202           if (curarg < argc)
00203             {
00204               this->rd_table_size_ = ACE_OS::atoi (argv[curarg]);
00205             }
00206         }
00207       else if (ACE_OS::strcmp (argv[curarg],
00208                                ACE_TEXT("-ORBConnectionHandlerCleanup")) == 0)
00209          {
00210            curarg++;
00211            if (curarg < argc)
00212              {
00213                ACE_TCHAR* name = argv[curarg];
00214 
00215                if (ACE_OS::strcmp (name, ACE_TEXT("0")) == 0 ||
00216                    ACE_OS::strcasecmp (name, ACE_TEXT("false")) == 0)
00217                  this->use_cleanup_options_ = false;
00218                else if (ACE_OS::strcmp (name, ACE_TEXT("1")) == 0 ||
00219                         ACE_OS::strcasecmp (name, ACE_TEXT("true")) == 0)
00220                  this->use_cleanup_options_ = true;
00221                else 
00222                  this->report_option_value_error (ACE_TEXT("-ORBConnectionHandlerCleanup"), name);
00223              }
00224          }
00225       else if (ACE_OS::strncmp (argv[curarg], ACE_TEXT("-ORB"), 4) == 0)
00226         {
00227           // Can we assume there is an argument after the option?
00228           // curarg++;
00229           ACE_ERROR ((LM_ERROR,
00230                       "Client_Strategy_Factory - "
00231                       "unknown option <%s>\n",
00232                       argv[curarg]));
00233         }
00234       else
00235         {
00236           ACE_DEBUG ((LM_DEBUG,
00237                       "Client_Strategy_Factory - "
00238                       "ignoring option <%s>\n",
00239                       argv[curarg]));
00240         }
00241 
00242 
00243     }
00244   return 0;
00245 }
00246 
00247 ACE_Lock *
00248 TAO_Default_Client_Strategy_Factory::create_profile_lock (void)
00249 {
00250   ACE_Lock *the_lock = 0;
00251 
00252   if (this->profile_lock_type_ == TAO_NULL_LOCK)
00253     ACE_NEW_RETURN (the_lock,
00254                     ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX> (),
00255                     0);
00256   else
00257     ACE_NEW_RETURN (the_lock,
00258                     ACE_Lock_Adapter<TAO_SYNCH_MUTEX> (),
00259                     0);
00260 
00261   return the_lock;
00262 }
00263 
00264 // Create the correct client transport muxing strategy.
00265 TAO_Transport_Mux_Strategy *
00266 TAO_Default_Client_Strategy_Factory::create_transport_mux_strategy (TAO_Transport *transport)
00267 {
00268   TAO_Transport_Mux_Strategy *tms = 0;
00269 
00270   if (this->transport_mux_strategy_ == TAO_MUXED_TMS)
00271     ACE_NEW_RETURN (tms,
00272                     TAO_Muxed_TMS (transport),
00273                     0);
00274   else
00275     ACE_NEW_RETURN (tms,
00276                     TAO_Exclusive_TMS (transport),
00277                     0);
00278 
00279   return tms;
00280 }
00281 
00282 ACE_Lock *
00283 TAO_Default_Client_Strategy_Factory::create_transport_mux_strategy_lock (void)
00284 {
00285   ACE_Lock *the_lock = 0;
00286 
00287   if (this->muxed_strategy_lock_type_ == TAO_NULL_LOCK)
00288     ACE_NEW_RETURN (the_lock,
00289                     ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX> (),
00290                     0);
00291   else
00292     ACE_NEW_RETURN (the_lock,
00293                     ACE_Lock_Adapter<TAO_SYNCH_RECURSIVE_MUTEX> (),
00294                     0);
00295 
00296   return the_lock;
00297 }
00298 
00299 int
00300 TAO_Default_Client_Strategy_Factory::reply_dispatcher_table_size (void) const
00301 {
00302   return this->rd_table_size_;
00303 }
00304 
00305 TAO_Wait_Strategy *
00306 TAO_Default_Client_Strategy_Factory::create_wait_strategy (TAO_Transport *transport)
00307 {
00308   TAO_Wait_Strategy *ws = 0;
00309 
00310   if (this->wait_strategy_ == TAO_WAIT_ON_READ)
00311     ACE_NEW_RETURN (ws,
00312                     TAO_Wait_On_Read (transport),
00313                     0);
00314   else if (this->wait_strategy_ == TAO_WAIT_ON_REACTOR)
00315     ACE_NEW_RETURN (ws,
00316                     TAO_Wait_On_Reactor (transport),
00317                     0);
00318   else if (this->wait_strategy_ == TAO_WAIT_ON_LF_NO_UPCALL)
00319     ACE_NEW_RETURN (ws,
00320                     TAO::Wait_On_LF_No_Upcall (transport),
00321                     0);
00322   else
00323     {
00324       // = Leader follower model.
00325 
00326       ACE_NEW_RETURN (ws,
00327                       TAO_Wait_On_Leader_Follower (transport),
00328                       0);
00329     }
00330 
00331   return ws;
00332 }
00333 
00334 TAO_Client_Strategy_Factory::Connect_Strategy
00335 TAO_Default_Client_Strategy_Factory::connect_strategy (void) const
00336 {
00337   return this->connect_strategy_;
00338 }
00339 
00340 TAO_Connect_Strategy *
00341 TAO_Default_Client_Strategy_Factory::create_connect_strategy (TAO_ORB_Core *orb_core)
00342 {
00343   TAO_Connect_Strategy *cs = 0;
00344 
00345   if (this->connect_strategy_ == TAO_BLOCKED_CONNECT)
00346     ACE_NEW_RETURN (cs,
00347                     TAO_Blocked_Connect_Strategy (orb_core),
00348                     0);
00349   else if (this->connect_strategy_ == TAO_REACTIVE_CONNECT)
00350     ACE_NEW_RETURN (cs,
00351                     TAO_Reactive_Connect_Strategy (orb_core),
00352                     0);
00353   else
00354     {
00355       // = Leader follower model.
00356 
00357       ACE_NEW_RETURN (cs,
00358                       TAO_LF_Connect_Strategy (orb_core),
00359                       0);
00360     }
00361 
00362   return cs;
00363 }
00364 
00365 
00366 int
00367 TAO_Default_Client_Strategy_Factory::allow_callback (void)
00368 {
00369   return (this->wait_strategy_ != TAO_WAIT_ON_READ);
00370 }
00371 
00372 ACE_Lock *
00373 TAO_Default_Client_Strategy_Factory::create_ft_service_retention_id_lock (void)
00374 {
00375   ACE_Lock *the_lock = 0;
00376 
00377   ACE_NEW_RETURN (the_lock,
00378                   ACE_Lock_Adapter<TAO_SYNCH_MUTEX>,
00379                   0);
00380 
00381   return the_lock;
00382 }
00383 
00384 void
00385 TAO_Default_Client_Strategy_Factory::report_option_value_error (
00386                                  const ACE_TCHAR* option_name,
00387                                  const ACE_TCHAR* option_value)
00388 {
00389   ACE_DEBUG((LM_DEBUG,
00390              ACE_TEXT ("Client_Strategy_Factory - unknown argument")
00391              ACE_TEXT (" <%s> for <%s>\n"),
00392              option_value, option_name));
00393 }
00394 
00395 bool
00396 TAO_Default_Client_Strategy_Factory::use_cleanup_options (void) const
00397 {
00398   return this->use_cleanup_options_;
00399 }
00400 
00401 TAO_END_VERSIONED_NAMESPACE_DECL
00402 
00403 // ****************************************************************
00404 
00405 ACE_STATIC_SVC_DEFINE (TAO_Default_Client_Strategy_Factory,
00406                        ACE_TEXT ("Client_Strategy_Factory"),
00407                        ACE_SVC_OBJ_T,
00408                        &ACE_SVC_NAME (TAO_Default_Client_Strategy_Factory),
00409                        ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00410                        0)
00411 ACE_FACTORY_DEFINE (TAO, TAO_Default_Client_Strategy_Factory)

Generated on Thu Nov 9 11:54:10 2006 for TAO by doxygen 1.3.6