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
)
120 test_var object_with_policy
;
121 CORBA::PolicyList
policy_list (1);
124 object_with_policy
= test::_duplicate (object
);
128 policy_list
.length (1);
129 TimeBase::TimeT rt_timeout
= 10 * 1000 * timeout
;
131 CORBA::Any rt_timeout_any
;
132 rt_timeout_any
<<= rt_timeout
;
134 orb
->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
137 CORBA::Object_var object_temp
=
138 object
->_set_policy_overrides (policy_list
,
139 CORBA::ADD_OVERRIDE
);
141 object_with_policy
= test::_narrow (object_temp
.in ());
143 policy_list
[0]->destroy ();
146 Messaging::SyncScope sync
=
147 eager_buffering
? Messaging::SYNC_NONE
: TAO::SYNC_DELAYED_BUFFERING
;
152 policy_list
.length (1);
154 orb
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
157 CORBA::Object_var object_temp
=
158 object_with_policy
->_set_policy_overrides (policy_list
,
159 CORBA::ADD_OVERRIDE
);
161 test_var object_with_two_policies
= test::_narrow (object_temp
.in ());
163 policy_list
[0]->destroy ();
165 return object_with_two_policies
._retn ();
169 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
174 // Initialize the ORB.
176 CORBA::ORB_init (argc
, argv
);
178 // Initialize options based on command-line arguments.
179 int parse_args_result
= parse_args (argc
, argv
);
180 if (parse_args_result
!= 0)
181 return parse_args_result
;
183 // Get an object reference from the argument string.
184 CORBA::Object_var object
=
185 orb
->string_to_object (IOR
);
187 // Try to narrow the object reference to a <test> reference.
188 test_var test_object_no_policy
= test::_narrow (object
.in ());
190 // Setup buffering and timeout
191 test_var test_object
= setup_policies (orb
.in (),
192 test_object_no_policy
.in ());
194 test::data
the_data (data_bytes
);
195 the_data
.length (data_bytes
);
197 for (CORBA::ULong i
= 1; i
<= iterations
; ++i
)
199 ACE_Time_Value start
= ACE_OS::gettimeofday (), end
;
202 // Invoke the oneway method.
203 test_object
->method (i
,
207 end
= ACE_OS::gettimeofday ();
209 ACE_DEBUG ((LM_DEBUG
,
210 "client:\t%d took\t%dms\n",
211 i
, (end
- start
).msec ()));
213 // Interval between successive calls.
214 ACE_Time_Value
sleep_interval (0, interval
* 1000);
216 // If we don't run the orb, then no data will be sent, and no
217 // connection will be made initially.
218 orb
->run (sleep_interval
);
220 catch (const CORBA::TIMEOUT
& )
222 // The timeout could be from a previous loop.
223 // A simplistic analysis could incorrectly conclude
224 // that as an unexpected timeout exception.
225 // We need to maintain a base start time thats updated
226 // in each iteration.
228 ACE_DEBUG ((LM_DEBUG
, "client: caught expected timeout\n"));
232 ACE_DEBUG ((LM_DEBUG
, "client: flushing\n"));
233 test_object_no_policy
->flush ();
235 ACE_DEBUG ((LM_DEBUG
, "client: Shutting down...\n"));
238 ACE_DEBUG ((LM_DEBUG
,"client killing server\n"));
239 long now
= ACE_OS::gettimeofday ().msec ();
240 test_object_no_policy
->shutdown (now
);
245 // Destroy the ORB. On some platforms, e.g., Win32, the socket
246 // library is closed at the end of main(). This means that any
247 // socket calls made after main() fail. Hence if we wait for
248 // static destructors to flush the queues, it will be too late.
249 // Therefore, we use explicit destruction here and flush the
250 // queues before main() ends.
253 catch (const CORBA::Exception
& ex
)
255 ex
._tao_print_exception ("Client side exception caught:");