Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / default_client.cpp
blob221e680cb50e82e7457346086d87026f1f5b4565
1 // -*- C++ -*-
2 #include "tao/default_client.h"
3 #include "tao/Wait_On_Read.h"
4 #include "tao/Wait_On_Reactor.h"
5 #include "tao/Wait_On_Leader_Follower.h"
6 #include "tao/Wait_On_LF_No_Upcall.h"
7 #include "tao/Exclusive_TMS.h"
8 #include "tao/Muxed_TMS.h"
9 #include "tao/Blocked_Connect_Strategy.h"
10 #include "tao/Reactive_Connect_Strategy.h"
11 #include "tao/LF_Connect_Strategy.h"
12 #include "tao/orbconf.h"
13 #include "tao/Invocation_Utils.h"
14 #include "tao/Messaging_SyncScopeC.h"
16 #include "ace/Lock_Adapter_T.h"
17 #include "ace/Recursive_Thread_Mutex.h"
19 #include "ace/OS_NS_strings.h"
20 #include "ace/OS_NS_string.h"
22 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
24 TAO_Default_Client_Strategy_Factory::TAO_Default_Client_Strategy_Factory ()
25 : transport_mux_strategy_ (TAO_MUXED_TMS)
26 , wait_strategy_ (TAO_WAIT_ON_LEADER_FOLLOWER)
27 , connect_strategy_ (TAO_LEADER_FOLLOWER_CONNECT)
28 , rd_table_size_ (TAO_RD_TABLE_SIZE)
29 , muxed_strategy_lock_type_ (TAO_THREAD_LOCK)
30 , use_cleanup_options_ (false)
31 , sync_scope_ (Messaging::SYNC_WITH_TRANSPORT)
33 // Use single thread client connection handler
34 #if defined (TAO_USE_ST_CLIENT_CONNECTION_HANDLER)
35 this->wait_strategy_ = TAO_WAIT_ON_REACTOR;
36 #elif defined (TAO_USE_WAIT_ON_LF_NO_UPCALL)
37 this->wait_strategy_ = TAO_WAIT_ON_LF_NO_UPCALL;
38 #elif defined (TAO_USE_WAIT_RW_STRATEGY)
39 this->wait_strategy_ = TAO_WAIT_ON_READ;
40 #else
41 this->wait_strategy_ = TAO_WAIT_ON_LEADER_FOLLOWER;
42 #endif /* TAO_USE_ST_CLIENT_CONNECTION_HANDLER */
44 #if TAO_USE_MUXED_TRANSPORT_MUX_STRATEGY == 1
45 this->transport_mux_strategy_ = TAO_MUXED_TMS;
46 #else
47 this->transport_mux_strategy_ = TAO_EXCLUSIVE_TMS;
48 #endif /* TAO_USE_MUXED_TRANSPORT_MUX_STRATEGY */
50 #if defined (TAO_USE_BLOCKING_CONNECT_STRATEGY)
51 this->connect_strategy_ = TAO_BLOCKED_CONNECT;
52 #elif defined (TAO_USE_REACTIVE_CONNECT_STRATEGY)
53 this->connect_strategy_ = TAO_REACTIVE_CONNECT;
54 #else
55 // @todo: will be changed when other strategies are implemented.
56 this->connect_strategy_ = TAO_LEADER_FOLLOWER_CONNECT;
57 #endif
60 TAO_Default_Client_Strategy_Factory::~TAO_Default_Client_Strategy_Factory ()
64 int
65 TAO_Default_Client_Strategy_Factory::init (int argc, ACE_TCHAR* argv[])
67 return this->parse_args (argc, argv);
70 int
71 TAO_Default_Client_Strategy_Factory::parse_args (int argc, ACE_TCHAR* argv[])
73 ACE_TRACE ("TAO_Default_Client_Strategy_Factory::parse_args");
75 int curarg;
77 for (curarg = 0; curarg < argc && argv[curarg]; ++curarg)
79 if (ACE_OS::strcasecmp (argv[curarg],
80 ACE_TEXT("-ORBClientConnectionHandler")) == 0
82 ACE_OS::strcasecmp (argv[curarg],
83 ACE_TEXT("-ORBWaitStrategy")) == 0)
85 curarg++;
86 if (curarg < argc)
88 ACE_TCHAR* name = argv[curarg];
90 if (ACE_OS::strcasecmp (name,
91 ACE_TEXT("MT")) == 0)
92 this->wait_strategy_ = TAO_WAIT_ON_LEADER_FOLLOWER;
93 else if (ACE_OS::strcasecmp (name,
94 ACE_TEXT("ST")) == 0)
95 this->wait_strategy_ = TAO_WAIT_ON_REACTOR;
96 else if (ACE_OS::strcasecmp (name,
97 ACE_TEXT("RW")) == 0)
98 this->wait_strategy_ = TAO_WAIT_ON_READ;
99 else if (ACE_OS::strcasecmp (name,
100 ACE_TEXT("MT_NOUPCALL")) == 0)
101 this->wait_strategy_ = TAO_WAIT_ON_LF_NO_UPCALL;
102 else
103 this->report_option_value_error (
104 ACE_TEXT("-ORBClientConnectionHandler"), name);
107 else if (ACE_OS::strcasecmp (argv[curarg],
108 ACE_TEXT("-ORBTransportMuxStrategy"))
109 == 0)
111 curarg++;
112 if (curarg < argc)
114 ACE_TCHAR* name = argv[curarg];
116 if (ACE_OS::strcasecmp (name,
117 ACE_TEXT("MUXED")) == 0)
118 this->transport_mux_strategy_ = TAO_MUXED_TMS;
119 else if (ACE_OS::strcasecmp (name,
120 ACE_TEXT("EXCLUSIVE")) == 0)
121 this->transport_mux_strategy_ = TAO_EXCLUSIVE_TMS;
122 else
123 this->report_option_value_error (
124 ACE_TEXT("-ORBTransportMuxStrategy"), name);
127 else if (ACE_OS::strcasecmp (argv[curarg],
128 ACE_TEXT("-ORBTransportMuxStrategyLock"))
129 == 0)
131 curarg++;
132 if (curarg < argc)
134 ACE_TCHAR* name = argv[curarg];
136 if (ACE_OS::strcasecmp (name,
137 ACE_TEXT("null")) == 0)
138 this->muxed_strategy_lock_type_ = TAO_NULL_LOCK;
139 else if (ACE_OS::strcasecmp (name,
140 ACE_TEXT("thread")) == 0)
141 this->muxed_strategy_lock_type_ = TAO_THREAD_LOCK;
142 else
143 this->report_option_value_error (
144 ACE_TEXT("-ORBTransportMuxStrategyLock"), name);
147 else if (ACE_OS::strcasecmp (argv[curarg],
148 ACE_TEXT("-ORBConnectStrategy")) == 0)
150 curarg++;
151 if (curarg < argc)
153 ACE_TCHAR* name = argv[curarg];
155 if (ACE_OS::strcasecmp (name,
156 ACE_TEXT("Blocked")) == 0)
157 this->connect_strategy_ = TAO_BLOCKED_CONNECT;
158 else if (ACE_OS::strcasecmp (name,
159 ACE_TEXT("Reactive")) == 0)
160 this->connect_strategy_ = TAO_REACTIVE_CONNECT;
161 else if (ACE_OS::strcasecmp (name,
162 ACE_TEXT("LF")) == 0)
163 this->connect_strategy_ = TAO_LEADER_FOLLOWER_CONNECT;
164 else
165 this->report_option_value_error (
166 ACE_TEXT("-ORBConnectStrategy"),
167 name);
170 else if (ACE_OS::strcasecmp (argv[curarg],
171 ACE_TEXT ("-ORBDefaultSyncScope")) == 0)
173 ++curarg;
174 if (curarg < argc)
176 ACE_TCHAR const * const current_arg = argv[curarg];
178 if (ACE_OS::strcasecmp (current_arg,
179 ACE_TEXT("none")) == 0)
181 this->sync_scope_ = Messaging::SYNC_NONE;
183 else if (ACE_OS::strcasecmp (current_arg,
184 ACE_TEXT("transport")) == 0)
186 this->sync_scope_ = Messaging::SYNC_WITH_TRANSPORT;
188 else if (ACE_OS::strcasecmp (current_arg,
189 ACE_TEXT("server")) == 0)
191 this->sync_scope_ = Messaging::SYNC_WITH_SERVER;
193 else if (ACE_OS::strcasecmp (current_arg,
194 ACE_TEXT("target")) == 0)
196 this->sync_scope_ = Messaging::SYNC_WITH_TARGET;
198 else
200 this->report_option_value_error (ACE_TEXT("-ORBDefaultSyncScope"),
201 argv[curarg]);
202 continue;
207 else if (ACE_OS::strcasecmp (argv[curarg],
208 ACE_TEXT("-ORBReplyDispatcherTableSize"))
209 == 0)
211 curarg++;
212 if (curarg < argc)
214 this->rd_table_size_ = ACE_OS::atoi (argv[curarg]);
217 else if (ACE_OS::strcmp (argv[curarg],
218 ACE_TEXT("-ORBConnectionHandlerCleanup")) == 0)
220 curarg++;
221 if (curarg < argc)
223 ACE_TCHAR* name = argv[curarg];
225 if (ACE_OS::strcmp (name, ACE_TEXT("0")) == 0 ||
226 ACE_OS::strcasecmp (name, ACE_TEXT("false")) == 0)
227 this->use_cleanup_options_ = false;
228 else if (ACE_OS::strcmp (name, ACE_TEXT("1")) == 0 ||
229 ACE_OS::strcasecmp (name, ACE_TEXT("true")) == 0)
230 this->use_cleanup_options_ = true;
231 else
232 this->report_option_value_error (
233 ACE_TEXT("-ORBConnectionHandlerCleanup"), name);
236 else if (ACE_OS::strcmp (argv[curarg],
237 ACE_TEXT("-ORBForwardOnCommFailureLimit"))
238 == 0)
240 curarg++;
241 if (curarg < argc)
243 ACE_TCHAR* name = argv[curarg];
245 ACE_TCHAR *err = nullptr;
246 long limit = ACE_OS::strtol (name, &err, 10);
247 if (err && *err != 0)
249 this->report_option_value_error (
250 ACE_TEXT("-ORBForwardOnCommFailureLimit"),
251 name);
253 else
254 this->invocation_retry_params_
255 .forward_on_exception_limit_[TAO::FOE_COMM_FAILURE] =
256 limit;
259 else if (ACE_OS::strcmp (argv[curarg],
260 ACE_TEXT("-ORBForwardOnTransientLimit")) == 0)
262 curarg++;
263 if (curarg < argc)
265 ACE_TCHAR* name = argv[curarg];
267 ACE_TCHAR *err = nullptr;
268 long limit = ACE_OS::strtol (name, &err, 10);
269 if (err && *err != 0)
271 this->report_option_value_error (
272 ACE_TEXT("-ORBForwardOnTransientLimit"),
273 name);
275 else
276 this->invocation_retry_params_
277 .forward_on_exception_limit_[TAO::FOE_TRANSIENT] =
278 limit;
281 else if (ACE_OS::strcmp (argv[curarg],
282 ACE_TEXT("-ORBForwardOnObjectNotExistLimit"))
283 == 0)
285 curarg++;
286 if (curarg < argc)
288 ACE_TCHAR* name = argv[curarg];
290 ACE_TCHAR *err = nullptr;
291 long limit = ACE_OS::strtol (name, &err, 10);
292 if (err && *err != 0)
294 this->report_option_value_error (
295 ACE_TEXT("-ORBForwardOnObjectNotExistLimit"),
296 name);
298 else
299 this->invocation_retry_params_
300 .forward_on_exception_limit_[TAO::FOE_OBJECT_NOT_EXIST] =
301 limit;
304 else if (ACE_OS::strcmp (argv[curarg],
305 ACE_TEXT("-ORBForwardOnInvObjrefLimit")) == 0)
307 curarg++;
308 if (curarg < argc)
310 ACE_TCHAR* name = argv[curarg];
312 ACE_TCHAR *err = nullptr;
313 long limit = ACE_OS::strtol (name, &err, 10);
314 if (err && *err != 0)
316 this->report_option_value_error (
317 ACE_TEXT("-ORBForwardOnInvObjrefLimit"), name);
319 else
320 this->invocation_retry_params_
321 .forward_on_exception_limit_[TAO::FOE_INV_OBJREF] =
322 limit;
325 else if (ACE_OS::strcmp (argv[curarg],
326 ACE_TEXT("-ORBForwardOnReplyClosedLimit"))
327 == 0)
329 curarg++;
330 if (curarg < argc)
332 ACE_TCHAR* name = argv[curarg];
334 ACE_TCHAR *err = nullptr;
335 long limit = ACE_OS::strtol (name, &err, 10);
336 if (err && *err != 0)
338 this->report_option_value_error (
339 ACE_TEXT("-ORBForwardOnReplyClosedLimit"), name);
341 else
342 this->invocation_retry_params_
343 .forward_on_reply_closed_limit_ = limit;
346 else if (ACE_OS::strncmp (argv[curarg], ACE_TEXT("-ORB"), 4) == 0)
348 // Can we assume there is an argument after the option?
349 // curarg++;
350 TAOLIB_ERROR ((LM_ERROR,
351 "Client_Strategy_Factory - "
352 "unknown option <%s>\n",
353 argv[curarg]));
355 else
357 TAOLIB_DEBUG ((LM_DEBUG,
358 "Client_Strategy_Factory - "
359 "ignoring option <%s>\n",
360 argv[curarg]));
363 return 0;
366 /// Create the correct client transport muxing strategy.
367 TAO_Transport_Mux_Strategy *
368 TAO_Default_Client_Strategy_Factory::create_transport_mux_strategy (
369 TAO_Transport *transport)
371 TAO_Transport_Mux_Strategy *tms = nullptr;
373 switch (this->transport_mux_strategy_)
375 case TAO_MUXED_TMS:
377 ACE_NEW_RETURN (tms,
378 TAO_Muxed_TMS (transport),
379 nullptr);
380 break;
382 case TAO_EXCLUSIVE_TMS:
384 ACE_NEW_RETURN (tms,
385 TAO_Exclusive_TMS (transport),
386 nullptr);
387 break;
391 return tms;
394 ACE_Lock *
395 TAO_Default_Client_Strategy_Factory::create_transport_mux_strategy_lock ()
397 ACE_Lock *the_lock = nullptr;
399 switch (this->muxed_strategy_lock_type_)
401 case TAO_NULL_LOCK:
403 ACE_NEW_RETURN (the_lock,
404 ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX> (),
405 nullptr);
406 break;
408 case TAO_THREAD_LOCK:
410 ACE_NEW_RETURN (the_lock,
411 ACE_Lock_Adapter<TAO_SYNCH_RECURSIVE_MUTEX> (),
412 nullptr);
413 break;
417 return the_lock;
421 TAO_Default_Client_Strategy_Factory::reply_dispatcher_table_size () const
423 return this->rd_table_size_;
426 TAO_Wait_Strategy *
427 TAO_Default_Client_Strategy_Factory::create_wait_strategy (
428 TAO_Transport *transport)
430 TAO_Wait_Strategy *ws = nullptr;
432 switch (this->wait_strategy_)
434 case TAO_WAIT_ON_LEADER_FOLLOWER :
436 ACE_NEW_RETURN (ws,
437 TAO_Wait_On_Leader_Follower (transport),
438 nullptr);
439 break;
441 case TAO_WAIT_ON_REACTOR:
443 ACE_NEW_RETURN (ws,
444 TAO_Wait_On_Reactor (transport),
445 nullptr);
446 break;
448 case TAO_WAIT_ON_READ:
450 ACE_NEW_RETURN (ws,
451 TAO_Wait_On_Read (transport),
452 nullptr);
453 break;
455 case TAO_WAIT_ON_LF_NO_UPCALL:
457 ACE_NEW_RETURN (ws,
458 TAO::Wait_On_LF_No_Upcall (transport),
459 nullptr);
460 break;
464 return ws;
467 TAO_Client_Strategy_Factory::Connect_Strategy
468 TAO_Default_Client_Strategy_Factory::connect_strategy () const
470 return this->connect_strategy_;
473 TAO_Connect_Strategy *
474 TAO_Default_Client_Strategy_Factory::create_connect_strategy (
475 TAO_ORB_Core *orb_core)
477 TAO_Connect_Strategy *cs = nullptr;
479 switch (this->connect_strategy_)
481 case TAO_BLOCKED_CONNECT:
483 ACE_NEW_RETURN (cs,
484 TAO_Blocked_Connect_Strategy (orb_core),
485 nullptr);
486 break;
488 case TAO_REACTIVE_CONNECT:
490 ACE_NEW_RETURN (cs,
491 TAO_Reactive_Connect_Strategy (orb_core),
492 nullptr);
493 break;
495 case TAO_LEADER_FOLLOWER_CONNECT :
497 ACE_NEW_RETURN (cs,
498 TAO_LF_Connect_Strategy (orb_core, this->wait_strategy_ == TAO_WAIT_ON_LF_NO_UPCALL),
499 nullptr);
500 break;
504 return cs;
507 Messaging::SyncScope
508 TAO_Default_Client_Strategy_Factory::sync_scope () const
510 return this->sync_scope_;
514 TAO_Default_Client_Strategy_Factory::allow_callback ()
516 return (this->wait_strategy_ != TAO_WAIT_ON_READ);
519 void
520 TAO_Default_Client_Strategy_Factory::report_option_value_error (
521 const ACE_TCHAR* option_name,
522 const ACE_TCHAR* option_value)
524 TAOLIB_DEBUG((LM_DEBUG,
525 ACE_TEXT ("Client_Strategy_Factory - unknown argument")
526 ACE_TEXT (" <%s> for <%s>\n"),
527 option_value, option_name));
530 bool
531 TAO_Default_Client_Strategy_Factory::use_cleanup_options () const
533 return this->use_cleanup_options_;
536 const TAO::Invocation_Retry_Params &
537 TAO_Default_Client_Strategy_Factory::invocation_retry_params () const
539 return this->invocation_retry_params_;
542 // ****************************************************************
544 ACE_STATIC_SVC_DEFINE (TAO_Default_Client_Strategy_Factory,
545 ACE_TEXT ("Client_Strategy_Factory"),
546 ACE_SVC_OBJ_T,
547 &ACE_SVC_NAME (TAO_Default_Client_Strategy_Factory),
548 ACE_Service_Type::DELETE_THIS |
549 ACE_Service_Type::DELETE_OBJ,
551 ACE_FACTORY_DEFINE (TAO, TAO_Default_Client_Strategy_Factory)
553 TAO_END_VERSIONED_NAMESPACE_DECL