1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// This may look like C, but it's really -*- C++ -*-
#include "ClientTask.h"
#include "tao/Exception.h"
#include "ace/SString.h"
ClientTask::ClientTask()
: failure_count_(0),
num_loops_(1)
{
}
ClientTask::~ClientTask()
{
}
void
ClientTask::add_engine(ClientEngine* engine)
{
// Pass in false so that _add_ref() is called.
ClientEngine_Handle engine_handle(engine,false);
this->engines_.push_back(engine_handle);
}
void
ClientTask::num_loops(unsigned num_loops)
{
this->num_loops_ = num_loops;
}
int
ClientTask::open(void*)
{
size_t const num_threads = this->engines_.size();
if (num_threads == 0)
{
ACE_ERROR_RETURN((LM_ERROR,
"(%P|%t) ClientTask cannot activate 0 threads.\n"),
-1);
}
if (this->activate(THR_NEW_LWP | THR_JOINABLE, num_threads) != 0)
{
// Assumes that when activate returns non-zero return code that
// no threads were activated.
ACE_ERROR_RETURN((LM_ERROR,
"(%P|%t) ClientTask failed to activate "
"the %d client threads.\n", num_threads),
-1);
}
return 0;
}
int
ClientTask::svc()
{
ClientEngine_Handle engine;
unsigned num_loops;
{
ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
this->engines_.get(engine, this->engines_.size() - 1);
this->engines_.pop_back();
num_loops = this->num_loops_;
}
try
{
if (engine->execute(num_loops) == false)
{
ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
++this->failure_count_;
}
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception (
"ClientTask::svc Caught exception from execute():");
ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
++this->failure_count_ ;
}
catch (...)
{
ACE_ERROR((LM_ERROR,
"(%P|%t) ClientTask::svc caught unknown (...) exception "\
"in execute() " ));
ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
++this->failure_count_;
}
return 0;
}
int
ClientTask::close(u_long)
{
return 0;
}
unsigned
ClientTask::failure_count() const
{
return this->failure_count_;
}
|