2 #include "ace/Get_Opt.h"
5 const ACE_TCHAR
*ior_output_file
= 0;
6 const ACE_TCHAR
*corbaloc_arg
= ACE_TEXT("corbaloc:iiop:1.0@localhost:12000/ObjectName");
10 int nclient_threads
= nthreads
;
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("c:l:i:o:n:"));
18 while ((c
= get_opts ()) != -1)
22 nclient_threads
= ACE_OS::atoi (get_opts
.opt_arg ());
26 corbaloc_arg
= get_opts
.opt_arg ();
30 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
34 ior_output_file
= get_opts
.opt_arg ();
38 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
43 ACE_ERROR_RETURN ((LM_ERROR
,
45 "-c <# client threads> "
48 "-n <# server threads> "
54 // Indicates successful parsing of the command line
58 /*****************************************************/
63 * Use the ACE_Task_Base class to run server threads
65 class Worker
: public ACE_Task_Base
69 Worker (CORBA::ORB_ptr orb
);
71 /// The thread entry point.
79 /*****************************************************/
84 * Use the ACE_Task_Base class to run client threads
86 class SelfClient
: public ACE_Task_Base
89 SelfClient (CORBA::ORB_ptr orb
, Simple_Server_ptr server
, int niterations
);
93 // The thread entry point.
96 void validate_connection ();
97 // Validate the connection
101 Simple_Server_var server_
;
105 /// The number of iterations on each client thread.
109 TAO_SYNCH_MUTEX mutex_
;
112 /***************************************************/
114 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
119 CORBA::ORB_init (argc
, argv
);
121 CORBA::Object_var poa_object
=
122 orb
->resolve_initial_references ("RootPOA");
124 if (CORBA::is_nil (poa_object
.in ()))
125 ACE_ERROR_RETURN ((LM_ERROR
,
126 " (%P|%t) Unable to initialize the POA.\n"),
129 PortableServer::POA_var root_poa
=
130 PortableServer::POA::_narrow (poa_object
.in ());
132 PortableServer::POAManager_var poa_manager
=
133 root_poa
->the_POAManager ();
135 if (parse_args (argc
, argv
) != 0)
138 Simple_Server_i
*server_impl
= 0;
139 ACE_NEW_RETURN (server_impl
,
140 Simple_Server_i (orb
.in ()),
143 PortableServer::ServantBase_var
owner_transfer(server_impl
);
145 PortableServer::ObjectId_var id
=
146 root_poa
->activate_object (server_impl
);
148 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
150 Simple_Server_var server
=
151 Simple_Server::_narrow (object
.in ());
153 CORBA::String_var ior
=
154 orb
->object_to_string (server
.in ());
156 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
158 // If the ior_output_file exists, output the ior to it
159 if (ior_output_file
!= 0)
161 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
162 if (output_file
== 0)
163 ACE_ERROR_RETURN ((LM_ERROR
,
164 "(%P|%t) Cannot open output file for writing IOR: %s",
167 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
168 ACE_OS::fclose (output_file
);
171 poa_manager
->activate ();
173 Worker
worker (orb
.in ());
174 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
176 ACE_ERROR_RETURN ((LM_ERROR
,
177 "(%P|%t) Cannot activate client threads\n"),
180 SelfClient
selfabuse (orb
.in(), server
.in(), niterations
);
181 if (selfabuse
.activate (THR_NEW_LWP
| THR_JOINABLE
,
182 nclient_threads
) != 0)
183 ACE_ERROR_RETURN ((LM_ERROR
,
184 "(%P|%t) Cannot activate abusive threads\n"),
187 selfabuse
.thr_mgr()->wait();
189 worker
.thr_mgr ()->wait ();
191 ACE_DEBUG ((LM_DEBUG
,
192 "(%P|%t) event loop finished\n"));
194 catch (const CORBA::Exception
& ex
)
196 ex
._tao_print_exception ("Exception caught:");
203 // ****************************************************************
205 Worker::Worker (CORBA::ORB_ptr orb
)
206 : orb_ (CORBA::ORB::_duplicate (orb
))
215 ACE_Time_Value
tv (140, 0);
216 this->orb_
->run (tv
);
218 catch (const CORBA::Exception
&)
224 // ****************************************************************
226 SelfClient::SelfClient (CORBA::ORB_ptr orb
, Simple_Server_ptr server
,
228 : server_ (Simple_Server::_duplicate (server
)),
229 orb_ (CORBA::ORB::_duplicate (orb
)),
230 niterations_ (niterations
)
235 SelfClient::validate_connection ()
237 // Ping the object 100 times, ignoring all exceptions.
238 // It would be better to use validate_connection() but the test must
239 // run on minimum CORBA builds too!
240 ACE_GUARD (TAO_SYNCH_MUTEX
, guard
, mutex_
);
242 for (int j
= 0; j
!= 100; ++j
)
246 this->server_
->test_method (j
);
248 catch (const CORBA::Exception
&){}
257 this->validate_connection ();
259 for (int i
= 0; i
< this->niterations_
; ++i
)
263 CORBA::Object_var probably_not_exist
=
264 orb_
->string_to_object (corbaloc_arg
);
267 if (CORBA::is_nil (probably_not_exist
.in()))
269 ACE_DEBUG ((LM_DEBUG
, "not found\n", corbaloc_arg
));
273 Simple_Server_var newserver
=
274 Simple_Server::_narrow (probably_not_exist
.in ());
276 // should throw an exception
277 if (CORBA::is_nil (newserver
.in()))
279 ACE_DEBUG ((LM_DEBUG
,
280 "(%P|%t) Not found it\n"));
284 ACE_DEBUG ((LM_DEBUG
,
285 "(%P|%t) Found it\n"));
290 catch (const CORBA::Exception
& ex
)
292 ex
._tao_print_exception ("MT_SelfClient: exception raised");
296 this->server_
->test_method (i
);
299 catch (const CORBA::Exception
& ex
)
301 ex
._tao_print_exception ("MT_SelfClient: exception raised");