2 #include "TestInf/AppHelper.h"
3 #include "TestInf/OrbRunner.h"
4 #include "TestInf/AppShutdown.h"
5 #include "TestInf/TestAppExceptionC.h"
6 #include "TestServant/Foo_ClientEngine.h"
7 #include "ace/Get_Opt.h"
8 #include "ace/Time_Value.h"
9 #include "ace/High_Res_Timer.h"
10 // To force static load the service.
11 #include "tao/PI/PI.h"
12 #include "tao/CSD_ThreadPool/CSD_ThreadPool.h"
15 ServerApp::ServerApp()
16 : TestAppBase("CSD_PT_ServerApp"),
17 ior_filename_prefix_(ACE_TEXT("foo")),
21 num_remote_clients_(1),
22 num_collocated_clients_(0),
25 scenario_id_("UnknownScenarioId"),
31 ServerApp::~ServerApp()
37 ServerApp::run_i(int argc
, ACE_TCHAR
* argv
[])
39 int result
= this->init(argc
, argv
);
47 this->servant_setup();
48 this->collocated_setup();
51 ACE_High_Res_Timer timer
;
54 this->run_collocated_clients();
55 this->run_orb_event_loop();
61 timer
.elapsed_time(tv
);
63 // Calling wait on ACE_Thread_Manager singleton to avoid the problem
64 // that the main thread might exit before all CSD Threads exit.
66 // Wait for all CSD task threads exit.
67 ACE_Thread_Manager::instance ()->wait ();
69 unsigned num_operations
= this->stats_
.total();
71 double ops_per_msec
= (1.0 * num_operations
) / tv
.msec();
73 ACE_DEBUG((LM_DEBUG
, "%s,%d,%d,%d,%.2f\n",
74 this->scenario_id_
.c_str(),
81 return this->check_results () ? 0 : -1;
86 ServerApp::init(int argc
, ACE_TCHAR
* argv
[])
88 this->orb_
= CORBA::ORB_init(argc
, argv
);
90 // Parse the command-line args for this application.
91 // * Raises -1 if problems are encountered.
92 // * Returns 1 if the usage statement was explicitly requested.
93 // * Returns 0 otherwise.
94 int result
= this->parse_args(argc
, argv
);
101 TheAppShutdown
->init(this->orb_
.in(),
102 this->num_remote_clients_
+
103 this->num_collocated_clients_
);
110 ServerApp::poa_setup()
112 this->poa_
= this->create_poa(this->orb_
.in(),
118 ServerApp::csd_setup()
120 this->tp_strategy_
= new TAO::CSD::TP_Strategy(this->num_csd_threads_
);
122 if (this->use_csd_
> 0)
124 if (!this->tp_strategy_
->apply_to(this->poa_
.in()))
127 "Failed to apply CSD strategy to poa.\n"));
128 throw TestAppException();
135 ServerApp::servant_setup()
137 this->servants_
.create_and_activate(this->num_servants_
,
140 this->ior_filename_prefix_
.c_str());
145 ServerApp::collocated_setup()
147 int client_id
= this->num_remote_clients_
;
149 for (unsigned i
= 0; i
< this->num_collocated_clients_
; i
++)
153 // Dole out the servant object references in a round-robin fashion.
154 unsigned servant_index
= i
% this->num_servants_
;
156 ServantListType::T_stub_var obj
= this->servants_
.objref(servant_index
);
158 ClientEngine_Handle engine
= new Foo_ClientEngine(obj
.in(), client_id
);
160 this->collocated_client_task_
.add_engine(engine
.in());
163 this->collocated_client_task_
.num_loops(this->num_loops_
);
168 ServerApp::poa_activate()
170 PortableServer::POAManager_var poa_manager
171 = this->poa_
->the_POAManager();
173 poa_manager
->activate();
178 ServerApp::run_collocated_clients()
180 if (this->num_collocated_clients_
> 0)
182 if (this->collocated_client_task_
.open() == -1)
184 throw TestAppException ();
191 ServerApp::run_orb_event_loop()
193 OrbRunner
orb_runner(this->orb_
.in(), this->num_orb_threads_
);
195 TheAppShutdown
->wait ();
206 ServerApp::parse_args(int argc
, ACE_TCHAR
* argv
[])
208 this->exe_name_
= argv
[0];
210 ACE_Get_Opt
get_opts(argc
, argv
, ACE_TEXT("p:s:n:t:r:c:l:u:x:z:"));
214 while ((c
= get_opts()) != -1)
220 this->ior_filename_prefix_
= get_opts
.opt_arg();
224 result
= this->set_arg(this->num_servants_
,
232 result
= this->set_arg(this->num_csd_threads_
,
240 result
= this->set_arg(this->num_orb_threads_
,
248 result
= this->set_arg(this->num_remote_clients_
,
251 "num_remote_clients");
255 result
= this->set_arg(this->num_collocated_clients_
,
258 "num_collocated_clients");
262 result
= this->set_arg(this->num_loops_
,
270 result
= this->set_arg(this->use_csd_
,
277 this->scenario_id_
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg());
281 result
= this->set_arg(this->trial_id_
,
289 this->usage_statement();
293 this->usage_statement();
303 return this->arg_dependency_checks();
307 ServerApp::usage_statement()
310 "Usage: %s [options]\n\n"
312 "\t[-p <ior_filename_prefix>]\n"
313 "\t[-s <num_servants>]\n"
314 "\t[-n <num_csd_threads>]\n"
315 "\t[-t <num_orb_threads>]\n"
316 "\t[-r <num_remote_clients>]\n"
317 "\t[-c <num_collocated_clients>]\n"
318 "\t[-l <num_loops>]\n"
319 "\t[-u <use_csd_flag>]\n"
320 "\t[-x <scenario_id_string>]\n"
321 "\t[-z <trial_id_number>]\n"
323 this->exe_name_
.c_str()));
328 ServerApp::arg_dependency_checks()
330 return (this->num_remote_clients_
331 + this->num_collocated_clients_
) > 0 ? 0 : -1;
336 ServerApp::set_arg(unsigned& value
,
337 const ACE_TCHAR
* arg
,
342 int tmp
= ACE_OS::atoi(arg
);
347 "Error: -%c <%s> must be integer type with a value of, "
348 "at least, %d.\n", opt
, name
, min
));
349 this->usage_statement();
358 PortableServer::POA_ptr
359 ServerApp::create_poa(CORBA::ORB_ptr orb
,
360 const char* poa_name
)
363 PortableServer::POA_var root_poa
364 = RefHelper
<PortableServer::POA
>::resolve_initial_ref(orb
,
367 // Get the POAManager from the Root POA.
368 PortableServer::POAManager_var poa_manager
369 = root_poa
->the_POAManager();
371 // Create the child POA Policies.
372 CORBA::PolicyList
policies(0);
375 // Create the child POA
376 PortableServer::POA_var poa
= AppHelper::create_poa(poa_name
,
381 // Give away the child POA_ptr from the POA_var variable.
387 ServerApp::check_results()
389 this->stats_
.init(this->num_remote_clients_
+
390 this->num_collocated_clients_
,
393 Foo_ClientEngine::expected_results(this->stats_
);
395 for (unsigned i
= 0; i
< this->num_servants_
; i
++)
397 this->servants_
.servant(i
)->gather_stats(this->stats_
);
400 this->stats_
.actual_vs_expected();