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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
// **********************************************************************
//
// Copyright (c) 2002
// ZeroC, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#include <Glacier/Missive.h>
using namespace std;
using namespace Ice;
using namespace Glacier;
Glacier::Missive::Missive(const ObjectPrx& proxy, const vector<Byte>& inParams, const Current& current,
bool forwardContext) :
_proxy(proxy),
_inParams(inParams),
_current(current),
_forwardContext(forwardContext)
{
Context::const_iterator p = current.ctx.find("_ovrd");
if(p != current.ctx.end())
{
_override = p->second;
}
}
void
Glacier::Missive::invoke()
{
std::vector<Byte> dummy;
if(_forwardContext)
{
_proxy->ice_invoke(_current.operation, _current.mode, _inParams, dummy, _current.ctx);
}
else
{
_proxy->ice_invoke(_current.operation, _current.mode, _inParams, dummy);
}
}
bool
Glacier::Missive::override(const MissivePtr& other)
{
if(_override.empty() || other->_override.empty())
{
return false;
}
return _override == other->_override;
}
const ObjectPrx&
Glacier::Missive::getProxy() const
{
return _proxy;
}
const Current&
Glacier::Missive::getCurrent() const
{
return _current;
}
Glacier::MissiveQueue::MissiveQueue(const Ice::CommunicatorPtr& communicator, int traceLevel, bool reverse,
const IceUtil::Time& sleepTime) :
_communicator(communicator),
_logger(communicator->getLogger()),
_traceLevel(traceLevel),
_reverse(reverse),
_sleepTime(sleepTime),
_destroy(false)
{
}
Glacier::MissiveQueue::~MissiveQueue()
{
assert(_destroy);
assert(_missives.empty());
assert(!_communicator);
}
void
Glacier::MissiveQueue::destroy()
{
IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
_destroy = true;
_missives.clear();
_communicator = 0;
_logger = 0;
notify();
}
void
Glacier::MissiveQueue::add(const MissivePtr& missive)
{
assert(missive);
IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
assert(!_destroy);
if(_missives.empty())
{
notify();
}
for(std::vector<MissivePtr>::iterator p = _missives.begin(); p != _missives.end(); ++p)
{
if(missive->override(*p))
{
*p = missive; // Replace old missive if this is an override.
return;
}
}
_missives.push_back(missive); // No override, add new missive.
}
void
Glacier::MissiveQueue::run()
{
while(true)
{
vector<ObjectPrx> proxies;
{
IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
while(!_destroy && _missives.empty())
{
wait();
}
if(_destroy)
{
return;
}
proxies.reserve(_missives.size());
vector<MissivePtr>::const_iterator p;
for(p = _missives.begin(); p != _missives.end(); ++p)
{
try
{
const ObjectPrx& proxy = (*p)->getProxy();
const Current& current = (*p)->getCurrent();
if(_traceLevel >= 2)
{
Trace out(_logger, "Glacier");
if(_reverse)
{
out << "reverse ";
}
out << "batch routing to:\n"
<< "proxy = " << _communicator->proxyToString(proxy) << '\n'
<< "operation = " << current.operation << '\n'
<< "mode = " << current.mode;
}
(*p)->invoke();
proxies.push_back(proxy);
}
catch(const Ice::Exception& ex)
{
if(_traceLevel >= 1)
{
Trace out(_logger, "Glacier");
if(_reverse)
{
out << "reverse ";
}
out << "batch routing exception:\n" << ex;
}
}
}
_missives.clear();
}
//
// Flush and sleep outside the thread synchronization, so that
// new messages can be added to this missive queue while this
// thread sends a batch and sleeps.
//
try
{
//
// This sends all batched missives.
//
// sort(proxies.begin(), proxies.end());
// proxies.erase(unique(proxies.begin(), proxies.end()), proxies.end());
vector<ObjectPrx>::const_iterator p;
for(p = proxies.begin(); p != proxies.end(); ++p)
{
(*p)->ice_flush();
}
//
// In order to avoid flooding the missive receivers, we add
// a delay between sending missives.
//
if(_sleepTime > IceUtil::Time())
{
IceUtil::ThreadControl::sleep(_sleepTime);
}
}
catch(const Ice::Exception& ex)
{
IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
if(_traceLevel >= 1)
{
Trace out(_logger, "Glacier");
if(_reverse)
{
out << "reverse ";
}
out << "batch routing exception:\n" << ex;
}
}
}
}
|