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
),
14 ClientTask::~ClientTask()
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
);
29 ClientTask::open(void*)
31 size_t num_threads
= this->engines_
.size();
35 ACE_ERROR_RETURN((LM_ERROR
,
36 "(%P|%t) ClientTask cannot activate 0 threads.\n"),
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
),
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();
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_
++;
85 "(%P|%t) ClientTask::svc caught unknown (...) exception "\
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 ();
102 ClientTask::close(u_long
)
108 ClientTask::failure_count () const
110 return this->failure_count_
;