2 //=============================================================================
6 * This is a client implementation.
8 * @author Irfan Pyarali
10 //=============================================================================
13 #include "ace/Get_Opt.h"
15 #include "tao/ORB_Core.h"
16 #include "tao/RTCORBA/RTCORBA.h"
17 #include "tao/Policy_ManagerC.h"
18 #include "tao/Strategies/advanced_resource.h"
19 #include "../check_supported_priorities.cpp"
20 #include "../common_args.cpp"
23 static int iterations
= 1;
25 static int shutdown_server
= 0;
26 static const ACE_TCHAR
*ior
= ACE_TEXT ("file://ior");
27 static const ACE_TCHAR
*invocation_priorities_file
= ACE_TEXT ("empty_file");
28 static const ACE_TCHAR
*protocols_file
= ACE_TEXT ("empty_file");
29 static const ACE_TCHAR
*bands_file
= ACE_TEXT ("empty_file");
32 parse_args (int argc
, ACE_TCHAR
**argv
)
34 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("b:d:i:k:p:t:x"));
37 while ((c
= get_opts ()) != -1)
41 bands_file
= get_opts
.opt_arg ();
45 debug
= ACE_OS::atoi (get_opts
.opt_arg ());
49 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
53 ior
= get_opts
.opt_arg ();
57 protocols_file
= get_opts
.opt_arg ();
61 invocation_priorities_file
= get_opts
.opt_arg ();
70 ACE_ERROR_RETURN ((LM_ERROR
,
72 "\t-b <bands file> (defaults to %s)\n"
73 "\t-i <iterations> (defaults to %d)\n"
74 "\t-k <ior> (defaults to %s)\n"
75 "\t-p <protocol file> (defaults to %s)\n"
76 "\t-t <invocation priorities file> (defaults to %s)\n"
77 "\t-x <shutdown server> (defaults to %d)\n"
84 invocation_priorities_file
,
95 Client (test_ptr test
,
97 RTCORBA::Current_ptr current
,
98 RTCORBA::RTORB_ptr rt_orb
,
99 CORBA::PolicyManager_ptr policy_manager
);
101 void vanilla_invocations ();
103 void priority_invocations (int debug
);
105 void set_client_protocols_policies (int debug
);
107 void set_priority_bands (int debug
);
109 void set_private_connection_policies ();
111 void reset_policies ();
117 RTCORBA::Current_var current_
;
118 RTCORBA::RTORB_var rt_orb_
;
119 CORBA::PolicyManager_var policy_manager_
;
122 class Worker_Thread
: public ACE_Task_Base
125 Worker_Thread (ACE_Thread_Manager
&thread_manager
,
128 RTCORBA::Current_ptr current
,
129 CORBA::Short priority
);
133 void validate_connection ();
138 RTCORBA::Current_var current_
;
139 CORBA::Short priority_
;
142 Worker_Thread::Worker_Thread (ACE_Thread_Manager
&thread_manager
,
145 RTCORBA::Current_ptr current
,
146 CORBA::Short priority
)
147 : ACE_Task_Base (&thread_manager
),
149 test_ (test::_duplicate (test
)),
150 current_ (RTCORBA::Current::_duplicate (current
)),
156 Worker_Thread::validate_connection ()
158 // Try to validate the connection several times, ignoring transient
159 // exceptions. If the connection can still not be setup, return
161 CORBA::PolicyList_var inconsistent_policies
;
162 int max_attempts
= 10;
163 int current_attempt
= 0;
169 this->test_
->_validate_connection (inconsistent_policies
.out ());
171 // If successful, we are done.
174 catch (const CORBA::TRANSIENT
& )
176 // If we have reach our maximum number of tries, throw exception.
177 if (current_attempt
== max_attempts
)
179 // Otherwise, ignore...
181 catch (const CORBA::Exception
&)
183 // Rethrow any other exceptions.
190 Worker_Thread::svc ()
194 this->current_
->the_priority (this->priority_
);
196 this->validate_connection ();
198 this->client_
.vanilla_invocations ();
200 catch (const CORBA::Exception
& ex
)
202 ex
._tao_print_exception ("Worker Thread exception:");
207 Client::Client (test_ptr test
,
209 RTCORBA::Current_ptr current
,
210 RTCORBA::RTORB_ptr rt_orb
,
211 CORBA::PolicyManager_ptr policy_manager
)
212 : test_ (test::_duplicate (test
)),
213 orb_ (CORBA::ORB::_duplicate (orb
)),
214 current_ (RTCORBA::Current::_duplicate (current
)),
215 rt_orb_ (RTCORBA::RTORB::_duplicate (rt_orb
)),
216 policy_manager_ (CORBA::PolicyManager::_duplicate (policy_manager
))
221 Client::vanilla_invocations ()
223 for (int i
= 0; i
< iterations
; i
++)
225 this->test_
->method ();
230 Client::priority_invocations (int debug
)
232 ULong_Array priorities
;
234 get_values ("client",
235 invocation_priorities_file
,
236 "invocation priorities",
241 ACE_ERROR ((LM_ERROR
,
242 "Error in parsing invocation priorities data file: %s\n",
243 invocation_priorities_file
));
249 Worker_Thread
**workers
= 0;
251 ACE_NEW_THROW_EX (workers
,
252 Worker_Thread
*[priorities
.size ()],
253 CORBA::NO_MEMORY ());
255 ACE_Thread_Manager thread_manager
;
258 i
< priorities
.size ();
261 ACE_NEW_THROW_EX (workers
[i
],
262 Worker_Thread (thread_manager
,
265 this->current_
.in (),
267 CORBA::NO_MEMORY ());
272 this->orb_
->orb_core ()->orb_params ()->thread_creation_flags ();
275 workers
[i
]->activate (flags
);
278 ACE_ERROR ((LM_ERROR
,
279 "Cannot activate thread\n"));
284 thread_manager
.wait ();
287 i
< priorities
.size ();
296 Client::set_client_protocols_policies (int debug
)
298 CORBA::PolicyList policies
;
301 get_protocols ("client",
308 ACE_ERROR ((LM_ERROR
,
309 "Error in parsing protocols data file: %s\n",
314 this->policy_manager_
->set_policy_overrides (policies
,
315 CORBA::ADD_OVERRIDE
);
319 Client::set_priority_bands (int debug
)
321 CORBA::PolicyList policies
;
324 get_priority_bands ("client",
331 ACE_ERROR ((LM_ERROR
,
332 "Error in parsing bands data file: %s\n",
337 this->policy_manager_
->set_policy_overrides (policies
,
338 CORBA::ADD_OVERRIDE
);
342 Client::set_private_connection_policies ()
344 CORBA::PolicyList policies
;
348 this->rt_orb_
->create_private_connection_policy ();
350 this->policy_manager_
->set_policy_overrides (policies
,
351 CORBA::ADD_OVERRIDE
);
355 Client::reset_policies ()
357 CORBA::PolicyList empty_policies
;
359 this->policy_manager_
->set_policy_overrides (empty_policies
,
360 CORBA::SET_OVERRIDE
);
363 class Task
: public ACE_Task_Base
366 Task (ACE_Thread_Manager
&thread_manager
,
374 Task::Task (ACE_Thread_Manager
&thread_manager
,
376 : ACE_Task_Base (&thread_manager
),
377 orb_ (CORBA::ORB::_duplicate (orb
))
386 CORBA::Object_var object
=
387 this->orb_
->resolve_initial_references ("RTORB");
389 RTCORBA::RTORB_var rt_orb
=
390 RTCORBA::RTORB::_narrow (object
.in ());
393 this->orb_
->resolve_initial_references ("ORBPolicyManager");
395 CORBA::PolicyManager_var policy_manager
=
396 CORBA::PolicyManager::_narrow (object
.in ());
399 this->orb_
->resolve_initial_references ("RTCurrent");
401 RTCORBA::Current_var current
=
402 RTCORBA::Current::_narrow (object
.in ());
404 current
->the_priority (0);
407 this->orb_
->string_to_object (ior
);
410 test::_narrow (object
.in ());
412 Client
client (test
.in (),
416 policy_manager
.in ());
418 client
.vanilla_invocations ();
420 client
.set_private_connection_policies ();
422 client
.vanilla_invocations ();
424 client
.reset_policies ();
426 client
.set_client_protocols_policies (debug
);
428 client
.vanilla_invocations ();
430 client
.set_private_connection_policies ();
432 client
.vanilla_invocations ();
434 client
.reset_policies ();
436 client
.set_priority_bands (debug
);
438 client
.priority_invocations (debug
);
440 client
.set_private_connection_policies ();
442 client
.priority_invocations (debug
);
444 client
.reset_policies ();
446 client
.set_priority_bands (debug
);
448 client
.set_client_protocols_policies (0);
450 client
.priority_invocations (0);
452 client
.set_private_connection_policies ();
454 client
.priority_invocations (debug
);
456 client
.reset_policies ();
463 catch (const CORBA::Exception
& ex
)
465 ex
._tao_print_exception ("Error!");
473 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
478 CORBA::ORB_init (argc
, argv
);
480 int parse_args_result
=
481 parse_args (argc
, argv
);
482 if (parse_args_result
!= 0)
483 return parse_args_result
;
485 // Make sure we can support multiple priorities that are required
487 if (!check_supported_priorities (orb
.in ()))
490 // Thread Manager for managing task.
491 ACE_Thread_Manager thread_manager
;
494 Task
task (thread_manager
,
497 // Task activation flags.
501 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
505 task
.activate (flags
);
510 ACE_ERROR_RETURN ((LM_ERROR
,
511 "Cannot create thread with scheduling policy %C\n"
512 "because the user does not have the appropriate privileges, terminating program....\n"
513 "Check svc.conf options and/or run as root\n",
514 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
522 // Wait for task to exit.
524 thread_manager
.wait ();
525 ACE_ASSERT (result
!= -1);
527 catch (const CORBA::Exception
& ex
)
529 ex
._tao_print_exception ("Error!");