default_client.cpp

Go to the documentation of this file.
00001 // $Id: default_client.cpp 79169 2007-08-02 08:41:23Z johnnyw $
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            "$Id: default_client.cpp 79169 2007-08-02 08:41:23Z johnnyw $")
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 TAO_Configurable_Refcount
00265 TAO_Default_Client_Strategy_Factory::create_profile_refcount (void)
00266 {
00267   switch (this->profile_lock_type_)
00268     {
00269     case TAO_NULL_LOCK:
00270       return TAO_Configurable_Refcount (
00271                      TAO_Configurable_Refcount::TAO_NULL_LOCK);
00272     case TAO_THREAD_LOCK:
00273     default:
00274       return TAO_Configurable_Refcount (
00275                      TAO_Configurable_Refcount::TAO_THREAD_LOCK);
00276     }
00277 }
00278 
00279 // Create the correct client transport muxing strategy.
00280 TAO_Transport_Mux_Strategy *
00281 TAO_Default_Client_Strategy_Factory::create_transport_mux_strategy (TAO_Transport *transport)
00282 {
00283   TAO_Transport_Mux_Strategy *tms = 0;
00284 
00285   if (this->transport_mux_strategy_ == TAO_MUXED_TMS)
00286     ACE_NEW_RETURN (tms,
00287                     TAO_Muxed_TMS (transport),
00288                     0);
00289   else
00290     ACE_NEW_RETURN (tms,
00291                     TAO_Exclusive_TMS (transport),
00292                     0);
00293 
00294   return tms;
00295 }
00296 
00297 ACE_Lock *
00298 TAO_Default_Client_Strategy_Factory::create_transport_mux_strategy_lock (void)
00299 {
00300   ACE_Lock *the_lock = 0;
00301 
00302   if (this->muxed_strategy_lock_type_ == TAO_NULL_LOCK)
00303     ACE_NEW_RETURN (the_lock,
00304                     ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX> (),
00305                     0);
00306   else
00307     ACE_NEW_RETURN (the_lock,
00308                     ACE_Lock_Adapter<TAO_SYNCH_RECURSIVE_MUTEX> (),
00309                     0);
00310 
00311   return the_lock;
00312 }
00313 
00314 int
00315 TAO_Default_Client_Strategy_Factory::reply_dispatcher_table_size (void) const
00316 {
00317   return this->rd_table_size_;
00318 }
00319 
00320 TAO_Wait_Strategy *
00321 TAO_Default_Client_Strategy_Factory::create_wait_strategy (TAO_Transport *transport)
00322 {
00323   TAO_Wait_Strategy *ws = 0;
00324 
00325 /*
00326  * Hook to customize the wait strategy object when the concrete wait strategy
00327  * object is known a priori.
00328  */
00329 //@@ WAIT_STRATEGY_SPL_COMMENT_HOOK_START
00330   if (this->wait_strategy_ == TAO_WAIT_ON_READ)
00331     ACE_NEW_RETURN (ws,
00332                     TAO_Wait_On_Read (transport),
00333                     0);
00334   else if (this->wait_strategy_ == TAO_WAIT_ON_REACTOR)
00335     ACE_NEW_RETURN (ws,
00336                     TAO_Wait_On_Reactor (transport),
00337                     0);
00338   else if (this->wait_strategy_ == TAO_WAIT_ON_LF_NO_UPCALL)
00339     ACE_NEW_RETURN (ws,
00340                     TAO::Wait_On_LF_No_Upcall (transport),
00341                     0);
00342   else
00343     {
00344       // = Leader follower model.
00345 
00346       ACE_NEW_RETURN (ws,
00347                       TAO_Wait_On_Leader_Follower (transport),
00348                       0);
00349     }
00350 //@@ WAIT_STRATEGY_SPL_COMMENT_HOOK_END
00351 
00352   return ws;
00353 }
00354 
00355 TAO_Client_Strategy_Factory::Connect_Strategy
00356 TAO_Default_Client_Strategy_Factory::connect_strategy (void) const
00357 {
00358   return this->connect_strategy_;
00359 }
00360 
00361 TAO_Connect_Strategy *
00362 TAO_Default_Client_Strategy_Factory::create_connect_strategy (TAO_ORB_Core *orb_core)
00363 {
00364   TAO_Connect_Strategy *cs = 0;
00365 
00366   if (this->connect_strategy_ == TAO_BLOCKED_CONNECT)
00367     ACE_NEW_RETURN (cs,
00368                     TAO_Blocked_Connect_Strategy (orb_core),
00369                     0);
00370   else if (this->connect_strategy_ == TAO_REACTIVE_CONNECT)
00371     ACE_NEW_RETURN (cs,
00372                     TAO_Reactive_Connect_Strategy (orb_core),
00373                     0);
00374   else
00375     {
00376       // = Leader follower model.
00377 
00378       ACE_NEW_RETURN (cs,
00379                       TAO_LF_Connect_Strategy (orb_core),
00380                       0);
00381     }
00382 
00383   return cs;
00384 }
00385 
00386 
00387 int
00388 TAO_Default_Client_Strategy_Factory::allow_callback (void)
00389 {
00390   return (this->wait_strategy_ != TAO_WAIT_ON_READ);
00391 }
00392 
00393 void
00394 TAO_Default_Client_Strategy_Factory::report_option_value_error (
00395                                  const ACE_TCHAR* option_name,
00396                                  const ACE_TCHAR* option_value)
00397 {
00398   ACE_DEBUG((LM_DEBUG,
00399              ACE_TEXT ("Client_Strategy_Factory - unknown argument")
00400              ACE_TEXT (" <%s> for <%s>\n"),
00401              option_value, option_name));
00402 }
00403 
00404 bool
00405 TAO_Default_Client_Strategy_Factory::use_cleanup_options (void) const
00406 {
00407   return this->use_cleanup_options_;
00408 }
00409 
00410 TAO_END_VERSIONED_NAMESPACE_DECL
00411 
00412 // ****************************************************************
00413 
00414 ACE_STATIC_SVC_DEFINE (TAO_Default_Client_Strategy_Factory,
00415                        ACE_TEXT ("Client_Strategy_Factory"),
00416                        ACE_SVC_OBJ_T,
00417                        &ACE_SVC_NAME (TAO_Default_Client_Strategy_Factory),
00418                        ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00419                        0)
00420 ACE_FACTORY_DEFINE (TAO, TAO_Default_Client_Strategy_Factory)

Generated on Tue Feb 2 17:37:51 2010 for TAO by  doxygen 1.4.7