5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_unistd.h"
7 #include "ace/Barrier.h"
10 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("test.ior");
11 size_t number_of_servers
= 300;
14 ACE_Barrier
*barrier
= 0;
18 parse_args (int argc
, ACE_TCHAR
*argv
[])
20 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:c:s:"));
23 while ((c
= get_opts ()) != -1)
27 ior_output_file
= get_opts
.opt_arg ();
30 number_of_servers
= ACE_OS::atoi(get_opts
.opt_arg ());
33 steps
= ACE_OS::atoi(get_opts
.opt_arg ());
38 ACE_ERROR_RETURN ((LM_ERROR
,
41 "-c <number of servers> "
47 // Indicates successful parsing of the command line
51 static TAO_SYNCH_MUTEX mutex
;
52 std::list
<MasterClient::Server_var
> servers
;
55 class MasterImpl
: public POA_MasterClient::Master
62 virtual void registerServer(MasterClient::Server_ptr c
)
64 ACE_GUARD(TAO_SYNCH_MUTEX
, mon
, mutex
);
65 servers
.push_back(MasterClient::Server::_duplicate(c
));
66 if (servers
.size () == number_of_servers
)
72 ACE_DEBUG ((LM_DEBUG
, "%d server registered with master\n", servers
.size()));
77 void Dispatcher_shutdown(void)
79 std::list
<MasterClient::Server_var
> copiedlist
;
81 ACE_GUARD(TAO_SYNCH_MUTEX
, mon
, mutex
);
84 std::list
<MasterClient::Server_var
>::iterator it
;
85 for(it
= copiedlist
.begin(); it
!= copiedlist
.end(); ++it
)
97 void Dispatcher_step(int id
, int i
)
99 std::list
<MasterClient::Server_var
> copiedlist
;
101 ACE_GUARD(TAO_SYNCH_MUTEX
, mon
, mutex
);
102 copiedlist
= servers
;
105 ACE_DEBUG ((LM_DEBUG
, "Id %d Sending %d pings in iteration %d\n", id
, copiedlist
.size(), i
));
112 std::list
<MasterClient::Server_var
>::iterator it
;
113 for(it
= copiedlist
.begin(); it
!= copiedlist
.end(); ++it
)
120 catch(CORBA::TIMEOUT
&)
124 catch(CORBA::TRANSIENT
&)
128 catch(CORBA::Exception
&e
)
130 ACE_ERROR ((LM_ERROR
, "ERROR: Caught CORBA exception %C", e
._info ().c_str()));
140 ACE_ERROR ((LM_ERROR
, "Ok: %d\n", ok
));
144 ACE_ERROR ((LM_ERROR
, "TIMEOUT: %d\n", timeout
));
148 ACE_ERROR ((LM_ERROR
, "TRANSIENT: %d\n", transient
));
152 ACE_ERROR ((LM_ERROR
, "CORBA: %d\n", corba
));
156 ACE_ERROR ((LM_ERROR
, "UNKNOWN: %d\n", unknown
));
160 void Dispatcher_run(int id
)
167 Dispatcher_step (id
, i
);
172 ACE_DEBUG ((LM_DEBUG
, "Id %d ready\n", id
));
177 ACE_DEBUG ((LM_DEBUG
, "Waiting for barrier\n"));
181 ACE_DEBUG ((LM_DEBUG
, "Shutting down ORB\n"));
187 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
191 orb
= CORBA::ORB_init (argc
, argv
);
193 if (parse_args (argc
, argv
) != 0)
196 CORBA::Object_var poa_object
=
197 orb
->resolve_initial_references("RootPOA");
199 PortableServer::POA_var root_poa
=
200 PortableServer::POA::_narrow (poa_object
.in ());
202 if (CORBA::is_nil (root_poa
.in ()))
203 ACE_ERROR_RETURN ((LM_ERROR
,
204 " (%P|%t) Panic: nil RootPOA\n"),
207 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
209 MasterImpl
*hello_impl
= 0;
210 ACE_NEW_RETURN (hello_impl
,
213 PortableServer::ServantBase_var
owner_transfer(hello_impl
);
215 PortableServer::ObjectId_var id
=
216 root_poa
->activate_object (hello_impl
);
218 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
220 MasterClient::Master_var hello
= MasterClient::Master::_narrow (object
.in ());
222 poa_manager
->activate ();
224 CORBA::String_var ior
= orb
->object_to_string (hello
.in ());
226 // Output the IOR to the <ior_output_file>
227 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
228 if (output_file
== 0)
229 ACE_ERROR_RETURN ((LM_ERROR
,
230 "Cannot open output file for writing IOR: %s\n",
233 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
234 ACE_OS::fclose (output_file
);
236 barrier
= new ACE_Barrier (n_threads
);
238 ACE_Thread_Manager
*thr_mgr
= ACE_Thread_Manager::instance ();
240 for(int i
= 0; i
< n_threads
; ++i
)
242 thr_mgr
->spawn_n (1, ACE_THR_FUNC (Dispatcher_run
), reinterpret_cast<void *> (i
), THR_NEW_LWP
| THR_DETACHED
);
247 ACE_DEBUG ((LM_DEBUG
, "Orb shutdown\n"));
251 ACE_DEBUG ((LM_DEBUG
, "Worker threads ready\n"));
253 Dispatcher_shutdown ();
257 root_poa
->destroy (1, 1);
261 orb
= CORBA::ORB::_nil ();
265 catch (const CORBA::Exception
& ex
)
267 ex
._tao_print_exception ("Exception caught:");