Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / CSD_Strategy_Tests / TP_Common / ClientTask.cpp
blob5f8ac3afd2995cb05dab67290f5326c6e6b081b2
1 #include "ClientTask.h"
2 #include "ClientEngine.h"
3 #include "AppShutdown.h"
4 #include "ace/SString.h"
7 ClientTask::ClientTask(bool shutdown_after_done)
8 : shutdown_after_done_(shutdown_after_done),
9 failure_count_(0)
14 ClientTask::~ClientTask()
19 void
20 ClientTask::add_engine(ClientEngine* engine)
22 // Pass in false so that _add_ref() is called.
23 ClientEngine_Handle engine_handle(engine,false);
24 this->engines_.push_back(engine_handle);
28 int
29 ClientTask::open(void*)
31 size_t num_threads = this->engines_.size();
33 if (num_threads == 0)
35 ACE_ERROR_RETURN((LM_ERROR,
36 "(%P|%t) ClientTask cannot activate 0 threads.\n"),
37 -1);
40 if (this->activate(THR_NEW_LWP | THR_JOINABLE, num_threads) != 0)
42 // Assumes that when activate returns non-zero return code that
43 // no threads were activated.
44 ACE_ERROR_RETURN((LM_ERROR,
45 "(%P|%t) ClientTask failed to activate "
46 "the %d client threads.\n", num_threads),
47 -1);
50 return 0;
54 int
55 ClientTask::svc()
57 ClientEngine_Handle engine;
60 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0);
61 this->engines_.get(engine, this->engines_.size() - 1);
62 this->engines_.pop_back();
65 try
67 bool exec_ret = engine->execute();
68 if (exec_ret == false)
70 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0);
71 this->failure_count_ ++;
74 catch (const CORBA::Exception& ex)
76 ex._tao_print_exception (
77 "ClientTask::svc Caught exception from execute():");
79 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0);
80 this->failure_count_ ++;
82 catch (...)
84 ACE_ERROR((LM_ERROR,
85 "(%P|%t) ClientTask::svc caught unknown (...) exception "\
86 "in execute() " ));
87 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0);
88 this->failure_count_ ++;
91 if(this->shutdown_after_done_)
93 // This is used to shutdown orb for a client application
94 // with an orb running.
95 TheAppShutdown->client_done ();
98 return 0;
102 ClientTask::close(u_long)
104 return 0;
107 unsigned
108 ClientTask::failure_count () const
110 return this->failure_count_;