COROIO: NNet::NActors::TBehavior< TBaseBehavior, TMessages > Class Template Reference
COROIO
 
Loading...
Searching...
No Matches
NNet::NActors::TBehavior< TBaseBehavior, TMessages > Class Template Reference

Template for type-safe behavior implementations. More...

#include <actor.hpp>

Inheritance diagram for NNet::NActors::TBehavior< TBaseBehavior, TMessages >:
NNet::NActors::IBehavior

Public Member Functions

void Receive (TMessageId messageId, TBlob blob, TActorContext::TPtr ctx) override
 Process incoming message with automatic type dispatch.
 

Detailed Description

template<typename TBaseBehavior, typename... TMessages>
class NNet::NActors::TBehavior< TBaseBehavior, TMessages >

Template for type-safe behavior implementations.

Template Parameters
TBaseBehaviorThe concrete behavior class that inherits from this template
TMessagesList of message types this behavior can handle

TBehavior provides automatic message deserialization and type-safe message handling. It supports both synchronous and asynchronous message handlers, automatically detecting the return type.

Usage example:

class MyBehavior : public TBehavior<MyBehavior, MessageA, MessageB> {
public:
void Receive(MessageA&& msg, TBlob blob, TActorContext::TPtr ctx) {
// Handle MessageA synchronously
}
TFuture<void> Receive(MessageB&& msg, TBlob blob, TActorContext::TPtr ctx) {
// Handle MessageB asynchronously
co_await someAsyncOperation();
}
void HandleUnknownMessage(TMessageId messageId, TBlob blob, TActorContext::TPtr ctx) {
// Handle messages not in the template parameter list
}
};
Template for type-safe behavior implementations.
Definition actor.hpp:413
void Receive(TMessageId messageId, TBlob blob, TActorContext::TPtr ctx) override
Process incoming message with automatic type dispatch.
Definition actor.hpp:424
Definition messages.hpp:84
Future type for coroutines returning a value of type T.
Definition corochain.hpp:182

Member Function Documentation

◆ Receive()

template<typename TBaseBehavior , typename... TMessages>
void NNet::NActors::TBehavior< TBaseBehavior, TMessages >::Receive ( TMessageId  messageId,
TBlob  blob,
TActorContext::TPtr  ctx 
)
inlineoverridevirtual

Process incoming message with automatic type dispatch.

Parameters
messageIdType identifier of the message
blobSerialized message data
ctxActor context for communication

This method automatically deserializes the message and calls the appropriate typed Receive method on the derived class.

Implements NNet::NActors::IBehavior.


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