blob: 0fdb0fab10848a82d519446e7e42b03d7e120905 (
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
|
#pragma once
#include <library/cpp/actors/core/actor.h>
#include <library/cpp/actors/core/events.h>
#include <util/generic/hash_set.h>
namespace NActors {
////////////////////////////////////////////////////////////////////////////
// TActiveActors
// This class helps manage created actors and kill them all on PoisonPill.
////////////////////////////////////////////////////////////////////////////
class TActiveActors : public THashSet<TActorId> {
public:
void Insert(const TActorId &aid) {
bool inserted = insert(aid).second;
Y_VERIFY(inserted);
}
void Insert(const TActiveActors &moreActors) {
for (const auto &aid : moreActors) {
Insert(aid);
}
}
void Erase(const TActorId &aid) {
auto num = erase(aid);
Y_VERIFY(num == 1);
}
size_t KillAndClear(const TActorContext &ctx) {
size_t s = size(); // number of actors managed
for (const auto &x: *this) {
ctx.Send(x, new TEvents::TEvPoisonPill());
}
clear();
return s; // how many actors we killed
}
};
} // NKikimr
|