1 #include "ace/Get_Opt.h"
4 #include "tao/RTCORBA/RTCORBA.h"
5 #include "tao/ORB_Core.h"
6 #include "tao/Policy_ManagerC.h"
7 #include "../check_supported_priorities.cpp"
8 #include "../common_args.cpp"
10 static int iterations
= 5;
11 static int shutdown_server
= 0;
14 static const ACE_TCHAR
*ior
= ACE_TEXT ("file://ior");
16 static const ACE_TCHAR
*invocation_priorities_file
= ACE_TEXT ("invocation_priorities");
17 static const ACE_TCHAR
*bands_file
= ACE_TEXT ("empty_file");
20 parse_args (int argc
, ACE_TCHAR
**argv
)
22 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("b:d:p:k:i:x"));
25 while ((c
= get_opts ()) != -1)
29 ior
= get_opts
.opt_arg ();
33 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
37 debug
= ACE_OS::atoi (get_opts
.opt_arg ());
45 invocation_priorities_file
= get_opts
.opt_arg ();
49 bands_file
= get_opts
.opt_arg ();
54 ACE_ERROR_RETURN ((LM_ERROR
,
58 "-p <invocation_priorities_file> "
70 class Worker_Thread
: public ACE_Task_Base
73 Worker_Thread (ACE_Thread_Manager
&thread_manager
,
75 RTCORBA::Current_ptr current
,
76 CORBA::Short priority
);
80 void validate_connection ();
84 RTCORBA::Current_var current_
;
85 CORBA::Short priority_
;
88 Worker_Thread::Worker_Thread (ACE_Thread_Manager
&thread_manager
,
90 RTCORBA::Current_ptr current
,
91 CORBA::Short priority
)
92 : ACE_Task_Base (&thread_manager
),
93 test_ (test::_duplicate (test
)),
94 current_ (RTCORBA::Current::_duplicate (current
)),
100 Worker_Thread::validate_connection ()
102 // Try to validate the connection several times, ignoring transient
103 // exceptions. If the connection can still not be setup, return
105 CORBA::PolicyList_var inconsistent_policies
;
106 int max_attempts
= 10;
107 int current_attempt
= 0;
113 this->test_
->_validate_connection (inconsistent_policies
.out ());
115 // If successful, we are done.
118 catch (const CORBA::TRANSIENT
& )
120 // If we have reach our maximum number of tries, throw exception.
121 if (current_attempt
== max_attempts
)
123 // Otherwise, ignore...
125 catch (const CORBA::Exception
&)
127 // Rethrow any other exceptions.
134 Worker_Thread::svc ()
138 this->current_
->the_priority (this->priority_
);
140 this->validate_connection ();
142 for (int i
= 0; i
< iterations
; i
++)
144 this->test_
->method ();
147 catch (const CORBA::Exception
& ex
)
149 ex
._tao_print_exception ("Worker Thread exception:");
154 class Task
: public ACE_Task_Base
157 Task (ACE_Thread_Manager
&thread_manager
,
165 Task::Task (ACE_Thread_Manager
&thread_manager
,
167 : ACE_Task_Base (&thread_manager
),
168 orb_ (CORBA::ORB::_duplicate (orb
))
177 CORBA::Object_var object
=
178 this->orb_
->resolve_initial_references ("RTORB");
180 RTCORBA::RTORB_var rt_orb
=
181 RTCORBA::RTORB::_narrow (object
.in ());
184 this->orb_
->resolve_initial_references ("RTCurrent");
186 RTCORBA::Current_var current
=
187 RTCORBA::Current::_narrow (object
.in ());
189 current
->the_priority (0);
192 this->orb_
->resolve_initial_references ("ORBPolicyManager");
194 CORBA::PolicyManager_var policy_manager
=
195 CORBA::PolicyManager::_narrow (object
.in ());
198 this->orb_
->string_to_object (ior
);
201 test::_narrow (object
.in ());
203 ULong_Array priorities
;
205 get_values ("client",
206 invocation_priorities_file
,
207 "invocation priorities",
213 CORBA::PolicyList policies
;
216 get_priority_bands ("client",
224 policy_manager
->set_policy_overrides (policies
,
225 CORBA::SET_OVERRIDE
);
229 // Thread Manager for managing workers.
230 ACE_Thread_Manager thread_manager
;
233 Worker_Thread
**workers
= 0;
235 ACE_NEW_RETURN (workers
,
236 Worker_Thread
*[priorities
.size ()],
240 i
< priorities
.size ();
243 ACE_NEW_RETURN (workers
[i
],
244 Worker_Thread (thread_manager
,
253 this->orb_
->orb_core ()->orb_params ()->thread_creation_flags ();
256 workers
[i
]->activate (flags
);
261 thread_manager
.wait ();
264 i
< priorities
.size ();
276 catch (const CORBA::Exception
& ex
)
278 ex
._tao_print_exception ("Unexpected exception!");
286 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
291 CORBA::ORB_init (argc
, argv
);
294 parse_args (argc
, argv
);
298 // Make sure we can support multiple priorities that are required
300 if (!check_supported_priorities (orb
.in ()))
303 // Thread Manager for managing task.
304 ACE_Thread_Manager thread_manager
;
307 Task
task (thread_manager
,
310 // Task activation flags.
314 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
318 task
.activate (flags
);
323 ACE_ERROR_RETURN ((LM_ERROR
,
324 "Cannot create thread with scheduling policy %C\n"
325 "because the user does not have the appropriate privileges, terminating program....\n"
326 "Check svc.conf options and/or run as root\n",
327 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
335 // Wait for task to exit.
337 thread_manager
.wait ();
338 ACE_ASSERT (result
!= -1);
340 catch (const CORBA::Exception
& ex
)
342 ex
._tao_print_exception ("Unexpected exception!");