COROIO: NNet::NActors::IActorRuntime Class Reference
COROIO
Loading...
Searching...
No Matches
NNet::NActors::IActorRuntime Class Referenceabstract

What a handler runs on: TActorSystem, or one loop of an engine that has several. More...

#include <actor.hpp>

Inheritance diagram for NNet::NActors::IActorRuntime:
NNet::NActors::TActorSystem

Public Member Functions

virtual void Send (TActorId sender, TActorId recipient, TMessageId messageId, TBlob blob)=0
 Low-level send with a pre-serialized blob. Prefer the typed Send<T> overload.
template<typename T, typename... Args>
void Send (TActorId sender, TActorId recipient, Args &&... args)
 Sends a typed message from sender to recipient (non-blocking).
virtual TEvent Schedule (TTime when, TActorId sender, TActorId recipient, TMessageId messageId, TBlob blob)=0
 Low-level schedule with a pre-serialized blob. Prefer the typed Schedule<T> overload.
template<typename T, typename... Args>
TEvent Schedule (TTime when, TActorId sender, TActorId recipient, Args &&... args)
 Schedules a typed message to be delivered at when.
virtual void Cancel (TEvent event)=0
 Cancels a previously scheduled message.
virtual TActorId Register (IActor::TPtr actor)=0
 Registers an actor and returns its system-wide ID.
template<typename T, typename TQuestion>
auto Ask (TActorId recepient, TQuestion &&message)
 Sends a request and returns an awaitable for the reply of type T.
auto Sleep (TTime until)
 Suspends the current coroutine until until. Delegates to the poller.
template<typename Rep, typename Period>
auto Sleep (std::chrono::duration< Rep, Period > duration)
 Suspends the current coroutine for duration. Delegates to the poller.
std::unique_ptr< INotifier > CreateNotifier ()
 Creates a notifier on the poller thread. The poller must outlive it.

Protected Member Functions

 IActorRuntime (TPollerBase *poller, TNodeId nodeId)
TActorContext::TPtr MakeContext (TActorId sender, TActorId self)

Protected Attributes

TPollerBase * Poller
TNodeId NodeId_

Friends

class TActorContext

Detailed Description

What a handler runs on: TActorSystem, or one loop of an engine that has several.

TActorContext reaches its engine only through this class. An engine implements the blob-level virtual methods; the typed Send<T>, Schedule<T> and Ask<T> are written here once on top of them. The poller and the arena of the contexts belong to the loop, so Sleep, CreateNotifier and freeing a context need no virtual call.

Member Function Documentation

◆ Ask()

template<typename T, typename TQuestion>
auto NNet::NActors::IActorRuntime::Ask ( TActorId recepient,
TQuestion && message )
inline

Sends a request and returns an awaitable for the reply of type T.

Registers a temporary one-shot actor that captures the reply and self-destructs via TPoison. Must be co_await-ed inside ICoroActor::CoReceive or an async TBehavior::Receive.

Template Parameters
TExpected reply message type.
TQuestionRequest message type.
Parameters
recepientActor to send the question to.
messageRequest message forwarded to Send.
Returns
Awaitable that resolves to T when the reply arrives.
auto reply = co_await sys.Ask<Pong>(pingActor, Ping{});

◆ Cancel()

virtual void NNet::NActors::IActorRuntime::Cancel ( TEvent event)
pure virtual

Cancels a previously scheduled message.

Safe to call even if the message has already been delivered.

Parameters
eventHandle returned by Schedule().

Implemented in NNet::NActors::TActorSystem.

◆ MakeContext()

TActorContext::TPtr NNet::NActors::IActorRuntime::MakeContext ( TActorId sender,
TActorId self )
inlineprotected

The context of a handler that runs here. Inline: called for every message, so out of line it would add a function call to every receive.

◆ Register()

virtual TActorId NNet::NActors::IActorRuntime::Register ( IActor::TPtr actor)
pure virtual

Registers an actor and returns its system-wide ID.

Takes ownership of the actor. The returned TActorId is valid until TPoison is delivered or the system is destroyed. Slots are reused with a bumped cookie to prevent stale delivery.

Parameters
actorUnique pointer to the actor (ownership transferred).
Returns
Globally unique ID for this actor.

Implemented in NNet::NActors::TActorSystem.

◆ Schedule() [1/2]

template<typename T, typename... Args>
TEvent NNet::NActors::IActorRuntime::Schedule ( TTime when,
TActorId sender,
TActorId recipient,
Args &&... args )
inline

Schedules a typed message to be delivered at when.

Parameters
whenAbsolute time point for delivery.
senderActor ID for the scheduled message.
recipientDestination actor ID.
argsConstructor arguments forwarded to T.
Returns
Event handle — pass to Cancel() to abort before delivery.

◆ Schedule() [2/2]

virtual TEvent NNet::NActors::IActorRuntime::Schedule ( TTime when,
TActorId sender,
TActorId recipient,
TMessageId messageId,
TBlob blob )
pure virtual

Low-level schedule with a pre-serialized blob. Prefer the typed Schedule<T> overload.

Implemented in NNet::NActors::TActorSystem.

◆ Send() [1/2]

template<typename T, typename... Args>
void NNet::NActors::IActorRuntime::Send ( TActorId sender,
TActorId recipient,
Args &&... args )
inline

Sends a typed message from sender to recipient (non-blocking).

Routes automatically: local actors receive via their mailbox; remote actors (different NodeId) are serialized and queued to the outbound node buffer. Delivery happens on the next event-loop iteration.

Template Parameters
TMessage type; must have static TMessageId MessageId. If it declares using LocalMessage = ...; it is never serialized for the wire and sending it to another node is dropped (logged).
Parameters
senderActor ID that appears as ctx->Sender() in the handler.
recipientDestination actor ID.
argsConstructor arguments forwarded to T.

◆ Send() [2/2]

virtual void NNet::NActors::IActorRuntime::Send ( TActorId sender,
TActorId recipient,
TMessageId messageId,
TBlob blob )
pure virtual

Low-level send with a pre-serialized blob. Prefer the typed Send<T> overload.

Implemented in NNet::NActors::TActorSystem.


The documentation for this class was generated from the following files:
  • coroio/actors/actor.hpp
  • coroio/actors/actor.cpp