2 #include "Client_Task.h"
3 #include "tao/AnyTypeCode/Any.h"
7 const ACE_Time_Value
TRANSIENT_HOLDOFF (0, 2000); // 2ms delay
8 const int TRANSIENT_LIMIT
= 100;
11 Client_Task::Client_Task (ACE_Thread_Manager
*thr_mgr
,
12 Test::Payload_Receiver_ptr payload_receiver
,
13 CORBA::Long event_count
,
14 CORBA::ULong event_size
,
16 Messaging::SyncScope sync_scope
,
17 const ACE_CString
& ident
)
18 : ACE_Task_Base (thr_mgr
)
19 , payload_receiver_ (Test::Payload_Receiver::_duplicate (payload_receiver
))
20 , event_count_ (event_count
)
21 , event_size_ (event_size
)
22 , orb_ (CORBA::ORB::_duplicate (orb
))
23 , sync_scope_ (sync_scope
)
31 Client_Task::done() const
33 if (tasks_running_
== 0)
41 Client_Task::ID () const
50 if (TAO_debug_level
> 0)
52 ACE_DEBUG ((LM_DEBUG
,"(%P|%t) Client_Task %s started\n", this->ID ()));
54 Test::Payload
payload (this->event_size_
);
55 payload
.length (this->event_size_
);
57 for (CORBA::ULong j
= 0; j
!= payload
.length (); ++j
)
59 payload
[j
] = (j
% 256);
64 this->validate_connection ();
66 CORBA::Object_var object
=
67 this->orb_
->resolve_initial_references ("PolicyCurrent");
68 CORBA::PolicyCurrent_var policy_current
=
69 CORBA::PolicyCurrent::_narrow (object
.in ());
71 CORBA::Any scope_as_any
;
72 scope_as_any
<<= this->sync_scope_
;
74 CORBA::PolicyList
policy_list (1);
75 policy_list
.length (1);
77 this->orb_
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
80 policy_current
->set_policy_overrides (policy_list
,
83 if (TAO_debug_level
> 0)
85 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Client_Task %s sending %d payloads.\n",
86 this->ID (), this->event_count_
));
88 int transient_count
= 0;
89 for (int i
= 0; i
!= this->event_count_
; ++i
)
93 this->payload_receiver_
->more_data (payload
, this->sync_scope_
!= Messaging::SYNC_WITH_TARGET
);
96 catch (const CORBA::TRANSIENT
&)
98 if (++transient_count
< TRANSIENT_LIMIT
)
100 if (transient_count
== TRANSIENT_LIMIT
/ 2)
102 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Client_Task %s large TRANSIENTS encountered at payload %d/%d.\n",
103 this->ID (), i
+1, this->event_count_
));
105 ACE_OS::sleep (TRANSIENT_HOLDOFF
);
106 --i
; // Re-try the same message
110 break; // Abort the message sending.
115 catch (const CORBA::Exception
& ex
)
117 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Client_Task %s: ", this->ID ()));
118 ex
._tao_print_exception ("CORBA Exception caught:");
125 ACE_DEBUG ((LM_DEBUG
, "(%P) Unknown exception caught\n"));
131 if (TAO_debug_level
> 0)
133 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Client_Task %s finished.\n", this->ID ()));
141 Client_Task::validate_connection ()
145 int transient_count
= 0;
146 Test::Payload
payload(0);
147 for (int i
= 0; i
!= 100; ++i
)
151 this->payload_receiver_
->ping();
154 catch (const CORBA::TRANSIENT
&)
156 if (++transient_count
< TRANSIENT_LIMIT
)
158 if (transient_count
== TRANSIENT_LIMIT
/ 2)
160 ACE_DEBUG ((LM_DEBUG
,
161 "(%P|%t) Client Task %s large TRANSIENTS encountered at validation %d%%.\n",
164 ACE_OS::sleep (TRANSIENT_HOLDOFF
);
165 --i
; // Re-try the same message
169 break; // Abort the message sending.
174 catch (const CORBA::Exception
&)
176 // Deliberatly ignores any other corba exceptions