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
|
#pragma once
namespace NActors {
class TSenderBaseActor: public TActorBootstrapped<TSenderBaseActor> {
protected:
const TActorId RecipientActorId;
const ui32 Preload;
ui64 SequenceNumber = 0;
ui32 InFlySize = 0;
public:
TSenderBaseActor(const TActorId& recipientActorId, ui32 preload = 1)
: RecipientActorId(recipientActorId)
, Preload(preload)
{
}
virtual ~TSenderBaseActor() {
}
virtual void Bootstrap(const TActorContext& ctx) {
Become(&TSenderBaseActor::StateFunc);
ctx.Send(ctx.ExecutorThread.ActorSystem->InterconnectProxy(RecipientActorId.NodeId()), new TEvInterconnect::TEvConnectNode);
}
virtual void SendMessagesIfPossible(const TActorContext& ctx) {
while (InFlySize < Preload) {
SendMessage(ctx);
}
}
virtual void SendMessage(const TActorContext& /*ctx*/) {
++SequenceNumber;
}
virtual void Handle(TEvents::TEvUndelivered::TPtr& /*ev*/, const TActorContext& ctx) {
SendMessage(ctx);
}
virtual void Handle(TEvTestResponse::TPtr& /*ev*/, const TActorContext& ctx) {
SendMessagesIfPossible(ctx);
}
void Handle(TEvInterconnect::TEvNodeConnected::TPtr& /*ev*/, const TActorContext& ctx) {
SendMessagesIfPossible(ctx);
}
void Handle(TEvInterconnect::TEvNodeDisconnected::TPtr& /*ev*/, const TActorContext& /*ctx*/) {
}
virtual void Handle(TEvents::TEvPoisonPill::TPtr& /*ev*/, const TActorContext& ctx) {
Die(ctx);
}
virtual STRICT_STFUNC(StateFunc,
HFunc(TEvTestResponse, Handle)
HFunc(TEvents::TEvUndelivered, Handle)
HFunc(TEvents::TEvPoisonPill, Handle)
HFunc(TEvInterconnect::TEvNodeConnected, Handle)
HFunc(TEvInterconnect::TEvNodeDisconnected, Handle)
)
};
class TReceiverBaseActor: public TActor<TReceiverBaseActor> {
protected:
ui64 ReceivedCount = 0;
public:
TReceiverBaseActor()
: TActor(&TReceiverBaseActor::StateFunc)
{
}
virtual ~TReceiverBaseActor() {
}
virtual STRICT_STFUNC(StateFunc,
HFunc(TEvTest, Handle)
)
virtual void Handle(TEvTest::TPtr& /*ev*/, const TActorContext& /*ctx*/) {}
};
}
|