blob: 136d711309fb87c00e534880b075412108cfa35c (
plain) (
blame)
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "staticthrottlepolicy.h"
#include "message.h"
namespace mbus {
StaticThrottlePolicy::StaticThrottlePolicy() :
_maxPendingCount(0),
_maxPendingSize(0),
_pendingSize(0)
{ }
uint32_t
StaticThrottlePolicy::getMaxPendingCount() const
{
return _maxPendingCount;
}
StaticThrottlePolicy &
StaticThrottlePolicy::setMaxPendingCount(uint32_t maxCount)
{
_maxPendingCount = maxCount;
return *this;
}
uint64_t
StaticThrottlePolicy::getMaxPendingSize() const
{
return _maxPendingSize;
}
StaticThrottlePolicy &
StaticThrottlePolicy::setMaxPendingSize(uint64_t maxSize)
{
_maxPendingSize = maxSize;
return *this;
}
uint64_t
StaticThrottlePolicy::getPendingSize() const
{
return _pendingSize;
}
bool
StaticThrottlePolicy::canSend(const Message &msg, uint32_t pendingCount)
{
if (_maxPendingCount > 0 && pendingCount >= _maxPendingCount) {
return false;
}
if (_maxPendingSize > 0 && _pendingSize >= _maxPendingSize) {
return false;
}
(void)msg;
return true;
}
void
StaticThrottlePolicy::processMessage(Message &msg)
{
uint32_t size = msg.getApproxSize();
msg.setContext(Context((uint64_t)size));
_pendingSize += size;
}
void
StaticThrottlePolicy::processReply(Reply &reply)
{
uint32_t size = reply.getContext().value.UINT64;
_pendingSize -= size;
}
} // namespace mbus
|