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
;
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
;
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
;
55 // @todo: will be changed when other strategies are implemented.
56 this->connect_strategy_
= TAO_LEADER_FOLLOWER_CONNECT
;
60 TAO_Default_Client_Strategy_Factory::~TAO_Default_Client_Strategy_Factory ()
65 TAO_Default_Client_Strategy_Factory::init (int argc
, ACE_TCHAR
* argv
[])
67 return this->parse_args (argc
, argv
);
71 TAO_Default_Client_Strategy_Factory::parse_args (int argc
, ACE_TCHAR
* argv
[])
73 ACE_TRACE ("TAO_Default_Client_Strategy_Factory::parse_args");
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)
88 ACE_TCHAR
* name
= argv
[curarg
];
90 if (ACE_OS::strcasecmp (name
,
92 this->wait_strategy_
= TAO_WAIT_ON_LEADER_FOLLOWER
;
93 else if (ACE_OS::strcasecmp (name
,
95 this->wait_strategy_
= TAO_WAIT_ON_REACTOR
;
96 else if (ACE_OS::strcasecmp (name
,
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
;
103 this->report_option_value_error (
104 ACE_TEXT("-ORBClientConnectionHandler"), name
);
107 else if (ACE_OS::strcasecmp (argv
[curarg
],
108 ACE_TEXT("-ORBTransportMuxStrategy"))
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
;
123 this->report_option_value_error (
124 ACE_TEXT("-ORBTransportMuxStrategy"), name
);
127 else if (ACE_OS::strcasecmp (argv
[curarg
],
128 ACE_TEXT("-ORBTransportMuxStrategyLock"))
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
;
143 this->report_option_value_error (
144 ACE_TEXT("-ORBTransportMuxStrategyLock"), name
);
147 else if (ACE_OS::strcasecmp (argv
[curarg
],
148 ACE_TEXT("-ORBConnectStrategy")) == 0)
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
;
165 this->report_option_value_error (
166 ACE_TEXT("-ORBConnectStrategy"),
170 else if (ACE_OS::strcasecmp (argv
[curarg
],
171 ACE_TEXT ("-ORBDefaultSyncScope")) == 0)
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
;
200 this->report_option_value_error (ACE_TEXT("-ORBDefaultSyncScope"),
207 else if (ACE_OS::strcasecmp (argv
[curarg
],
208 ACE_TEXT("-ORBReplyDispatcherTableSize"))
214 this->rd_table_size_
= ACE_OS::atoi (argv
[curarg
]);
217 else if (ACE_OS::strcmp (argv
[curarg
],
218 ACE_TEXT("-ORBConnectionHandlerCleanup")) == 0)
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;
232 this->report_option_value_error (
233 ACE_TEXT("-ORBConnectionHandlerCleanup"), name
);
236 else if (ACE_OS::strcmp (argv
[curarg
],
237 ACE_TEXT("-ORBForwardOnCommFailureLimit"))
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"),
254 this->invocation_retry_params_
255 .forward_on_exception_limit_
[TAO::FOE_COMM_FAILURE
] =
259 else if (ACE_OS::strcmp (argv
[curarg
],
260 ACE_TEXT("-ORBForwardOnTransientLimit")) == 0)
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"),
276 this->invocation_retry_params_
277 .forward_on_exception_limit_
[TAO::FOE_TRANSIENT
] =
281 else if (ACE_OS::strcmp (argv
[curarg
],
282 ACE_TEXT("-ORBForwardOnObjectNotExistLimit"))
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"),
299 this->invocation_retry_params_
300 .forward_on_exception_limit_
[TAO::FOE_OBJECT_NOT_EXIST
] =
304 else if (ACE_OS::strcmp (argv
[curarg
],
305 ACE_TEXT("-ORBForwardOnInvObjrefLimit")) == 0)
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
);
320 this->invocation_retry_params_
321 .forward_on_exception_limit_
[TAO::FOE_INV_OBJREF
] =
325 else if (ACE_OS::strcmp (argv
[curarg
],
326 ACE_TEXT("-ORBForwardOnReplyClosedLimit"))
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
);
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?
350 TAOLIB_ERROR ((LM_ERROR
,
351 "Client_Strategy_Factory - "
352 "unknown option <%s>\n",
357 TAOLIB_DEBUG ((LM_DEBUG
,
358 "Client_Strategy_Factory - "
359 "ignoring option <%s>\n",
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_
)
378 TAO_Muxed_TMS (transport
),
382 case TAO_EXCLUSIVE_TMS
:
385 TAO_Exclusive_TMS (transport
),
395 TAO_Default_Client_Strategy_Factory::create_transport_mux_strategy_lock ()
397 ACE_Lock
*the_lock
= nullptr;
399 switch (this->muxed_strategy_lock_type_
)
403 ACE_NEW_RETURN (the_lock
,
404 ACE_Lock_Adapter
<ACE_SYNCH_NULL_MUTEX
> (),
408 case TAO_THREAD_LOCK
:
410 ACE_NEW_RETURN (the_lock
,
411 ACE_Lock_Adapter
<TAO_SYNCH_RECURSIVE_MUTEX
> (),
421 TAO_Default_Client_Strategy_Factory::reply_dispatcher_table_size () const
423 return this->rd_table_size_
;
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
:
437 TAO_Wait_On_Leader_Follower (transport
),
441 case TAO_WAIT_ON_REACTOR
:
444 TAO_Wait_On_Reactor (transport
),
448 case TAO_WAIT_ON_READ
:
451 TAO_Wait_On_Read (transport
),
455 case TAO_WAIT_ON_LF_NO_UPCALL
:
458 TAO::Wait_On_LF_No_Upcall (transport
),
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
:
484 TAO_Blocked_Connect_Strategy (orb_core
),
488 case TAO_REACTIVE_CONNECT
:
491 TAO_Reactive_Connect_Strategy (orb_core
),
495 case TAO_LEADER_FOLLOWER_CONNECT
:
498 TAO_LF_Connect_Strategy (orb_core
, this->wait_strategy_
== TAO_WAIT_ON_LF_NO_UPCALL
),
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
);
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
));
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"),
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