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.
72 virtual int svc (void);
80 /*****************************************************/
85 * Use the ACE_Task_Base class to run client threads
87 class SelfClient
: public ACE_Task_Base
90 SelfClient (CORBA::ORB_ptr orb
, Simple_Server_ptr server
, int niterations
);
93 virtual int svc (void);
94 // The thread entry point.
97 void validate_connection (void);
98 // Validate the connection
103 Simple_Server_var server_
;
107 /// The number of iterations on each client thread.
111 TAO_SYNCH_MUTEX mutex_
;
114 /***************************************************/
116 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
121 CORBA::ORB_init (argc
, argv
);
123 CORBA::Object_var poa_object
=
124 orb
->resolve_initial_references ("RootPOA");
126 if (CORBA::is_nil (poa_object
.in ()))
127 ACE_ERROR_RETURN ((LM_ERROR
,
128 " (%P|%t) Unable to initialize the POA.\n"),
131 PortableServer::POA_var root_poa
=
132 PortableServer::POA::_narrow (poa_object
.in ());
134 PortableServer::POAManager_var poa_manager
=
135 root_poa
->the_POAManager ();
137 if (parse_args (argc
, argv
) != 0)
140 Simple_Server_i
*server_impl
= 0;
141 ACE_NEW_RETURN (server_impl
,
142 Simple_Server_i (orb
.in ()),
145 PortableServer::ServantBase_var
owner_transfer(server_impl
);
147 PortableServer::ObjectId_var id
=
148 root_poa
->activate_object (server_impl
);
150 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
152 Simple_Server_var server
=
153 Simple_Server::_narrow (object
.in ());
155 CORBA::String_var ior
=
156 orb
->object_to_string (server
.in ());
158 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
160 // If the ior_output_file exists, output the ior to it
161 if (ior_output_file
!= 0)
163 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
164 if (output_file
== 0)
165 ACE_ERROR_RETURN ((LM_ERROR
,
166 "(%P|%t) Cannot open output file for writing IOR: %s",
169 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
170 ACE_OS::fclose (output_file
);
173 poa_manager
->activate ();
175 Worker
worker (orb
.in ());
176 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
178 ACE_ERROR_RETURN ((LM_ERROR
,
179 "(%P|%t) Cannot activate client threads\n"),
182 SelfClient
selfabuse (orb
.in(), server
.in(), niterations
);
183 if (selfabuse
.activate (THR_NEW_LWP
| THR_JOINABLE
,
184 nclient_threads
) != 0)
185 ACE_ERROR_RETURN ((LM_ERROR
,
186 "(%P|%t) Cannot activate abusive threads\n"),
189 selfabuse
.thr_mgr()->wait();
191 worker
.thr_mgr ()->wait ();
193 ACE_DEBUG ((LM_DEBUG
,
194 "(%P|%t) event loop finished\n"));
196 catch (const CORBA::Exception
& ex
)
198 ex
._tao_print_exception ("Exception caught:");
205 // ****************************************************************
207 Worker::Worker (CORBA::ORB_ptr orb
)
208 : orb_ (CORBA::ORB::_duplicate (orb
))
217 ACE_Time_Value
tv (140, 0);
218 this->orb_
->run (tv
);
220 catch (const CORBA::Exception
&)
226 // ****************************************************************
228 SelfClient::SelfClient (CORBA::ORB_ptr orb
, Simple_Server_ptr server
,
230 : server_ (Simple_Server::_duplicate (server
)),
231 orb_ (CORBA::ORB::_duplicate (orb
)),
232 niterations_ (niterations
)
237 SelfClient::validate_connection (void)
239 // Ping the object 100 times, ignoring all exceptions.
240 // It would be better to use validate_connection() but the test must
241 // run on minimum CORBA builds too!
242 ACE_GUARD (TAO_SYNCH_MUTEX
, guard
, mutex_
);
244 for (int j
= 0; j
!= 100; ++j
)
248 this->server_
->test_method (j
);
250 catch (const CORBA::Exception
&){}
255 SelfClient::svc (void)
259 this->validate_connection ();
261 for (int i
= 0; i
< this->niterations_
; ++i
)
265 CORBA::Object_var probably_not_exist
=
266 orb_
->string_to_object (corbaloc_arg
);
269 if (CORBA::is_nil (probably_not_exist
.in()))
271 ACE_DEBUG ((LM_DEBUG
, "not found\n", corbaloc_arg
));
275 Simple_Server_var newserver
=
276 Simple_Server::_narrow (probably_not_exist
.in ());
278 // should throw an exception
279 if (CORBA::is_nil (newserver
.in()))
281 ACE_DEBUG ((LM_DEBUG
,
282 "(%P|%t) Not found it\n"));
287 ACE_DEBUG ((LM_DEBUG
,
288 "(%P|%t) Found it\n"));
293 catch (const CORBA::Exception
& ex
)
295 ex
._tao_print_exception ("MT_SelfClient: exception raised");
299 this->server_
->test_method (i
);
303 catch (const CORBA::Exception
& ex
)
305 ex
._tao_print_exception ("MT_SelfClient: exception raised");