2 //=============================================================================
6 * This is a client that uses oneways with buffering constraints
7 * and roundtrip timeout constraints.
9 * @author Irfan Pyarali
11 //=============================================================================
16 #include "tao/Messaging/Messaging.h"
17 #include "tao/AnyTypeCode/TAOA.h"
18 #include "tao/AnyTypeCode/Any.h"
20 #include "ace/Get_Opt.h"
21 #include "ace/Read_Buffer.h"
22 #include "ace/OS_NS_unistd.h"
23 #include "ace/OS_NS_sys_time.h"
25 // Eager buffering option.
26 static int eager_buffering
= 0;
28 // Name of file contains ior.
29 static const ACE_TCHAR
*IOR
= ACE_TEXT ("file://ior");
31 // Default iterations.
32 static u_long iterations
= 20;
34 // Default number of bytes to send as data.
35 static CORBA::ULong data_bytes
= 100000;
37 // Default roundtrip timeout (in milli seconds).
38 static long timeout
= 500;
40 // Default amount of work.
41 static CORBA::ULong work
= 3000;
43 // Time interval between invocation (in milli seconds).
44 static u_long interval
= 500;
46 // Flag indicates whether to shutdown remote server or not upon client
48 static int shutdown_server
= 0;
51 parse_args (int argc
, ACE_TCHAR
**argv
)
53 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("ek:i:d:t:w:z:x"));
56 while ((c
= get_opts ()) != -1)
64 IOR
= get_opts
.opt_arg ();
68 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
72 data_bytes
= ACE_OS::atoi (get_opts
.opt_arg ());
76 timeout
= ACE_OS::atoi (get_opts
.opt_arg ());
80 work
= ACE_OS::atoi (get_opts
.opt_arg ());
84 interval
= ACE_OS::atoi (get_opts
.opt_arg ());
93 ACE_ERROR_RETURN ((LM_ERROR
,
95 "-e eager buffering [default is delayed] "
99 "-t roundtrip timeout "
101 "-z interval between calls "
102 "-x shutdown server "
109 ACE_ERROR_RETURN ((LM_ERROR
,
110 "Please specify the IOR for the servant\n"), -1);
112 // Indicates successful parsing of command line.
117 setup_policies (CORBA::ORB_ptr orb
, test_ptr object
)
119 test_var object_with_policy
;
120 CORBA::PolicyList
policy_list (1);
123 object_with_policy
= test::_duplicate (object
);
127 policy_list
.length (1);
128 TimeBase::TimeT rt_timeout
= 10 * 1000 * timeout
;
130 CORBA::Any rt_timeout_any
;
131 rt_timeout_any
<<= rt_timeout
;
133 orb
->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
136 CORBA::Object_var object_temp
=
137 object
->_set_policy_overrides (policy_list
,
138 CORBA::ADD_OVERRIDE
);
140 object_with_policy
= test::_narrow (object_temp
.in ());
142 policy_list
[0]->destroy ();
145 Messaging::SyncScope sync
=
146 eager_buffering
? Messaging::SYNC_NONE
: TAO::SYNC_DELAYED_BUFFERING
;
151 policy_list
.length (1);
153 orb
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
156 CORBA::Object_var object_temp
=
157 object_with_policy
->_set_policy_overrides (policy_list
,
158 CORBA::ADD_OVERRIDE
);
160 test_var object_with_two_policies
= test::_narrow (object_temp
.in ());
162 policy_list
[0]->destroy ();
164 return object_with_two_policies
._retn ();
168 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
172 // Initialize the ORB.
174 CORBA::ORB_init (argc
, argv
);
176 // Initialize options based on command-line arguments.
177 int parse_args_result
= parse_args (argc
, argv
);
178 if (parse_args_result
!= 0)
179 return parse_args_result
;
181 // Get an object reference from the argument string.
182 CORBA::Object_var object
=
183 orb
->string_to_object (IOR
);
185 // Try to narrow the object reference to a <test> reference.
186 test_var test_object_no_policy
= test::_narrow (object
.in ());
188 // Setup buffering and timeout
189 test_var test_object
= setup_policies (orb
.in (),
190 test_object_no_policy
.in ());
192 test::data
the_data (data_bytes
);
193 the_data
.length (data_bytes
);
195 for (CORBA::ULong i
= 1; i
<= iterations
; ++i
)
197 ACE_Time_Value start
= ACE_OS::gettimeofday (), end
;
200 // Invoke the oneway method.
201 test_object
->method (i
,
205 end
= ACE_OS::gettimeofday ();
207 ACE_DEBUG ((LM_DEBUG
,
208 "client:\t%d took\t%dms\n",
209 i
, (end
- start
).msec ()));
211 // Interval between successive calls.
212 ACE_Time_Value
sleep_interval (0, interval
* 1000);
214 // If we don't run the orb, then no data will be sent, and no
215 // connection will be made initially.
216 orb
->run (sleep_interval
);
218 catch (const CORBA::TIMEOUT
& )
220 // The timeout could be from a previous loop.
221 // A simplistic analysis could incorrectly conclude
222 // that as an unexpected timeout exception.
223 // We need to maintain a base start time thats updated
224 // in each iteration.
226 ACE_DEBUG ((LM_DEBUG
, "client: caught expected timeout\n"));
230 ACE_DEBUG ((LM_DEBUG
, "client: flushing\n"));
231 test_object_no_policy
->flush ();
233 ACE_DEBUG ((LM_DEBUG
, "client: Shutting down...\n"));
236 ACE_DEBUG ((LM_DEBUG
,"client killing server\n"));
237 long now
= ACE_OS::gettimeofday ().msec ();
238 test_object_no_policy
->shutdown (now
);
241 orb
->shutdown (true);
243 // Destroy the ORB. On some platforms, e.g., Win32, the socket
244 // library is closed at the end of main(). This means that any
245 // socket calls made after main() fail. Hence if we wait for
246 // static destructors to flush the queues, it will be too late.
247 // Therefore, we use explicit destruction here and flush the
248 // queues before main() ends.
251 catch (const CORBA::Exception
& ex
)
253 ex
._tao_print_exception ("Client side exception caught:");