COROIO: NNet::NActors::TActorContext Class Reference
COROIO
 
Loading...
Searching...
No Matches
NNet::NActors::TActorContext Class Reference

Context object providing actor communication and scheduling capabilities. More...

#include <actor.hpp>

Inheritance diagram for NNet::NActors::TActorContext:
NNet::NActors::TMockActorContext

Classes

struct  TAsync
 Helper class for managing asynchronous operations in actors. More...
 

Public Types

using TPtr = std::unique_ptr< TActorContext >
 

Public Member Functions

TActorId Sender () const
 Get the sender of the current message.
 
TActorId Self () const
 Get this actor's ID.
 
void Send (TActorId to, TMessageId messageId, TBlob blob)
 Send a message to another actor.
 
void Forward (TActorId to, TMessageId messageId, TBlob blob)
 Forward a message to another actor (preserves original sender)
 
template<typename T , typename... Args>
void Send (TActorId to, Args &&... args)
 Send a typed message to another actor.
 
template<typename T , typename... Args>
void Forward (TActorId to, Args &&... args)
 Forward a typed message to another actor.
 
TEvent Schedule (TTime when, TActorId sender, TActorId recipient, TMessageId messageId, TBlob blob)
 Schedule a message to be delivered at a specific time.
 
template<typename T , typename... Args>
TEvent Schedule (TTime when, TActorId sender, TActorId recipient, Args &&... args)
 Schedule a typed message to be delivered at a specific time.
 
void Cancel (TEvent event)
 Cancel a previously scheduled message.
 
TFuture< void > Sleep (TTime until)
 Sleep until a specific time.
 
template<typename Rep , typename Period >
TFuture< void > Sleep (std::chrono::duration< Rep, Period > duration)
 Sleep for a specific duration.
 
template<typename T , typename TQuestion >
TFuture< T > Ask (TActorId recipient, TQuestion &&question)
 Send a message and wait for a response.
 
TAsync StartAsync ()
 Start an asynchronous operation context.
 

Static Public Member Functions

static void * operator new (size_t size, TActorSystem *actorSystem)
 
static void operator delete (void *ptr)
 

Friends

class TActorSystem
 
class TMockActorContext
 

Detailed Description

Context object providing actor communication and scheduling capabilities.

TActorContext is passed to actors when they receive messages. It provides methods for sending messages, scheduling future messages, sleeping, and performing request-response patterns.

The context contains information about the current message sender and the actor's own ID. It also manages asynchronous operations through the actor system.

Member Function Documentation

◆ Ask()

template<typename T , typename TQuestion >
TFuture< T > NNet::NActors::TActorContext::Ask ( TActorId  recipient,
TQuestion &&  question 
)
inline

Send a message and wait for a response.

Template Parameters
TExpected response message type
TQuestionQuestion message type
Parameters
recipientActor to send the question to
questionQuestion message to send
Returns
Future containing the response message

◆ Cancel()

void NNet::NActors::TActorContext::Cancel ( TEvent  event)

Cancel a previously scheduled message.

Parameters
eventEvent handle returned by Schedule()

◆ Forward() [1/2]

template<typename T , typename... Args>
void NNet::NActors::TActorContext::Forward ( TActorId  to,
Args &&...  args 
)
inline

Forward a typed message to another actor.

Template Parameters
TMessage type that has MessageId static member
Parameters
toRecipient actor ID
argspassed to Message constructor

◆ Forward() [2/2]

void NNet::NActors::TActorContext::Forward ( TActorId  to,
TMessageId  messageId,
TBlob  blob 
)

Forward a message to another actor (preserves original sender)

Parameters
toRecipient actor ID
messageIdMessage type identifier
blobSerialized message data

◆ Schedule() [1/2]

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

Schedule a typed message to be delivered at a specific time.

Template Parameters
TMessage type that has MessageId static member
Parameters
whenTime when the message should be delivered
senderSender actor ID for the scheduled message
recipientRecipient actor ID
argsargs passed to the Message constructor
Returns
Event handle that can be used to cancel the scheduled message

◆ Schedule() [2/2]

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

Schedule a message to be delivered at a specific time.

Parameters
whenTime when the message should be delivered
senderSender actor ID for the scheduled message
recipientRecipient actor ID
messageIdMessage type identifier
blobSerialized message data
Returns
Event handle that can be used to cancel the scheduled message

◆ Send() [1/2]

template<typename T , typename... Args>
void NNet::NActors::TActorContext::Send ( TActorId  to,
Args &&...  args 
)
inline

Send a typed message to another actor.

Template Parameters
TMessage type that has MessageId static member
Parameters
toRecipient actor ID
argspassed to Message constructor

◆ Send() [2/2]

void NNet::NActors::TActorContext::Send ( TActorId  to,
TMessageId  messageId,
TBlob  blob 
)

Send a message to another actor.

Parameters
toRecipient actor ID
messageIdMessage type identifier
blobSerialized message data

◆ Sleep() [1/2]

template<typename Rep , typename Period >
TFuture< void > NNet::NActors::TActorContext::Sleep ( std::chrono::duration< Rep, Period >  duration)
inline

Sleep for a specific duration.

Template Parameters
RepDuration representation type
PeriodDuration period type
Parameters
durationHow long to sleep
Returns
Future that completes when the sleep duration has elapsed

◆ Sleep() [2/2]

TFuture< void > NNet::NActors::TActorContext::Sleep ( TTime  until)
inline

Sleep until a specific time.

Parameters
untilTime to sleep until
Returns
Future that completes when the sleep time is reached

◆ StartAsync()

TActorContext::TAsync NNet::NActors::TActorContext::StartAsync ( )

Start an asynchronous operation context.

Returns
TAsync helper for managing the async operation

The documentation for this class was generated from the following files: