4 Session::Session (Test::Session_Control_ptr control
,
5 CORBA::ULong payload_size
,
6 CORBA::ULong thread_count
,
7 CORBA::ULong message_count
,
8 CORBA::ULong peer_count
)
9 : control_ (Test::Session_Control::_duplicate (control
))
11 , payload_size_ (payload_size
)
12 , thread_count_ (thread_count
)
13 , message_count_ (message_count
)
14 , active_thread_count_ (0)
15 , expected_messages_ (thread_count
* message_count
* (peer_count
- 1))
17 , barrier_ (thread_count
+ 1)
21 Session::~Session (void)
28 this->barrier_
.wait ();
30 /// Automatically decrease the reference count at the end of the
32 PortableServer::ServantBase_var
auto_decrement (this);
37 // Use the same payload over and over
38 Test::Payload
payload (this->payload_size_
);
39 payload
.length (this->payload_size_
);
41 // Get the number of peers just once.
42 CORBA::ULong session_count
=
43 this->other_sessions_
.length ();
45 for (; i
!= this->message_count_
; ++i
)
51 "(%P|%t) Session::svc, "
52 "sending message %d\n",
56 for (CORBA::ULong j
= 0; j
!= session_count
; ++j
)
58 Test::Payload_var received
=
59 this->other_sessions_
[j
]->echo_payload (payload
);
64 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
, ace_mon
, this->mutex_
, -1);
65 this->active_thread_count_
--;
66 if (this->more_work ())
73 catch (const CORBA::Exception
& ex
)
76 "(%P|%t) ERROR: Session::svc, "
77 "send %d messages out of %d\n",
79 ex
._tao_print_exception ("Session::svc - ");
87 Session::start (const Test::Session_List
&other_sessions
)
89 if (other_sessions
.length () == 0)
90 throw Test::No_Peers ();
93 ACE_GUARD (TAO_SYNCH_MUTEX
, ace_mon
, this->mutex_
);
95 throw Test::Already_Running ();
97 this->other_sessions_
= other_sessions
;
99 for (CORBA::ULong i
= 0; i
!= this->thread_count_
; ++i
)
101 // Increase the reference count because the new thread will have
102 // access to this object....
107 if (this->task_
.activate (
108 THR_NEW_LWP
| THR_JOINABLE
, 1, 1) == -1)
110 this->_remove_ref ();
115 this->active_thread_count_
++;
118 catch (const CORBA::Exception
& ex
)
120 ex
._tao_print_exception ("Session::start, ignored");
124 if (this->active_thread_count_
!= this->thread_count_
)
128 this->validate_connections ();
130 this->barrier_
.wait ();
132 if (this->running_
!= 0)
135 /// None of the threads are running, this session is useless at
136 /// this point, report the problem and destroy the local objects
141 Session::echo_payload (const Test::Payload
&the_payload
)
143 if (the_payload
.length () != this->payload_size_
)
145 ACE_ERROR ((LM_ERROR
,
146 "ERROR: (%P|%t) Session::echo_payload, "
147 "unexpected payload size (%d != %d)\n",
148 the_payload
.length (), this->payload_size_
));
151 Test::Payload_var
retval (new Test::Payload (the_payload
));
154 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
, ace_mon
, this->mutex_
,
156 this->expected_messages_
--;
160 verbose
= this->expected_messages_
% 500 == 0;
161 if (this->expected_messages_
< 500)
162 verbose
= (this->expected_messages_
% 100 == 0);
163 if (this->expected_messages_
< 100)
164 verbose
= (this->expected_messages_
% 10 == 0);
166 if (this->expected_messages_
< 5)
171 ACE_DEBUG ((LM_DEBUG
,
172 "(%P|%t) Session::echo_payload, "
173 "%d messages to go\n",
174 this->expected_messages_
));
176 if (this->more_work ())
177 return retval
._retn ();
181 return retval
._retn ();
186 Session::destroy (void)
188 // Make sure local resources are released
190 PortableServer::POA_var poa
=
191 this->_default_POA ();
192 PortableServer::ObjectId_var oid
=
193 poa
->servant_to_id (this);
194 poa
->deactivate_object (oid
.in ());
198 Session::more_work (void) const
200 if (this->expected_messages_
> 0
201 || this->active_thread_count_
> 0
202 || this->running_
== 0)
209 Session::validate_connections (void)
211 const CORBA::ULong session_count
=
212 this->other_sessions_
.length ();
213 for (CORBA::ULong j
= 0; j
!= session_count
; ++j
)
217 #if (TAO_HAS_CORBA_MESSAGING == 1)
218 CORBA::PolicyList_var unused
;
219 this->other_sessions_
[j
]->_validate_connection (unused
);
221 (void) this->other_sessions_
[j
]->_is_a ("Not_An_IDL_Type");
222 #endif /* TAO_HAS_MESSAGING == 1 */
224 catch (const CORBA::Exception
&)
231 Session::terminate (CORBA::Boolean success
)
233 // Make sure that global resources are released
236 this->control_
->session_finished (success
);
238 catch (const CORBA::Exception
& ex
)
240 ex
._tao_print_exception ("Session::terminate, ignored");