@@ -284,12 +284,6 @@ namespace NActors {
284284
285285 class TDecorator ;
286286
287- class TActorVirtualBehaviour {
288- public:
289- static void Receive (IActor* actor, std::unique_ptr<IEventHandle> ev);
290- public:
291- };
292-
293287 class TActorCallbackBehaviour {
294288 private:
295289 using TBase = IActor;
@@ -374,18 +368,14 @@ namespace NActors {
374368 friend class TExecutorPoolBaseMailboxed ;
375369 friend class TExecutorThread ;
376370
377- IActor (const ui32 activityType)
378- : SelfActorId(TActorId())
379- , ElapsedTicks(0 )
380- , ActivityType(activityType)
381- , HandledEvents(0 ) {
382- }
371+ public:
372+ using TReceiveFunc = void (IActor::*)(TAutoPtr<IEventHandle>& ev);
373+
374+ private:
375+ TReceiveFunc StateFunc_;
383376
384- protected:
385- TActorCallbackBehaviour CImpl;
386377 public:
387378 using TEventFlags = IEventHandle::TEventFlags;
388- using TReceiveFunc = TActorCallbackBehaviour::TReceiveFunc;
389379 // / @sa services.proto NKikimrServices::TActivity::EType
390380 using EActorActivity = EInternalActorType;
391381 using EActivityType = EActorActivity;
@@ -394,23 +384,39 @@ namespace NActors {
394384 protected:
395385 ui64 HandledEvents;
396386
397- template <typename EEnum = EActivityType, typename std::enable_if<std::is_enum<EEnum>::value, bool >::type v = true >
398- IActor (const EEnum activityEnumType = EActivityType::OTHER)
399- : IActor(TEnumProcessKey<TActorActivityTag, EEnum>::GetIndex(activityEnumType)) {
400- }
401-
402- IActor (TActorCallbackBehaviour&& cImpl, const ui32 activityType)
387+ IActor (TReceiveFunc stateFunc, const ui32 activityType)
403388 : SelfActorId(TActorId())
404389 , ElapsedTicks(0 )
405- , CImpl(std::move(cImpl) )
390+ , StateFunc_(stateFunc )
406391 , ActivityType(activityType)
407392 , HandledEvents(0 )
408393 {
409394 }
410395
411396 template <typename EEnum = EActivityType, typename std::enable_if<std::is_enum<EEnum>::value, bool >::type v = true >
412- IActor (TActorCallbackBehaviour&& cImpl, const EEnum activityEnumType = EActivityType::OTHER)
413- : IActor(std::move(cImpl), TEnumProcessKey<TActorActivityTag, EEnum>::GetIndex(activityEnumType)) {
397+ IActor (TReceiveFunc stateFunc, const EEnum activityEnumType = EActivityType::OTHER)
398+ : IActor(stateFunc, TEnumProcessKey<TActorActivityTag, EEnum>::GetIndex(activityEnumType)) {
399+ }
400+
401+ template <typename T>
402+ void Become (T stateFunc) {
403+ StateFunc_ = static_cast <TReceiveFunc>(stateFunc);
404+ }
405+
406+ template <typename T, typename ... TArgs>
407+ void Become (T stateFunc, TArgs&&... args) {
408+ StateFunc_ = static_cast <TReceiveFunc>(stateFunc);
409+ Schedule (std::forward<TArgs>(args)...);
410+ }
411+
412+ template <typename T, typename ... TArgs>
413+ void Become (T stateFunc, const TActorContext& ctx, TArgs&&... args) {
414+ StateFunc_ = static_cast <TReceiveFunc>(stateFunc);
415+ ctx.Schedule (std::forward<TArgs>(args)...);
416+ }
417+
418+ TReceiveFunc CurrentStateFunc () const {
419+ return StateFunc_;
414420 }
415421
416422 public:
@@ -549,11 +555,7 @@ namespace NActors {
549555#endif
550556 ++HandledEvents;
551557 LastReceiveTimestamp = TActivationContext::Monotonic ();
552- if (CImpl.Initialized ()) {
553- CImpl.Receive (this , ev);
554- } else {
555- TActorVirtualBehaviour::Receive (this , std::unique_ptr<IEventHandle>(ev.Release ()));
556- }
558+ (this ->*StateFunc_)(ev);
557559 }
558560
559561 TActorContext ActorContext () const {
@@ -639,43 +641,11 @@ namespace NActors {
639641 return TLocalProcessKeyState<TActorActivityTag>::GetInstance ().GetNameByIndex (index);
640642 }
641643
642- class IActorCallback : public IActor {
643- protected:
644- template <class TEnum = IActor::EActivityType>
645- IActorCallback (TReceiveFunc stateFunc, const TEnum activityType = IActor::EActivityType::OTHER)
646- : IActor(TActorCallbackBehaviour(stateFunc), activityType) {
647-
648- }
649-
650- IActorCallback (TReceiveFunc stateFunc, const ui32 activityType)
651- : IActor(TActorCallbackBehaviour(stateFunc), activityType) {
652-
653- }
654-
655- public:
656- template <typename T>
657- void Become (T stateFunc) {
658- CImpl.Become (stateFunc);
659- }
660-
661- template <typename T, typename ... TArgs>
662- void Become (T stateFunc, const TActorContext& ctx, TArgs&&... args) {
663- CImpl.Become (stateFunc, ctx, std::forward<TArgs>(args)...);
664- }
665-
666- template <typename T, typename ... TArgs>
667- void Become (T stateFunc, TArgs&&... args) {
668- CImpl.Become (stateFunc);
669- Schedule (std::forward<TArgs>(args)...);
670- }
671-
672- TReceiveFunc CurrentStateFunc () const {
673- return CImpl.CurrentStateFunc ();
674- }
675- };
644+ // For compatibility with existing code
645+ using IActorCallback = IActor;
676646
677647 template <typename TDerived>
678- class TActor : public IActorCallback {
648+ class TActor : public IActor {
679649 private:
680650 using TDerivedReceiveFunc = void (TDerived::*)(TAutoPtr<IEventHandle>& ev);
681651
@@ -729,36 +699,36 @@ namespace NActors {
729699 // UnsafeBecome methods don't verify the bindings of the stateFunc to the TDerived
730700 template <typename T>
731701 void UnsafeBecome (T stateFunc) {
732- this ->IActorCallback ::Become (stateFunc);
702+ this ->IActor ::Become (stateFunc);
733703 }
734704
735705 template <typename T, typename ... TArgs>
736706 void UnsafeBecome (T stateFunc, const TActorContext& ctx, TArgs&&... args) {
737- this ->IActorCallback ::Become (stateFunc, ctx, std::forward<TArgs>(args)...);
707+ this ->IActor ::Become (stateFunc, ctx, std::forward<TArgs>(args)...);
738708 }
739709
740710 template <typename T, typename ... TArgs>
741711 void UnsafeBecome (T stateFunc, TArgs&&... args) {
742- this ->IActorCallback ::Become (stateFunc, std::forward<TArgs>(args)...);
712+ this ->IActor ::Become (stateFunc, std::forward<TArgs>(args)...);
743713 }
744714
745715 template <typename T>
746716 void Become (T stateFunc) {
747717 // TODO(kruall): have to uncomment asserts after end of sync contrib/ydb
748718 // static_assert(std::is_convertible_v<T, TDerivedReceiveFunc>);
749- this ->IActorCallback ::Become (stateFunc);
719+ this ->IActor ::Become (stateFunc);
750720 }
751721
752722 template <typename T, typename ... TArgs>
753723 void Become (T stateFunc, const TActorContext& ctx, TArgs&&... args) {
754724 // static_assert(std::is_convertible_v<T, TDerivedReceiveFunc>);
755- this ->IActorCallback ::Become (stateFunc, ctx, std::forward<TArgs>(args)...);
725+ this ->IActor ::Become (stateFunc, ctx, std::forward<TArgs>(args)...);
756726 }
757727
758728 template <typename T, typename ... TArgs>
759729 void Become (T stateFunc, TArgs&&... args) {
760730 // static_assert(std::is_convertible_v<T, TDerivedReceiveFunc>);
761- this ->IActorCallback ::Become (stateFunc, std::forward<TArgs>(args)...);
731+ this ->IActor ::Become (stateFunc, std::forward<TArgs>(args)...);
762732 }
763733 };
764734
0 commit comments