4 #include "AppShutdown.h"
5 #include "TestAppExceptionC.h"
6 #include "Foo_C_Custom_ClientEngine.h"
7 #include "Foo_C_ClientEngine.h"
8 #include "Foo_C_Statistics.h"
9 #include "ace/Get_Opt.h"
10 // To force static load the service.
11 #include "tao/PI/PI.h"
12 #include "tao/CSD_ThreadPool/CSD_ThreadPool.h"
14 ServerApp::ServerApp()
15 : TestAppBase("TP_Test_4_Server"),
16 ior_filename_prefix_(ACE_TEXT("foo")),
20 num_remote_clients_(1),
21 num_collocated_clients_(0),
22 collocated_client_kind_(0)
27 ServerApp::run_i(int argc
, ACE_TCHAR
* argv
[])
29 int result
= this->init(argc
, argv
);
37 this->servant_setup();
38 this->collocated_setup();
40 this->run_collocated_clients();
41 this->run_orb_event_loop();
43 // Calling wait on ACE_Thread_Manager singleton to avoid the problem
44 // that the main thread might exit before all CSD Threads exit.
46 // Wait for all CSD task threads exit.
47 ACE_Thread_Manager::instance ()->wait ();
50 return this->check_validity () ? 0 : -1;
55 ServerApp::init(int argc
, ACE_TCHAR
* argv
[])
57 this->orb_
= CORBA::ORB_init(argc
, argv
);
59 // Parse the command-line args for this application.
60 // * Raises -1 if problems are encountered.
61 // * Returns 1 if the usage statement was explicitly requested.
62 // * Returns 0 otherwise.
63 int result
= this->parse_args(argc
, argv
);
69 unsigned num_clients
= this->num_remote_clients_
+
70 this->num_collocated_clients_
;
72 TheAppShutdown
->init(this->orb_
.in(), num_clients
);
79 ServerApp::poa_setup()
81 this->poa_
= this->create_poa(this->orb_
.in(),
87 ServerApp::csd_setup()
89 this->tp_strategy_
= new TAO::CSD::TP_Strategy(this->num_csd_threads_
);
91 if (!this->tp_strategy_
->apply_to(this->poa_
.in()))
94 "Failed to apply CSD strategy to poa.\n"));
95 throw TestAppException();
101 ServerApp::servant_setup()
103 this->servants_
.create_and_activate(this->num_servants_
,
106 this->ior_filename_prefix_
.c_str());
111 ServerApp::collocated_setup()
113 int custom_client_id_start
= this->num_remote_clients_
;
115 unsigned servant_index
= 0;
117 for (unsigned i
= 0; i
< this->num_collocated_clients_
; i
++)
121 // Dole out the servant object references in a round-robin fashion.
122 servant_index
= (servant_index
+ 1) % this->num_servants_
;
125 ServantListType::T_stub_var obj
= this->servants_
.objref(servant_index
);
127 ClientEngine_Handle engine
=
128 new Foo_C_Custom_ClientEngine(this->servants_
.servant(servant_index
),
130 this->tp_strategy_
.in(),
131 ++ custom_client_id_start
);
132 this->collocated_client_task_
.add_engine(engine
.in());
138 ServerApp::poa_activate()
140 PortableServer::POAManager_var poa_manager
141 = this->poa_
->the_POAManager();
143 poa_manager
->activate();
148 ServerApp::run_collocated_clients()
150 if (this->num_collocated_clients_
> 0)
152 if (this->collocated_client_task_
.open() == -1)
154 throw TestAppException ();
161 ServerApp::run_orb_event_loop()
163 OrbRunner
orb_runner(this->orb_
.in(), this->num_orb_threads_
);
165 TheAppShutdown
->wait ();
172 for (unsigned i
= 0; i
< this->num_servants_
; i
++)
174 this->servants_
.servant(i
)->dump();
177 // Wait for all of the collocated client task threads to finish.
178 if (this->num_collocated_clients_
> 0)
180 this->collocated_client_task_
.wait();
186 ServerApp::parse_args(int argc
, ACE_TCHAR
* argv
[])
188 this->exe_name_
= argv
[0];
190 ACE_Get_Opt
get_opts(argc
, argv
, ACE_TEXT("p:s:n:t:r:c:k:"));
194 while ((c
= get_opts()) != -1)
200 this->ior_filename_prefix_
= get_opts
.opt_arg();
204 result
= this->set_arg(this->num_servants_
,
212 result
= this->set_arg(this->num_csd_threads_
,
220 result
= this->set_arg(this->num_orb_threads_
,
228 result
= this->set_arg(this->num_remote_clients_
,
231 "num_remote_clients");
235 result
= this->set_arg(this->num_collocated_clients_
,
238 "num_collocated_clients");
242 result
= this->set_arg(this->collocated_client_kind_
,
245 "collocated_client_kind");
249 this->usage_statement();
253 this->usage_statement();
263 return this->arg_dependency_checks();
267 ServerApp::usage_statement()
270 "Usage: %s [options]\n\n"
272 "\t[-p <ior_filename_prefix>]\n"
273 "\t[-s <num_servants>]\n"
274 "\t[-n <num_csd_threads>]\n"
275 "\t[-t <num_orb_threads>]\n"
276 "\t[-r <num_remote_clients>]\n"
277 "\t[-c <num_collocated_clients>]\n"
278 "\t[-k <collocated_client_kind>]\n"
280 this->exe_name_
.c_str()));
285 ServerApp::arg_dependency_checks()
287 return (this->num_remote_clients_
288 + this->num_collocated_clients_
) > 0 ? 0 : -1;
293 ServerApp::set_arg(unsigned& value
,
294 const ACE_TCHAR
* arg
,
299 int tmp
= ACE_OS::atoi(arg
);
304 "Error: -%c <%s> must be integer type with a value of, "
305 "at least, %d.\n", opt
, name
, min
));
306 this->usage_statement();
316 PortableServer::POA_ptr
317 ServerApp::create_poa(CORBA::ORB_ptr orb
,
318 const char* poa_name
)
321 PortableServer::POA_var root_poa
322 = RefHelper
<PortableServer::POA
>::resolve_initial_ref(orb
,
325 // Get the POAManager from the Root POA.
326 PortableServer::POAManager_var poa_manager
327 = root_poa
->the_POAManager();
329 // Create the child POA Policies.
330 CORBA::PolicyList
policies(0);
333 // Create the child POA
334 PortableServer::POA_var poa
335 = AppHelper::create_poa(poa_name
,
340 // Give away the child POA_ptr from the POA_var variable.
346 ServerApp::check_validity ()
348 Foo_C_Statistics
stats (this->num_remote_clients_
,
349 this->num_collocated_clients_
);
351 Foo_C_ClientEngine::expected_results (stats
);
352 Foo_C_Custom_ClientEngine::expected_results (stats
);
354 for (unsigned i
= 0; i
< this->num_servants_
; i
++)
356 this->servants_
.servant(i
)->gather_stats(stats
);
359 return stats
.actual_vs_expected ();