00001
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 84327 2009-02-05 13:49:01Z 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
00038 #if defined (TAO_USE_ST_CLIENT_CONNECTION_HANDLER)
00039 this->wait_strategy_ = TAO_WAIT_ON_REACTOR;
00040 #elif defined (TAO_USE_WAIT_ON_LF_NO_UPCALL)
00041 this->wait_strategy_ = TAO_WAIT_ON_LF_NO_UPCALL;
00042 #else
00043 this->wait_strategy_ = TAO_WAIT_ON_LEADER_FOLLOWER;
00044 #endif
00045
00046 #if TAO_USE_MUXED_TRANSPORT_MUX_STRATEGY == 1
00047 this->transport_mux_strategy_ = TAO_MUXED_TMS;
00048 #else
00049 this->transport_mux_strategy_ = TAO_EXCLUSIVE_TMS;
00050 #endif
00051
00052
00053 this->connect_strategy_ = TAO_LEADER_FOLLOWER_CONNECT;
00054 }
00055
00056 TAO_Default_Client_Strategy_Factory::~TAO_Default_Client_Strategy_Factory (void)
00057 {
00058 }
00059
00060 int
00061 TAO_Default_Client_Strategy_Factory::init (int argc, ACE_TCHAR* argv[])
00062 {
00063 return this->parse_args (argc, argv);
00064 }
00065
00066 int
00067 TAO_Default_Client_Strategy_Factory::parse_args (int argc, ACE_TCHAR* argv[])
00068 {
00069 ACE_TRACE ("TAO_Default_Client_Strategy_Factory::parse_args");
00070
00071 int curarg;
00072
00073 for (curarg = 0; curarg < argc && argv[curarg]; ++curarg)
00074 {
00075 if (ACE_OS::strcasecmp (argv[curarg],
00076 ACE_TEXT("-ORBProfileLock")) == 0)
00077 {
00078 curarg++;
00079 if (curarg < argc)
00080 {
00081 ACE_TCHAR* name = argv[curarg];
00082
00083 if (ACE_OS::strcasecmp (name,
00084 ACE_TEXT("thread")) == 0)
00085 this->profile_lock_type_ = TAO_THREAD_LOCK;
00086 else if (ACE_OS::strcasecmp (name,
00087 ACE_TEXT("null")) == 0)
00088 this->profile_lock_type_ = TAO_NULL_LOCK;
00089 else
00090 this->report_option_value_error (ACE_TEXT("-ORBProfileLock"), name);
00091 }
00092 }
00093 else if (ACE_OS::strcasecmp (argv[curarg],
00094 ACE_TEXT("-ORBIIOPProfileLock")) == 0)
00095 {
00096 ACE_DEBUG ((LM_DEBUG,
00097 ACE_TEXT ("WARNING: The -ORBIIOPProfileLock option")
00098 ACE_TEXT (" is deprecated and will be removed.\n")
00099 ACE_TEXT (" Please use -ORBProfileLock instead\n")));
00100 curarg++;
00101 if (curarg < argc)
00102 {
00103 ACE_TCHAR* name = argv[curarg];
00104
00105 if (ACE_OS::strcasecmp (name,
00106 ACE_TEXT("thread")) == 0)
00107 this->profile_lock_type_ = TAO_THREAD_LOCK;
00108 else if (ACE_OS::strcasecmp (name,
00109 ACE_TEXT("null")) == 0)
00110 this->profile_lock_type_ = TAO_NULL_LOCK;
00111 else
00112 this->report_option_value_error (ACE_TEXT("-ORBIIOPProfileLock"), name);
00113 }
00114 }
00115
00116 else if (ACE_OS::strcasecmp (argv[curarg],
00117 ACE_TEXT("-ORBClientConnectionHandler")) == 0
00118 ||
00119 ACE_OS::strcasecmp (argv[curarg],
00120 ACE_TEXT("-ORBWaitStrategy")) == 0)
00121 {
00122 curarg++;
00123 if (curarg < argc)
00124 {
00125 ACE_TCHAR* name = argv[curarg];
00126
00127 if (ACE_OS::strcasecmp (name,
00128 ACE_TEXT("MT")) == 0)
00129 this->wait_strategy_ = TAO_WAIT_ON_LEADER_FOLLOWER;
00130 else if (ACE_OS::strcasecmp (name,
00131 ACE_TEXT("ST")) == 0)
00132 this->wait_strategy_ = TAO_WAIT_ON_REACTOR;
00133 else if (ACE_OS::strcasecmp (name,
00134 ACE_TEXT("RW")) == 0)
00135 this->wait_strategy_ = TAO_WAIT_ON_READ;
00136 else if (ACE_OS::strcasecmp (name,
00137 ACE_TEXT("MT_NOUPCALL")) == 0)
00138 this->wait_strategy_ = TAO_WAIT_ON_LF_NO_UPCALL;
00139 else
00140 this->report_option_value_error (ACE_TEXT("-ORBClientConnectionHandler"), name);
00141 }
00142 }
00143 else if (ACE_OS::strcasecmp (argv[curarg],
00144 ACE_TEXT("-ORBTransportMuxStrategy")) == 0)
00145 {
00146 curarg++;
00147 if (curarg < argc)
00148 {
00149 ACE_TCHAR* name = argv[curarg];
00150
00151 if (ACE_OS::strcasecmp (name,
00152 ACE_TEXT("MUXED")) == 0)
00153 this->transport_mux_strategy_ = TAO_MUXED_TMS;
00154 else if (ACE_OS::strcasecmp (name,
00155 ACE_TEXT("EXCLUSIVE")) == 0)
00156 this->transport_mux_strategy_ = TAO_EXCLUSIVE_TMS;
00157 else
00158 this->report_option_value_error (ACE_TEXT("-ORBTransportMuxStrategy"), name);
00159 }
00160 }
00161 else if (ACE_OS::strcasecmp (argv[curarg],
00162 ACE_TEXT("-ORBTransportMuxStrategyLock")) == 0)
00163 {
00164 curarg++;
00165 if (curarg < argc)
00166 {
00167 ACE_TCHAR* name = argv[curarg];
00168
00169 if (ACE_OS::strcasecmp (name,
00170 ACE_TEXT("null")) == 0)
00171 this->muxed_strategy_lock_type_ = TAO_NULL_LOCK;
00172 else if (ACE_OS::strcasecmp (name,
00173 ACE_TEXT("thread")) == 0)
00174 this->muxed_strategy_lock_type_ = TAO_THREAD_LOCK;
00175 else
00176 this->report_option_value_error (ACE_TEXT("-ORBTransportMuxStrategyLock"), name);
00177 }
00178 }
00179 else if (ACE_OS::strcasecmp (argv[curarg],
00180 ACE_TEXT("-ORBConnectStrategy")) == 0)
00181 {
00182 curarg++;
00183 if (curarg < argc)
00184 {
00185 ACE_TCHAR* name = argv[curarg];
00186
00187 if (ACE_OS::strcasecmp (name,
00188 ACE_TEXT("Blocked")) == 0)
00189 this->connect_strategy_ = TAO_BLOCKED_CONNECT;
00190 else if (ACE_OS::strcasecmp (name,
00191 ACE_TEXT("Reactive")) == 0)
00192 this->connect_strategy_ = TAO_REACTIVE_CONNECT;
00193 else if (ACE_OS::strcasecmp (name,
00194 ACE_TEXT("LF")) == 0)
00195 this->connect_strategy_ = TAO_LEADER_FOLLOWER_CONNECT;
00196 else
00197 this->report_option_value_error (ACE_TEXT("-ORBConnectStrategy"), name);
00198 }
00199 }
00200 else if (ACE_OS::strcasecmp (argv[curarg],
00201 ACE_TEXT("-ORBReplyDispatcherTableSize")) == 0)
00202 {
00203 curarg++;
00204 if (curarg < argc)
00205 {
00206 this->rd_table_size_ = ACE_OS::atoi (argv[curarg]);
00207 }
00208 }
00209 else if (ACE_OS::strcmp (argv[curarg],
00210 ACE_TEXT("-ORBConnectionHandlerCleanup")) == 0)
00211 {
00212 curarg++;
00213 if (curarg < argc)
00214 {
00215 ACE_TCHAR* name = argv[curarg];
00216
00217 if (ACE_OS::strcmp (name, ACE_TEXT("0")) == 0 ||
00218 ACE_OS::strcasecmp (name, ACE_TEXT("false")) == 0)
00219 this->use_cleanup_options_ = false;
00220 else if (ACE_OS::strcmp (name, ACE_TEXT("1")) == 0 ||
00221 ACE_OS::strcasecmp (name, ACE_TEXT("true")) == 0)
00222 this->use_cleanup_options_ = true;
00223 else
00224 this->report_option_value_error (ACE_TEXT("-ORBConnectionHandlerCleanup"), name);
00225 }
00226 }
00227 else if (ACE_OS::strncmp (argv[curarg], ACE_TEXT("-ORB"), 4) == 0)
00228 {
00229
00230
00231 ACE_ERROR ((LM_ERROR,
00232 "Client_Strategy_Factory - "
00233 "unknown option <%s>\n",
00234 argv[curarg]));
00235 }
00236 else
00237 {
00238 ACE_DEBUG ((LM_DEBUG,
00239 "Client_Strategy_Factory - "
00240 "ignoring option <%s>\n",
00241 argv[curarg]));
00242 }
00243
00244
00245 }
00246 return 0;
00247 }
00248
00249 ACE_Lock *
00250 TAO_Default_Client_Strategy_Factory::create_profile_lock (void)
00251 {
00252 ACE_Lock *the_lock = 0;
00253
00254 switch (this->profile_lock_type_)
00255 {
00256 case TAO_NULL_LOCK:
00257 {
00258 ACE_NEW_RETURN (the_lock,
00259 ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX> (),
00260 0);
00261 break;
00262 }
00263 case TAO_THREAD_LOCK:
00264 {
00265 ACE_NEW_RETURN (the_lock,
00266 ACE_Lock_Adapter<TAO_SYNCH_MUTEX> (),
00267 0);
00268 break;
00269 }
00270 }
00271
00272 return the_lock;
00273 }
00274
00275 TAO_Configurable_Refcount
00276 TAO_Default_Client_Strategy_Factory::create_profile_refcount (void)
00277 {
00278 switch (this->profile_lock_type_)
00279 {
00280 case TAO_NULL_LOCK:
00281 return TAO_Configurable_Refcount (
00282 TAO_Configurable_Refcount::TAO_NULL_LOCK);
00283 case TAO_THREAD_LOCK:
00284 default:
00285 return TAO_Configurable_Refcount (
00286 TAO_Configurable_Refcount::TAO_THREAD_LOCK);
00287 }
00288 }
00289
00290
00291 TAO_Transport_Mux_Strategy *
00292 TAO_Default_Client_Strategy_Factory::create_transport_mux_strategy (TAO_Transport *transport)
00293 {
00294 TAO_Transport_Mux_Strategy *tms = 0;
00295
00296 switch (this->transport_mux_strategy_)
00297 {
00298 case TAO_MUXED_TMS:
00299 {
00300 ACE_NEW_RETURN (tms,
00301 TAO_Muxed_TMS (transport),
00302 0);
00303 break;
00304 }
00305 case TAO_EXCLUSIVE_TMS:
00306 {
00307 ACE_NEW_RETURN (tms,
00308 TAO_Exclusive_TMS (transport),
00309 0);
00310 break;
00311 }
00312 }
00313
00314 return tms;
00315 }
00316
00317 ACE_Lock *
00318 TAO_Default_Client_Strategy_Factory::create_transport_mux_strategy_lock (void)
00319 {
00320 ACE_Lock *the_lock = 0;
00321
00322 switch (this->muxed_strategy_lock_type_)
00323 {
00324 case TAO_NULL_LOCK:
00325 {
00326 ACE_NEW_RETURN (the_lock,
00327 ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX> (),
00328 0);
00329 break;
00330 }
00331 case TAO_THREAD_LOCK:
00332 {
00333 ACE_NEW_RETURN (the_lock,
00334 ACE_Lock_Adapter<TAO_SYNCH_RECURSIVE_MUTEX> (),
00335 0);
00336 break;
00337 }
00338 }
00339
00340 return the_lock;
00341 }
00342
00343 int
00344 TAO_Default_Client_Strategy_Factory::reply_dispatcher_table_size (void) const
00345 {
00346 return this->rd_table_size_;
00347 }
00348
00349 TAO_Wait_Strategy *
00350 TAO_Default_Client_Strategy_Factory::create_wait_strategy (TAO_Transport *transport)
00351 {
00352 TAO_Wait_Strategy *ws = 0;
00353
00354
00355
00356
00357
00358
00359 switch (this->wait_strategy_)
00360 {
00361 case TAO_WAIT_ON_LEADER_FOLLOWER :
00362 {
00363 ACE_NEW_RETURN (ws,
00364 TAO_Wait_On_Leader_Follower (transport),
00365 0);
00366 break;
00367 }
00368 case TAO_WAIT_ON_REACTOR:
00369 {
00370 ACE_NEW_RETURN (ws,
00371 TAO_Wait_On_Reactor (transport),
00372 0);
00373 break;
00374 }
00375 case TAO_WAIT_ON_READ:
00376 {
00377 ACE_NEW_RETURN (ws,
00378 TAO_Wait_On_Read (transport),
00379 0);
00380 break;
00381 }
00382 case TAO_WAIT_ON_LF_NO_UPCALL:
00383 {
00384 ACE_NEW_RETURN (ws,
00385 TAO::Wait_On_LF_No_Upcall (transport),
00386 0);
00387 break;
00388 }
00389 }
00390
00391
00392 return ws;
00393 }
00394
00395 TAO_Client_Strategy_Factory::Connect_Strategy
00396 TAO_Default_Client_Strategy_Factory::connect_strategy (void) const
00397 {
00398 return this->connect_strategy_;
00399 }
00400
00401 TAO_Connect_Strategy *
00402 TAO_Default_Client_Strategy_Factory::create_connect_strategy (TAO_ORB_Core *orb_core)
00403 {
00404 TAO_Connect_Strategy *cs = 0;
00405
00406 switch (this->connect_strategy_)
00407 {
00408 case TAO_BLOCKED_CONNECT:
00409 {
00410 ACE_NEW_RETURN (cs,
00411 TAO_Blocked_Connect_Strategy (orb_core),
00412 0);
00413 break;
00414 }
00415 case TAO_REACTIVE_CONNECT:
00416 {
00417 ACE_NEW_RETURN (cs,
00418 TAO_Reactive_Connect_Strategy (orb_core),
00419 0);
00420 break;
00421 }
00422 case TAO_LEADER_FOLLOWER_CONNECT :
00423 {
00424 ACE_NEW_RETURN (cs,
00425 TAO_LF_Connect_Strategy (orb_core),
00426 0);
00427 break;
00428 }
00429 }
00430
00431 return cs;
00432 }
00433
00434
00435 int
00436 TAO_Default_Client_Strategy_Factory::allow_callback (void)
00437 {
00438 return (this->wait_strategy_ != TAO_WAIT_ON_READ);
00439 }
00440
00441 void
00442 TAO_Default_Client_Strategy_Factory::report_option_value_error (
00443 const ACE_TCHAR* option_name,
00444 const ACE_TCHAR* option_value)
00445 {
00446 ACE_DEBUG((LM_DEBUG,
00447 ACE_TEXT ("Client_Strategy_Factory - unknown argument")
00448 ACE_TEXT (" <%s> for <%s>\n"),
00449 option_value, option_name));
00450 }
00451
00452 bool
00453 TAO_Default_Client_Strategy_Factory::use_cleanup_options (void) const
00454 {
00455 return this->use_cleanup_options_;
00456 }
00457
00458
00459
00460 ACE_STATIC_SVC_DEFINE (TAO_Default_Client_Strategy_Factory,
00461 ACE_TEXT ("Client_Strategy_Factory"),
00462 ACE_SVC_OBJ_T,
00463 &ACE_SVC_NAME (TAO_Default_Client_Strategy_Factory),
00464 ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00465 0)
00466 ACE_FACTORY_DEFINE (TAO, TAO_Default_Client_Strategy_Factory)
00467
00468 TAO_END_VERSIONED_NAMESPACE_DECL
00469