2 #include "FooServantList.h"
4 #include "OrbShutdownTask.h"
5 #include "ace/Get_Opt.h"
6 #include "tao/CSD_ThreadPool/CSD_TP_Strategy.h"
7 #include "tao/Intrusive_Ref_Count_Handle_T.h"
8 // To force static load the service.
10 #include "tao/CSD_ThreadPool/CSD_ThreadPool.h"
13 ServerApp::ServerApp()
14 : ior_filename_(ACE_TEXT("foo")),
21 ServerApp::~ServerApp()
27 ServerApp::run (int argc
, ACE_TCHAR
* argv
[])
29 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
31 // Parse the command-line args for this application.
32 // * Raises -1 if problems are encountered.
33 // * Returns 1 if the usage statement was explicitly requested.
34 // * Returns 0 otherwise.
35 int result
= this->parse_args (argc
, argv
);
41 TheOrbShutdownTask::instance()->orb (orb
.in ());
44 = orb
->resolve_initial_references("RootPOA");
46 if (CORBA::is_nil(obj
.in()))
49 "(%P|%t) Failed to resolve initial ref for 'RootPOA'.\n"));
50 throw TestException();
53 PortableServer::POA_var root_poa
54 = PortableServer::POA::_narrow(obj
.in());
56 if (CORBA::is_nil(root_poa
.in()))
59 "(%P|%t) Failed to narrow obj ref to POA interface.\n"));
60 throw TestException();
63 PortableServer::POAManager_var poa_manager
64 = root_poa
->the_POAManager();
66 // Create the child POA.
67 CORBA::PolicyList
policies(1);
70 policies
[0] = root_poa
->create_id_assignment_policy(PortableServer::USER_ID
);
72 PortableServer::POA_var child_poa
73 = root_poa
->create_POA("ChildPoa",
77 if (CORBA::is_nil(child_poa
.in()))
79 ACE_ERROR((LM_ERROR
, "(%P|%t) ERROR [ServerApp::run()]: "
80 "Failed to create the child POA.\n"));
81 throw TestException();
84 policies
[0]->destroy ();
86 // Create the thread pool servant dispatching strategy object, and
87 // hold it in a (local) smart pointer variable.
88 TAO_Intrusive_Ref_Count_Handle
<TAO::CSD::TP_Strategy
> csd_tp_strategy
=
89 new TAO::CSD::TP_Strategy();
91 csd_tp_strategy
->set_num_threads(this->num_servants_
);
93 // Tell the strategy to apply itself to the child poa.
94 if (csd_tp_strategy
->apply_to(child_poa
.in()) == false)
96 ACE_ERROR((LM_ERROR
, "(%P|%t) ERROR [ServerApp::run()]: "
97 "Failed to apply custom dispatching strategy to child poa.\n"));
98 throw TestException();
101 FooServantList
servants(this->ior_filename_
.c_str(),
106 servants
.create_and_activate(child_poa
.in());
108 // Activate the POA Manager
109 poa_manager
->activate();
112 "(%P|%t) ServerApp is ready. Running the ORB event loop.\n"));
114 // Run the ORB event loop.
118 "(%P|%t) ServerApp ORB has stopped running. "
119 "Stop the CSD strategy.\n"));
121 // Sleep for 2 second to let the done() two-way call complete
126 "(%P|%t) ServerApp is waiting for OrbShutdownTask.\n"));
127 TheOrbShutdownTask::instance()->wait ();
130 "(%P|%t) ServerApp is destroying the Root POA.\n"));
132 // Tear-down the root poa and orb.
133 root_poa
->destroy(1, 1);
136 "(%P|%t) ServerApp is destroying the ORB.\n"));
141 "(%P|%t) ServerApp has completed running successfully.\n"));
148 ServerApp::parse_args(int argc
, ACE_TCHAR
* argv
[])
150 this->exe_name_
= argv
[0];
152 ACE_Get_Opt
get_opts(argc
, argv
, ACE_TEXT("p:s:c:"));
157 while ((c
= get_opts()) != -1)
162 this->ior_filename_
= get_opts
.opt_arg();
166 tmp
= ACE_OS::atoi(get_opts
.opt_arg());
169 this->usage_statement();
173 this->num_servants_
= tmp
;
177 tmp
= ACE_OS::atoi(get_opts
.opt_arg());
180 this->usage_statement();
184 this->num_clients_
= tmp
;
188 this->usage_statement();
192 this->usage_statement();
202 ServerApp::usage_statement()
205 "Usage: %s [options]\n\n"
207 "\t[-p <ior_filename_prefix>]\n"
208 "\t[-s <num_servants>]\n"
209 "\t[-c <num_clients>]\n"
211 "Default ior_filename_prefix is 'foo'.\n"
212 "Default num_servants is 1.\n"
213 "Default num_clients is 1.\n\n",
214 this->exe_name_
.c_str()));