127using TEvent = std::pair<unsigned, TTime>;
147 using TPtr = std::unique_ptr<TActorContext>;
189 template<
typename T,
typename... Args>
203 template<
typename T,
typename... Args>
226 template<
typename T,
typename... Args>
233 void Cancel(TEvent event);
261 template<
typename Rep,
typename Period>
281 template<
typename T,
typename TQuestion>
293 : ActorSystem_(actorSystem)
300 TLocalActorId ActorId_;
310 static void*
operator new(
size_t size,
TActorSystem* actorSystem);
311 static void operator delete(
void* ptr);
317 , ActorSystem(actorSystem)
353 using TPtr = std::unique_ptr<IActor>;
369 virtual void Receive(TMessageId messageId,
TBlob blob, TActorContext::TPtr ctx) = 0;
401 void Receive(TMessageId messageId,
TBlob blob, TActorContext::TPtr ctx)
override;
436 virtual void Receive(TMessageId messageId,
TBlob blob, TActorContext::TPtr ctx) = 0;
470template<
typename TBaseBehavior,
typename... TMessages>
483 void Receive(TMessageId messageId,
TBlob blob, TActorContext::TPtr ctx)
override {
484 bool handled = (TryHandleMessage<TMessages>(
491 static_cast<TBaseBehavior*
>(
this)->HandleUnknownMessage(messageId, std::move(blob), std::move(ctx));
496 template<
typename TMessage>
497 bool TryHandleMessage(TMessageId messageId,
TBlob& blob, TActorContext::TPtr& ctx) {
498 if (TMessage::MessageId == messageId) {
500 auto&& mes = DeserializeNear<TMessage>(blob);
501 HandleMessage<TMessage>(
507 auto&& mes = DeserializeFar<TMessage>(blob);
508 HandleMessage<TMessage>(
519 template<
typename TMessage>
520 void HandleMessage(TMessage&& message, TBlob blob, TActorContext::TPtr ctx)
522 using ReturnType =
decltype(
static_cast<TBaseBehavior*
>(
this)->
Receive(
523 std::declval<TMessage>(),
524 std::declval<TBlob>(),
525 std::declval<TActorContext::TPtr>()
528 if constexpr (std::is_same_v<ReturnType, void>) {
529 static_cast<TBaseBehavior*
>(
this)->
Receive(
535 auto async = ctx->StartAsync();
536 auto future =
static_cast<TBaseBehavior*
>(
this)->
Receive(
541 if (!future.done()) {
542 async.Commit(std::move(future));
598 CurrentBehavior_ = behavior;
607 void Receive(TMessageId messageId,
TBlob blob, TActorContext::TPtr ctx)
override {
608 CurrentBehavior_->
Receive(messageId, std::move(blob), std::move(ctx));
Base interface for all actors in the system.
Definition actor.hpp:351
virtual void Receive(TMessageId messageId, TBlob blob, TActorContext::TPtr ctx)=0
Process an incoming message.
Actor that delegates message handling to a pluggable behavior.
Definition actor.hpp:586
void Receive(TMessageId messageId, TBlob blob, TActorContext::TPtr ctx) override
Delegate message handling to the current behavior.
Definition actor.hpp:607
void Become(IBehavior *behavior)
Switch to a new behavior.
Definition actor.hpp:597
Base interface for actor behaviors.
Definition actor.hpp:426
virtual void Receive(TMessageId messageId, TBlob blob, TActorContext::TPtr ctx)=0
Process an incoming message according to this behavior.
Coroutine-based actor interface for asynchronous message processing.
Definition actor.hpp:393
void Receive(TMessageId messageId, TBlob blob, TActorContext::TPtr ctx) override
IActor bridge — invokes CoReceive and parks pending futures.
Definition actor.cpp:7
virtual TFuture< void > CoReceive(TMessageId messageId, TBlob blob, TActorContext::TPtr ctx)=0
Asynchronous message handler (override in subclass)
Context object providing actor communication and scheduling capabilities.
Definition actor.hpp:145
TActorId Self() const
Get this actor's ID.
Definition actor.hpp:155
void Forward(TActorId to, TMessageId messageId, TBlob blob)
Forward a message to another actor (preserves original sender)
Definition actorsystem.cpp:21
TFuture< void > Sleep(TTime until)
Suspend the current handler until a specific time.
Definition actorsystem.hpp:478
TFuture< T > Ask(TActorId recipient, TQuestion &&question)
Send a request and suspend until a reply of type T arrives.
Definition actorsystem.hpp:488
void Cancel(TEvent event)
Cancel a previously scheduled message.
Definition actorsystem.cpp:31
void Send(TActorId to, TMessageId messageId, TBlob blob)
Send a message to another actor.
Definition actorsystem.cpp:16
TAsync StartAsync()
Start an asynchronous operation context.
Definition actor.cpp:16
TEvent Schedule(TTime when, TActorId sender, TActorId recipient, TMessageId messageId, TBlob blob)
Schedule a message to be delivered at a specific time.
Definition actorsystem.cpp:26
TActorId Sender() const
Get the sender of the current message.
Definition actor.hpp:150
Globally unique identifier for actors across a distributed system.
Definition actorid.hpp:29
Single-threaded actor runtime.
Definition actorsystem.hpp:99
Template for type-safe behavior implementations.
Definition actor.hpp:472
void Receive(TMessageId messageId, TBlob blob, TActorContext::TPtr ctx) override
Process incoming message with automatic type dispatch.
Definition actor.hpp:483
Message envelope containing routing and payload information.
Definition actor.hpp:119
TActorId Recipient
Actor that should receive the message.
Definition actor.hpp:122
TBlob Blob
Serialized message data.
Definition actor.hpp:124
TActorId Sender
Actor that sent the message.
Definition actor.hpp:121
TMessageId MessageId
Type identifier of the message.
Definition actor.hpp:123
Mock actor context for testing purposes.
Definition actor.hpp:334
Implementation of a promise/future system for coroutines.
Helper class for managing asynchronous operations in actors.
Definition actor.hpp:291
Opaque message payload with Near/Far duality.
Definition messages.hpp:99
@ Near
Live object pointer — valid only within the same process.
Owned coroutine handle that carries a result of type T.
Definition corochain.hpp:185