2 #include "Client_Task.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "tao/TimeBaseC.h"
5 #include "tao/Messaging/Messaging.h"
6 #include "tao/AnyTypeCode/Any.h"
8 Client_Task::Client_Task (CORBA::ORB_ptr orb
,
9 Test::Sleep_Service_ptr sleep_service
,
11 CORBA::ULong sleep_time
,
13 : orb_ (CORBA::ORB::_duplicate (orb
))
14 , sleep_service_ (Test::Sleep_Service::_duplicate (sleep_service
))
15 , iterations_ (iterations
)
16 , sleep_time_ (sleep_time
)
18 , successful_calls_ (0)
19 , timed_out_calls_ (0)
20 , too_big_difference_ (0)
25 Client_Task::successful_calls (void) const
27 return this->successful_calls_
;
31 Client_Task::timed_out_calls (void) const
33 return this->timed_out_calls_
;
37 Client_Task::too_big_difference_calls (void) const
39 return this->too_big_difference_
;
43 Client_Task::svc (void)
46 int successful_calls
= 0;
47 int timed_out_calls
= 0;
51 this->validate_connection ();
53 CORBA::Object_var object
=
54 this->orb_
->resolve_initial_references ("PolicyCurrent");
55 CORBA::PolicyCurrent_var policy_current
=
56 CORBA::PolicyCurrent::_narrow (object
.in ());
58 TimeBase::TimeT timeout_period
= 10 * this->timeout_
;
60 CORBA::Any timeout_as_any
;
61 timeout_as_any
<<= timeout_period
;
63 CORBA::PolicyList
policy_list (1);
64 policy_list
.length (1);
66 this->orb_
->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
69 policy_current
->set_policy_overrides (policy_list
,
72 for (int i
= 0; i
!= this->iterations_
; ++i
)
74 int retval
= this->one_iteration ();
85 "(%P|%t) - Client_Task::svc %d / %d iterations\n",
86 i
, this->iterations_
));
91 catch (const CORBA::Exception
& ex
)
93 ex
._tao_print_exception ("Exception caught:");
97 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
, ace_mon
, this->mutex_
, -1);
98 this->successful_calls_
+= successful_calls
;
99 this->timed_out_calls_
+= timed_out_calls
;
105 Client_Task::validate_connection (void)
109 for (int i
= 0; i
!= 100; ++i
)
111 (void) this->sleep_service_
->go_to_sleep (0);
114 catch (const CORBA::TRANSIENT
& )
116 // Ignore transient exceptions
121 Client_Task::one_iteration (void)
125 ACE_Time_Value start
= ACE_OS::gettimeofday ();
127 this->sleep_service_
->go_to_sleep (this->sleep_time_
);
129 ACE_Time_Value end
= ACE_OS::gettimeofday ();
131 if (this->sleep_time_
> this->timeout_
)
133 // If we don't sleep then the next request will also
135 // The server is already sleeping, the client sends a new
136 // request, but the server cannot process it until the
137 // previous sleep completes. The sleep times for multiple
138 // requests accumulate, and the client always fails.
139 CORBA::ULong remainder
=
140 this->sleep_time_
- this->timeout_
;
141 ACE_Time_Value
tv (0, remainder
);
145 if (this->timeout_
> 0)
147 CORBA::ULong max_milliseconds
= this->timeout_
/ 1000;
149 ACE_Time_Value elapsed
= end
- start
;
150 CORBA::ULong elapsed_milliseconds
= elapsed
.msec ();
152 if (elapsed_milliseconds
> max_milliseconds
)
154 CORBA::ULong difference
=
155 elapsed_milliseconds
- max_milliseconds
;
157 // If the different is more than 10 milliseconds we are
158 // *way* off, this is an error.
161 this->too_big_difference_
++;
162 ACE_ERROR ((LM_ERROR
,
163 "(%P|%t) Elapsed time = %d, expected %d\n",
164 elapsed_milliseconds
, max_milliseconds
));
171 catch (const CORBA::TIMEOUT
& )
173 // Ignore this exception, it is usually caused by a transient
177 catch (const CORBA::Exception
& ex
)
179 ex
._tao_print_exception ("Exception caught:");