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
;
85 ACE_NEW_RETURN (coordinator_impl
,
86 Coordinator (peer_count
),
89 PortableServer::ObjectId_var id
=
90 root_poa
->activate_object (coordinator_impl
);
92 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
94 Test::Coordinator_var coordinator
=
95 Test::Coordinator::_narrow (object
.in ());
97 CORBA::String_var ior
=
98 orb
->object_to_string (coordinator
.in ());
100 // If the ior_output_file exists, output the ior to it
101 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
102 if (output_file
== 0)
103 ACE_ERROR_RETURN ((LM_ERROR
,
104 "Cannot open output file for writing IOR: %s",
107 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
108 ACE_OS::fclose (output_file
);
110 poa_manager
->activate ();
112 ACE_DEBUG ((LM_DEBUG
, "Waiting for peers . . . "));
114 i
!= 30 && !coordinator_impl
->has_all_peers ();
117 ACE_Time_Value
tv (1, 0);
120 ACE_DEBUG ((LM_DEBUG
, "done.\n"));
122 if (!coordinator_impl
->has_all_peers ())
124 ACE_ERROR ((LM_DEBUG
,
125 "ERROR: timeout, some peers failed to register\n"));
129 ACE_DEBUG ((LM_DEBUG
, "Building session list . . . "));
131 Session_Control
*session_control_impl
= 0;
132 ACE_NEW_RETURN (session_control_impl
,
133 Session_Control (peer_count
),
136 id
= root_poa
->activate_object (session_control_impl
);
138 object
= root_poa
->id_to_reference (id
.in ());
140 Test::Session_Control_var session_control
=
141 Test::Session_Control::_narrow (object
.in ());
143 Test::Session_List session_list
;
144 coordinator_impl
->create_session_list (session_control
.in (),
150 ACE_ASSERT (session_list
.length () == peer_count
);
151 ACE_DEBUG ((LM_DEBUG
, "done.\n"));
153 ACE_DEBUG ((LM_DEBUG
, "Giving start signal . . . "));
155 for (j
= 0; j
!= peer_count
; ++j
)
157 // Make a copy of the sessions, excluding the j-th element
158 Test::Session_List
other_sessions (peer_count
- 1);
159 other_sessions
.length (peer_count
- 1);
160 CORBA::ULong count
= 0;
161 for (CORBA::ULong k
= 0; k
!= peer_count
; ++k
)
165 other_sessions
[count
++] =
166 Test::Session::_duplicate (session_list
[k
]);
169 session_list
[j
]->start (other_sessions
);
172 ACE_DEBUG ((LM_DEBUG
, "done.\n"));
174 ACE_DEBUG ((LM_DEBUG
, "Waiting for sessions . . .\n"));
176 k
!= 300 && !session_control_impl
->all_sessions_finished ();
179 ACE_Time_Value
tv (1, 0);
183 if (!session_control_impl
->all_sessions_finished ())
185 ACE_ERROR ((LM_ERROR
,
186 "ERROR: timeout waiting for sessions\n"));
190 ACE_DEBUG ((LM_DEBUG
, "All sessions finished . . .\n"));
192 for (j
= 0; j
!= peer_count
; ++j
)
194 session_list
[j
]->destroy ();
197 ACE_DEBUG ((LM_DEBUG
, "Shutdown all peers . . .\n"));
199 coordinator_impl
->shutdown_all_peers ();
200 ACE_OS::sleep (5); // Allow the shutdown message to be processed.
201 coordinator_impl
->_remove_ref();
202 session_control_impl
->_remove_ref();
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:");