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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
// $Id$
#include "Peer_i.h"
#if !defined(__ACE_INLINE__)
#include "Peer_i.i"
#endif /* __ACE_INLINE__ */
ACE_RCSID(FL_Callback, Peer_i, "$Id$")
Peer_Handler_i::Peer_Handler_i (Peer_i *peer)
: peer_ (peer)
{
}
void
Peer_Handler_i::request (CORBA::Long retval,
CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException))
{
static int i = 0;
i++;
if (i % 100 == 0)
ACE_DEBUG ((LM_DEBUG, "(%P|%t) %d replies received\n", i));
this->peer_->reply (retval, ACE_TRY_ENV);
}
void
Peer_Handler_i::request_excep (
AMI_PeerExceptionHolder * excep_holder,
CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException))
{
ACE_UNUSED_ARG (excep_holder);
ACE_UNUSED_ARG (ACE_TRY_ENV);
}
void
Peer_Handler_i::start (CORBA::Environment &)
ACE_THROW_SPEC ((CORBA::SystemException))
{
}
void
Peer_Handler_i::shutdown (CORBA::Environment &)
ACE_THROW_SPEC ((CORBA::SystemException))
{
}
Peer_i::Peer_i (void)
: reply_handler_ (this)
{
}
Peer_i::~Peer_i (void)
{
}
void
Peer_i::init (CORBA::ORB_ptr orb,
Progress_ptr progress,
const ACE_Time_Value &delay,
CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException))
{
this->orb_ = CORBA::ORB::_duplicate (orb);
this->progress_ = Progress::_duplicate (progress);
this->delay_ = delay;
Peer_var peer = this->_this (ACE_TRY_ENV);
ACE_CHECK;
ACE_DEBUG ((LM_DEBUG, "Peer (%P|%t) - binding\n"));
this->id_ = this->progress_->bind (peer.in (), ACE_TRY_ENV);
ACE_CHECK;
}
void
Peer_i::reply (CORBA::Long result,
CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException))
{
this->progress_->recv_reply (result, ACE_TRY_ENV);
}
CORBA::Long
Peer_i::request (CORBA::Long id,
CORBA::Environment &)
ACE_THROW_SPEC ((CORBA::SystemException))
{
ACE_Time_Value tv = this->delay_;
ACE_OS::sleep (tv);
return id;
}
void
Peer_i::start (const PeerSet &the_peers,
CORBA::Long iterations,
CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException))
{
AMI_PeerHandler_var handler =
this->reply_handler_._this (ACE_TRY_ENV);
ACE_CHECK;
// @@ Report errors as exceptions...
Peer_Task *task;
ACE_NEW (task, Peer_Task (the_peers,
iterations,
this->progress_.in (),
handler.in (),
this->id_));
task->activate ();
}
void
Peer_i::shutdown (CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException))
{
this->orb_->shutdown (0, ACE_TRY_ENV);
}
// ****************************************************************
Peer_Task::Peer_Task (const PeerSet& the_peers,
CORBA::Long iterations,
Progress_ptr progress,
AMI_PeerHandler_ptr handler,
CORBA::Long id)
: the_peers_ (the_peers),
iterations_ (iterations),
progress_ (Progress::_duplicate (progress)),
handler_ (AMI_PeerHandler::_duplicate (handler)),
id_ (id)
{
}
int
Peer_Task::svc (void)
{
for (int i = 0; i != this->iterations_; ++i)
{
CORBA::ULong l = this->the_peers_.length ();
for (CORBA::ULong j = 0; j != l; ++j)
{
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
this->the_peers_[j]->sendc_request (this->handler_.in (),
this->id_,
ACE_TRY_ENV);
ACE_TRY_CHECK;
this->progress_->sent_request (this->id_,
ACE_TRY_ENV);
ACE_TRY_CHECK;
}
ACE_CATCHANY
{
// Ignore exceptions;
}
ACE_ENDTRY;
}
if (i % 100 == 0)
ACE_DEBUG ((LM_DEBUG, "(%P|%t) %d requests sent\n", i));
}
return 0;
}
|