Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Big_Request_Muxing / Client_Task.cpp
blob9846d0ba5d65e2e0eca199856d229329269f550c
2 #include "Client_Task.h"
3 #include "tao/AnyTypeCode/Any.h"
5 namespace
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,
15 CORBA::ORB_ptr orb,
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)
24 , tasks_running_(0)
25 , done_(false)
26 , id_ (ident)
30 bool
31 Client_Task::done() const
33 if (tasks_running_ == 0)
34 return done_;
36 //else
37 return false;
40 const char *
41 Client_Task::ID () const
43 return id_.c_str ();
46 int
47 Client_Task::svc ()
49 ++tasks_running_;
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);
62 try
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);
76 policy_list[0] =
77 this->orb_->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
78 scope_as_any);
80 policy_current->set_policy_overrides (policy_list,
81 CORBA::ADD_OVERRIDE);
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)
91 try
93 this->payload_receiver_->more_data (payload, this->sync_scope_ != Messaging::SYNC_WITH_TARGET);
94 transient_count= 0;
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
108 else
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:");
119 --tasks_running_;
120 done_ = true;
121 return -1;
123 catch (...)
125 ACE_DEBUG ((LM_DEBUG, "(%P) Unknown exception caught\n"));
126 --tasks_running_;
127 done_ = true;
128 return -1;
131 if (TAO_debug_level > 0)
133 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Client_Task %s finished.\n", this->ID ()));
135 --tasks_running_;
136 done_ = true;
137 return 0;
140 void
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();
152 transient_count= 0;
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",
162 this->ID (), i+1));
164 ACE_OS::sleep (TRANSIENT_HOLDOFF);
165 --i; // Re-try the same message
167 else
169 break; // Abort the message sending.
174 catch (const CORBA::Exception &)
176 // Deliberatly ignores any other corba exceptions