1 #include "Coordinator.h"
2 #include "Session_Control.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_stdio.h"
5 #include "ace/OS_NS_unistd.h"
7 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
8 CORBA::ULong peer_count
= 4;
9 CORBA::ULong payload_size
= 1024;
10 CORBA::ULong message_count
= 1000;
11 CORBA::ULong thread_count
= 4;
14 parse_args (int argc
, ACE_TCHAR
*argv
[])
16 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:p:b:i:n:"));
19 while ((c
= get_opts ()) != -1)
23 ior_output_file
= get_opts
.opt_arg ();
27 peer_count
= ACE_OS::atoi (get_opts
.opt_arg ());
31 payload_size
= ACE_OS::atoi (get_opts
.opt_arg ());
35 message_count
= ACE_OS::atoi (get_opts
.opt_arg ());
39 thread_count
= ACE_OS::atoi (get_opts
.opt_arg ());
44 ACE_ERROR_RETURN ((LM_ERROR
,
55 // Indicates successful parsing of the command line
60 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
65 CORBA::ORB_init (argc
, argv
);
67 CORBA::Object_var poa_object
=
68 orb
->resolve_initial_references("RootPOA");
70 PortableServer::POA_var root_poa
=
71 PortableServer::POA::_narrow (poa_object
.in ());
73 if (CORBA::is_nil (poa_object
.in ()))
74 ACE_ERROR_RETURN ((LM_ERROR
,
75 " (%P|%t) Panic got a nil RootPOA\n"),
78 PortableServer::POAManager_var poa_manager
=
79 root_poa
->the_POAManager ();
81 if (parse_args (argc
, argv
) != 0)
84 Coordinator
*coordinator_impl
= 0;
85 ACE_NEW_RETURN (coordinator_impl
,
86 Coordinator (peer_count
),
88 PortableServer::ServantBase_var
coordinator_owner (coordinator_impl
);
90 PortableServer::ObjectId_var id
=
91 root_poa
->activate_object (coordinator_impl
);
93 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
95 Test::Coordinator_var coordinator
=
96 Test::Coordinator::_narrow (object
.in ());
98 poa_manager
->activate ();
100 CORBA::String_var ior
=
101 orb
->object_to_string (coordinator
.in ());
103 // If the ior_output_file exists, output the ior to it
104 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
105 if (output_file
== 0)
106 ACE_ERROR_RETURN ((LM_ERROR
,
107 "Cannot open output file for writing IOR: %s",
110 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
111 ACE_OS::fclose (output_file
);
113 ACE_DEBUG ((LM_DEBUG
, "Waiting for peers . . . "));
115 i
!= 60 && !coordinator_impl
->has_all_peers ();
118 ACE_Time_Value
tv (1, 0);
121 ACE_DEBUG ((LM_DEBUG
, "done.\n"));
123 if (!coordinator_impl
->has_all_peers ())
125 ACE_ERROR ((LM_DEBUG
,
126 "ERROR: timeout, some peers failed to register\n"));
130 ACE_DEBUG ((LM_DEBUG
, "Building session list . . . "));
132 Session_Control
*session_control_impl
= 0;
133 ACE_NEW_RETURN (session_control_impl
,
134 Session_Control (peer_count
),
136 PortableServer::ServantBase_var
session_control_owner (session_control_impl
);
138 PortableServer::ObjectId_var idu
=
139 root_poa
->activate_object (session_control_impl
);
141 CORBA::Object_var objectu
= root_poa
->id_to_reference (idu
.in ());
143 Test::Session_Control_var session_control
=
144 Test::Session_Control::_narrow (objectu
.in ());
146 Test::Session_List session_list
;
147 coordinator_impl
->create_session_list (session_control
.in (),
153 ACE_ASSERT (session_list
.length () == peer_count
);
155 ACE_DEBUG ((LM_DEBUG
, "done.\n"));
156 ACE_DEBUG ((LM_DEBUG
, "Giving start signal . . . "));
159 for (j
= 0; j
!= peer_count
; ++j
)
161 // Make a copy of the sessions, excluding the j-th element
162 Test::Session_List
other_sessions (peer_count
- 1);
163 other_sessions
.length (peer_count
- 1);
164 CORBA::ULong count
= 0;
165 for (CORBA::ULong k
= 0; k
!= peer_count
; ++k
)
169 other_sessions
[count
++] =
170 Test::Session::_duplicate (session_list
[k
]);
173 session_list
[j
]->start (other_sessions
);
176 ACE_DEBUG ((LM_DEBUG
,"done\n"));
177 ACE_DEBUG ((LM_DEBUG
, "Waiting for sessions to finish. . .\n"));
179 k
!= 300 && !session_control_impl
->all_sessions_finished ();
182 ACE_Time_Value
tv (1, 0);
186 if (!session_control_impl
->all_sessions_finished ())
188 ACE_ERROR ((LM_ERROR
,
189 "ERROR: timeout waiting for sessions\n"));
193 ACE_DEBUG ((LM_DEBUG
, "All sessions finished, destroy session list . . .\n"));
195 for (j
= 0; j
!= peer_count
; ++j
)
197 session_list
[j
]->destroy ();
200 ACE_DEBUG ((LM_DEBUG
, "Shutdown all peers . . .\n"));
202 coordinator_impl
->shutdown_all_peers ();
203 ACE_OS::sleep (5); // Allow the shutdown message to be processed.
204 ACE_DEBUG ((LM_DEBUG
, "Shutdown poa and orb . . .\n"));
206 root_poa
->destroy (true, true);
210 catch (const CORBA::Exception
& ex
)
212 ex
._tao_print_exception ("Exception caught:");