3 #include "ace/Get_Opt.h"
6 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
7 const ACE_TCHAR
*corbaloc_arg
= ACE_TEXT("corbaloc:iiop:1.0@localhost:12000/ObjectName");
10 int server_shutdown
= 0;
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("l:k:n:i:x"));
18 while ((c
= get_opts ()) != -1)
22 ior
= get_opts
.opt_arg ();
25 corbaloc_arg
= get_opts
.opt_arg ();
28 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
31 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
38 ACE_ERROR_RETURN ((LM_ERROR
,
47 // Indicates successful parsing of the command line
51 class Client
: public ACE_Task_Base
54 // Run the client thread
57 // Use the ACE_Task_Base class to run the client threads.
60 Client (Simple_Server_ptr server
, int niterations
);
64 // The thread entry point.
67 void validate_connection ();
68 // Validate the connection
71 Simple_Server_var server_
;
75 // The number of iterations on each client thread.
79 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
84 CORBA::ORB_init (argc
, argv
);
86 if (parse_args (argc
, argv
) != 0)
89 CORBA::Object_var object
=
90 orb
->string_to_object (ior
);
92 Simple_Server_var server
=
93 Simple_Server::_narrow (object
.in ());
95 if (CORBA::is_nil (server
.in ()))
97 ACE_ERROR_RETURN ((LM_ERROR
,
98 "Object reference <%s> is nil.\n",
103 Client
client (server
.in (), niterations
);
104 if (client
.activate (THR_NEW_LWP
| THR_JOINABLE
,
106 ACE_ERROR_RETURN ((LM_ERROR
,
107 "Cannot activate client threads\n"),
110 // While those threads are busy sending 1.2 messages
111 // send some corba loc requests, don't really care if there is an
112 // object there to find
113 if (!server_shutdown
)
115 ACE_DEBUG ((LM_DEBUG
,
116 "starting string_to_object %s\n",
119 for (int c
= 0; c
< (niterations
* 2); c
++)
123 CORBA::Object_var probably_not_exist
=
124 orb
->string_to_object(corbaloc_arg
);
127 if (CORBA::is_nil(probably_not_exist
.in()))
129 ACE_DEBUG ((LM_DEBUG
, "not found\n", corbaloc_arg
));
133 Simple_Server_var newserver
=
134 Simple_Server::_narrow (probably_not_exist
.in ());
136 // should throw an exception
137 if (CORBA::is_nil(newserver
.in()))
139 ACE_DEBUG ((LM_DEBUG
, "not found it\n", corbaloc_arg
));
143 ACE_DEBUG ((LM_DEBUG
, "found it\n", corbaloc_arg
));
147 catch (const CORBA::Exception
&)
149 // ACE_DEBUG ((LM_DEBUG, "caught exception\n", corbaloc_arg));
153 ACE_DEBUG ((LM_DEBUG
,
154 "(%P|%t) waiting for threads\n"));
156 client
.thr_mgr ()->wait ();
158 ACE_DEBUG ((LM_DEBUG
,
159 "(%P|%t) threads finished\n"));
168 catch (const CORBA::Exception
& ex
)
170 ex
._tao_print_exception ("Caught exception:");
177 // ****************************************************************
179 Client::Client (Simple_Server_ptr server
,
181 : server_ (Simple_Server::_duplicate (server
)),
182 niterations_ (niterations
)
187 Client::validate_connection ()
189 // Ping the object 100 times, ignoring all exceptions.
190 // It would be better to use validate_connection() but the test must
191 // run on minimum CORBA builds too!
192 for (int j
= 0; j
!= 100; ++j
)
196 this->server_
->test_method (j
);
198 catch (const CORBA::Exception
&){}
207 this->validate_connection ();
209 for (int i
= 0; i
< this->niterations_
; ++i
)
211 this->server_
->test_method (i
);
213 if (TAO_debug_level
> 0 && i
% 100 == 0)
214 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) iteration = %d\n",
218 catch (const CORBA::Exception
& ex
)
220 ex
._tao_print_exception ("MT_Client: exception raised");