4 #include "AppShutdown.h"
5 #include "TestAppExceptionC.h"
6 #include "Foo_A_ClientEngine.h"
7 #include "ace/Get_Opt.h"
8 // To force static load the service.
10 #include "tao/CSD_ThreadPool/CSD_ThreadPool.h"
12 ServerApp::ServerApp()
13 : TestAppBase("TP_Test_2_Server"),
14 ior_filename_prefix_(ACE_TEXT("foo")),
18 num_remote_clients_(1),
19 num_collocated_clients_(0),
20 collocated_client_kind_(0)
26 ServerApp::run_i(int argc
, ACE_TCHAR
* argv
[])
28 int result
= this->init(argc
, argv
);
36 this->servant_setup();
37 this->collocated_setup();
39 this->run_collocated_clients();
40 this->run_orb_event_loop();
42 // Calling wait on ACE_Thread_Manager singleton to avoid the problem
43 // that the main thread might exit before all CSD Threads exit.
45 // Wait for all CSD task threads exit.
46 ACE_Thread_Manager::instance ()->wait ();
49 return this->check_validity () ? 0 : -1;
54 ServerApp::init(int argc
, ACE_TCHAR
* argv
[])
56 this->orb_
= CORBA::ORB_init(argc
, argv
);
58 // Parse the command-line args for this application.
59 // * Raises -1 if problems are encountered.
60 // * Returns 1 if the usage statement was explicitly requested.
61 // * Returns 0 otherwise.
62 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 client_id_start
= this->num_remote_clients_
;
114 for (unsigned i
= 0; i
< this->num_collocated_clients_
; i
++)
116 // Dole out the servant object references in a round-robin fashion.
117 unsigned servant_index
= i
% this->num_servants_
;
119 ServantListType::T_stub_var obj
= this->servants_
.objref(servant_index
);
120 ClientEngine_Handle engine
= new Foo_A_ClientEngine(obj
.in(), ++client_id_start
);
121 this->collocated_client_task_
.add_engine(engine
.in());
127 ServerApp::poa_activate()
129 PortableServer::POAManager_var poa_manager
130 = this->poa_
->the_POAManager();
132 poa_manager
->activate();
137 ServerApp::run_collocated_clients()
139 if (this->num_collocated_clients_
> 0)
141 if (this->collocated_client_task_
.open() == -1)
143 throw TestAppException ();
150 ServerApp::run_orb_event_loop()
152 OrbRunner
orb_runner(this->orb_
.in(), this->num_orb_threads_
);
154 TheAppShutdown
->wait ();
165 ServerApp::parse_args(int argc
, ACE_TCHAR
* argv
[])
167 this->exe_name_
= argv
[0];
169 ACE_Get_Opt
get_opts(argc
, argv
, ACE_TEXT("p:s:n:t:r:c:k:"));
173 while ((c
= get_opts()) != -1)
179 this->ior_filename_prefix_
= get_opts
.opt_arg();
183 result
= this->set_arg(this->num_servants_
,
191 result
= this->set_arg(this->num_csd_threads_
,
199 result
= this->set_arg(this->num_orb_threads_
,
207 result
= this->set_arg(this->num_remote_clients_
,
210 "num_remote_clients");
214 result
= this->set_arg(this->num_collocated_clients_
,
217 "num_collocated_clients");
221 result
= this->set_arg(this->collocated_client_kind_
,
224 "collocated_client_kind");
228 this->usage_statement();
232 this->usage_statement();
242 return this->arg_dependency_checks();
246 ServerApp::usage_statement()
249 "Usage: %s [options]\n\n"
251 "\t[-p <ior_filename_prefix>]\n"
252 "\t[-s <num_servants>]\n"
253 "\t[-n <num_csd_threads>]\n"
254 "\t[-t <num_orb_threads>]\n"
255 "\t[-r <num_remote_clients>]\n"
256 "\t[-c <num_collocated_clients>]\n"
257 "\t[-k <collocated_client_kind>]\n"
259 this->exe_name_
.c_str()));
264 ServerApp::arg_dependency_checks()
266 return (this->num_remote_clients_
267 + this->num_collocated_clients_
) > 0 ? 0 : -1;
272 ServerApp::set_arg(unsigned& value
,
273 const ACE_TCHAR
* arg
,
278 int tmp
= ACE_OS::atoi(arg
);
283 "Error: -%c <%s> must be integer type with a value of, "
284 "at least, %d.\n", opt
, name
, min
));
285 this->usage_statement();
294 PortableServer::POA_ptr
295 ServerApp::create_poa(CORBA::ORB_ptr orb
,
296 const char* poa_name
)
299 PortableServer::POA_var root_poa
300 = RefHelper
<PortableServer::POA
>::resolve_initial_ref(orb
,
303 // Get the POAManager from the Root POA.
304 PortableServer::POAManager_var poa_manager
305 = root_poa
->the_POAManager();
307 // Create the child POA Policies.
308 CORBA::PolicyList
policies(0);
311 // Create the child POA
312 PortableServer::POA_var poa
= AppHelper::create_poa(poa_name
,
317 // Give away the child POA_ptr from the POA_var variable.
323 ServerApp::check_validity ()
325 // Check whether the clients return any errors.
326 if (this->num_collocated_clients_
> 0
327 && this->collocated_client_task_
.failure_count () > 0)
332 unsigned num_clients
= this->num_remote_clients_
+
333 this->num_collocated_clients_
;
335 Foo_A_Statistics
stats (num_clients
);
337 Foo_A_ClientEngine::expected_results (stats
);
339 for (unsigned i
= 0; i
< this->num_servants_
; i
++)
341 this->servants_
.servant(i
)->gather_stats(stats
);
344 return stats
.actual_vs_expected ();