diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/actors/interconnect/slowpoke_actor.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/actors/interconnect/slowpoke_actor.h')
-rw-r--r-- | library/cpp/actors/interconnect/slowpoke_actor.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/library/cpp/actors/interconnect/slowpoke_actor.h b/library/cpp/actors/interconnect/slowpoke_actor.h new file mode 100644 index 0000000000..4b02e5da48 --- /dev/null +++ b/library/cpp/actors/interconnect/slowpoke_actor.h @@ -0,0 +1,47 @@ +#pragma once + +#include <library/cpp/actors/core/actor_bootstrapped.h> + +namespace NActors { + + class TSlowpokeActor : public TActorBootstrapped<TSlowpokeActor> { + const TDuration Duration; + const TDuration SleepMin; + const TDuration SleepMax; + const TDuration RescheduleMin; + const TDuration RescheduleMax; + + public: + static constexpr NKikimrServices::TActivity::EType ActorActivityType() { + return NKikimrServices::TActivity::INTERCONNECT_COMMON; + } + + TSlowpokeActor(TDuration duration, TDuration sleepMin, TDuration sleepMax, TDuration rescheduleMin, TDuration rescheduleMax) + : Duration(duration) + , SleepMin(sleepMin) + , SleepMax(sleepMax) + , RescheduleMin(rescheduleMin) + , RescheduleMax(rescheduleMax) + {} + + void Bootstrap(const TActorContext& ctx) { + Become(&TThis::StateFunc, ctx, Duration, new TEvents::TEvPoisonPill); + HandleWakeup(ctx); + } + + void HandleWakeup(const TActorContext& ctx) { + Sleep(RandomDuration(SleepMin, SleepMax)); + ctx.Schedule(RandomDuration(RescheduleMin, RescheduleMax), new TEvents::TEvWakeup); + } + + static TDuration RandomDuration(TDuration min, TDuration max) { + return min + TDuration::FromValue(RandomNumber<ui64>(max.GetValue() - min.GetValue() + 1)); + } + + STRICT_STFUNC(StateFunc, + CFunc(TEvents::TSystem::PoisonPill, Die) + CFunc(TEvents::TSystem::Wakeup, HandleWakeup) + ) + }; + +} // NActors |