4 #include "AppShutdown.h"
5 #include "TestAppExceptionC.h"
6 #include "Foo_B_SimpleClientEngine.h"
7 #include "Callback_i.h"
8 #include "ace/Get_Opt.h"
9 // To force static load the service.
10 #include "tao/PI/PI.h"
11 #include "tao/CSD_ThreadPool/CSD_ThreadPool.h"
14 ServerApp::ServerApp()
15 : TestAppBase("TP_Test_3_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(),
84 if (this->num_collocated_clients_
> 0)
86 this->cb_poa_
= this->create_poa(this->orb_
.in(),
92 ServerApp::csd_setup()
94 this->tp_strategy_
= new TAO::CSD::TP_Strategy(this->num_csd_threads_
);
96 // We don't apply the strategy for this test to show that the bug isn't
97 // part of the CSD ThreadPool Strategy code.
99 if (!this->tp_strategy_
->apply_to(this->poa_
.in()))
102 "Failed to apply CSD strategy to poa.\n"));
103 throw TestAppException();
107 // Use another poa and strategy for callbacks. This would resolve
108 // the deadlock situation that happens when having number of csd
109 // threads less than number of collocated clients.
110 if (this->num_collocated_clients_
> 0)
112 this->cb_tp_strategy_
= new TAO::CSD::TP_Strategy();
113 // We don't apply the strategy for this test to show that the bug isn't
114 // part of the CSD ThreadPool Strategy code.
116 if (!this->cb_tp_strategy_
->apply_to(this->cb_poa_
.in()))
119 "Failed to apply CSD strategy to callback poa.\n"));
120 throw TestAppException();
128 ServerApp::servant_setup()
130 this->foo_servants_
.create_and_activate(this->num_servants_
,
133 this->ior_filename_prefix_
.c_str());
138 ServerApp::collocated_setup()
140 if (this->num_collocated_clients_
== 0)
143 this->cb_servants_
.create_and_activate(1, // number of callback servants
146 CallbackServantListType::T_stub_var cb
= this->cb_servants_
.objref(0);
148 unsigned client_id
= this->num_remote_clients_
;
150 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 FooServantListType::T_stub_var foo
157 = this->foo_servants_
.objref(servant_index
);
158 ClientEngine_Handle engine
159 = new Foo_B_SimpleClientEngine(foo
.in(), cb
.in (), client_id
);
160 this->collocated_client_task_
.add_engine(engine
.in());
166 ServerApp::poa_activate()
168 PortableServer::POAManager_var poa_manager
169 = this->poa_
->the_POAManager();
170 poa_manager
->activate();
175 ServerApp::run_collocated_clients()
177 if (this->num_collocated_clients_
> 0)
179 if (this->collocated_client_task_
.open() == -1)
181 throw TestAppException ();
188 ServerApp::run_orb_event_loop()
190 OrbRunner
orb_runner(this->orb_
.in(), this->num_orb_threads_
);
192 TheAppShutdown
->wait ();
203 ServerApp::parse_args(int argc
, ACE_TCHAR
* argv
[])
205 this->exe_name_
= argv
[0];
207 ACE_Get_Opt
get_opts(argc
, argv
, ACE_TEXT("p:s:n:t:r:c:k:"));
211 while ((c
= get_opts()) != -1)
217 this->ior_filename_prefix_
= get_opts
.opt_arg();
221 result
= set_arg(this->num_servants_
,
229 result
= set_arg(this->num_csd_threads_
,
237 result
= set_arg(this->num_orb_threads_
,
245 result
= set_arg(this->num_remote_clients_
,
248 "num_remote_clients");
252 result
= set_arg(this->num_collocated_clients_
,
255 "num_collocated_clients");
259 result
= set_arg(this->collocated_client_kind_
,
262 "collocated_client_kind");
266 this->usage_statement();
270 this->usage_statement();
280 return this->arg_dependency_checks();
284 ServerApp::usage_statement()
287 "Usage: %s [options]\n\n"
289 "\t[-p <ior_filename_prefix>]\n"
290 "\t[-s <num_servants>]\n"
291 "\t[-n <num_csd_threads>]\n"
292 "\t[-t <num_orb_threads>]\n"
293 "\t[-r <num_remote_clients>]\n"
294 "\t[-c <num_collocated_clients>]\n"
295 "\t[-k <collocated_client_kind>]\n"
297 this->exe_name_
.c_str()));
302 ServerApp::arg_dependency_checks()
304 return (this->num_remote_clients_
305 + this->num_collocated_clients_
) > 0 ? 0 : -1;
310 ServerApp::set_arg(unsigned& value
,
311 const ACE_TCHAR
* arg
,
316 int tmp
= ACE_OS::atoi(arg
);
321 "Error: -%c <%s> must be integer type with a value of, "
322 "at least, %d.\n", opt
, name
, min
));
323 this->usage_statement();
332 PortableServer::POA_ptr
333 ServerApp::create_poa(CORBA::ORB_ptr orb
,
334 const char* poa_name
)
337 PortableServer::POA_var root_poa
338 = RefHelper
<PortableServer::POA
>::resolve_initial_ref(orb
,
341 // Get the POAManager from the Root POA.
342 PortableServer::POAManager_var poa_manager
343 = root_poa
->the_POAManager();
345 // Create the child POA Policies.
346 CORBA::PolicyList
policies(0);
349 // Create the child POA
350 PortableServer::POA_var poa
= AppHelper::create_poa(poa_name
,
355 // Give away the child POA_ptr from the POA_var variable.
361 ServerApp::check_validity ()
365 // Check whether the clients return any errors.
366 if (this->num_collocated_clients_
> 0
367 && this->collocated_client_task_
.failure_count () > 0)
372 Foo_B_Statistics
stats (this->num_remote_clients_
,
373 this->num_collocated_clients_
);
375 Foo_B_SimpleClientEngine::expected_results (stats
);
377 for (unsigned i
= 0; i
< this->num_servants_
; i
++)
379 this->foo_servants_
.servant(i
)->gather_stats (stats
);
382 if (this->num_collocated_clients_
> 0)
384 this->cb_servants_
.servant (0)->gather_stats (stats
);
387 return stats
.actual_vs_expected ();