Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Client_Leaks / Client_Task.cpp
blobb49b07b1c75f16bddf72f048b51ece41eae5b898
2 #include "Client_Task.h"
4 Client_Task::Client_Task (Test::Process_Factory_ptr process_factory,
5 int iterations)
6 : process_factory_ (Test::Process_Factory::_duplicate (process_factory))
7 , iterations_ (iterations)
8 , successful_calls_ (0)
12 int
13 Client_Task::successful_calls () const
15 return this->successful_calls_;
18 int
19 Client_Task::svc ()
21 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Starting client task\n"));
23 int successful_calls = 0;
25 try
27 this->validate_connection ();
29 for (int i = 0; i != this->iterations_; ++i)
31 int retval = this->one_iteration ();
33 if (retval != 0)
34 successful_calls++;
36 if (i % 10 == 0)
38 ACE_DEBUG ((LM_DEBUG,
39 "(%P|%t) - Client_Task::svc %d / %d iterations\n",
40 i, this->iterations_));
44 catch (const CORBA::Exception& ex)
46 ex._tao_print_exception ("Exception caught:");
47 return -1;
49 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Client task finished\n"));
51 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
52 this->successful_calls_ += successful_calls;
54 return 0;
57 void
58 Client_Task::validate_connection ()
60 try
62 for (int i = 0; i != 100; ++i)
64 (void) this->process_factory_->noop ();
67 catch (const CORBA::TRANSIENT& )
69 // Ignore transient exceptions
73 int
74 Client_Task::one_iteration ()
76 try
78 Test::Process_var process =
79 this->process_factory_->create_new_process ();
81 (void) process->get_process_id ();
83 process->shutdown ();
85 return 1;
87 catch (const Test::Spawn_Failed& )
89 // Ignore this exception, it is usually caused by a transient
90 // condition
92 catch (const CORBA::Exception& ex)
94 ex._tao_print_exception ("Exception caught:");
97 return 0;