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 () const
27 return this->successful_calls_
;
31 Client_Task::timed_out_calls () const
33 return this->timed_out_calls_
;
37 Client_Task::too_big_difference_calls () const
39 return this->too_big_difference_
;
45 int successful_calls
= 0;
46 int timed_out_calls
= 0;
50 this->validate_connection ();
52 CORBA::Object_var object
=
53 this->orb_
->resolve_initial_references ("PolicyCurrent");
54 CORBA::PolicyCurrent_var policy_current
=
55 CORBA::PolicyCurrent::_narrow (object
.in ());
57 TimeBase::TimeT timeout_period
= 10 * this->timeout_
;
59 CORBA::Any timeout_as_any
;
60 timeout_as_any
<<= timeout_period
;
62 CORBA::PolicyList
policy_list (1);
63 policy_list
.length (1);
65 this->orb_
->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
68 policy_current
->set_policy_overrides (policy_list
,
71 for (int i
= 0; i
!= this->iterations_
; ++i
)
73 int retval
= this->one_iteration ();
84 "(%P|%t) - Client_Task::svc %d / %d iterations\n",
85 i
, this->iterations_
));
90 catch (const CORBA::Exception
& ex
)
92 ex
._tao_print_exception ("Exception caught:");
96 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
, ace_mon
, this->mutex_
, -1);
97 this->successful_calls_
+= successful_calls
;
98 this->timed_out_calls_
+= timed_out_calls
;
104 Client_Task::validate_connection ()
108 for (int i
= 0; i
!= 100; ++i
)
110 (void) this->sleep_service_
->go_to_sleep (0);
113 catch (const CORBA::TRANSIENT
& )
115 // Ignore transient exceptions
120 Client_Task::one_iteration ()
124 ACE_Time_Value start
= ACE_OS::gettimeofday ();
126 this->sleep_service_
->go_to_sleep (this->sleep_time_
);
128 ACE_Time_Value end
= ACE_OS::gettimeofday ();
130 if (this->sleep_time_
> this->timeout_
)
132 // If we don't sleep then the next request will also
134 // The server is already sleeping, the client sends a new
135 // request, but the server cannot process it until the
136 // previous sleep completes. The sleep times for multiple
137 // requests accumulate, and the client always fails.
138 CORBA::ULong remainder
=
139 this->sleep_time_
- this->timeout_
;
140 ACE_Time_Value
tv (0, remainder
);
144 if (this->timeout_
> 0)
146 CORBA::ULong max_milliseconds
= this->timeout_
/ 1000;
148 ACE_Time_Value elapsed
= end
- start
;
149 CORBA::ULong elapsed_milliseconds
= elapsed
.msec ();
151 if (elapsed_milliseconds
> max_milliseconds
)
153 CORBA::ULong difference
=
154 elapsed_milliseconds
- max_milliseconds
;
156 // If the different is more than 10 milliseconds we are
157 // *way* off, this is an error.
160 this->too_big_difference_
++;
161 ACE_ERROR ((LM_ERROR
,
162 "(%P|%t) Elapsed time = %d, expected %d\n",
163 elapsed_milliseconds
, max_milliseconds
));
170 catch (const CORBA::TIMEOUT
& )
172 // Ignore this exception, it is usually caused by a transient
176 catch (const CORBA::Exception
& ex
)
178 ex
._tao_print_exception ("Exception caught:");