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

Actor that delegates message handling to a pluggable behavior. More...

#include <actor.hpp>

Inheritance diagram for NNet::NActors::IBehaviorActor:
NNet::NActors::IActor

Public Member Functions

void Become (IBehavior *behavior)
 Switch to a new behavior.
 
void Receive (TMessageId messageId, TBlob blob, TActorContext::TPtr ctx) override
 Delegate message handling to the current behavior.
 

Additional Inherited Members

- Public Types inherited from NNet::NActors::IActor
using TPtr = std::unique_ptr< IActor >
 

Detailed Description

Actor that delegates message handling to a pluggable behavior.

IBehaviorActor allows actors to change their message handling behavior dynamically at runtime. This is useful for implementing state machines, protocol handlers, or any actor that needs to change its behavior based on its current state.

Usage example:

class StatefulActor : public IBehaviorActor,
public TBehavior<StatefulActor, InitMessage, WorkMessage> {
public:
StatefulActor() {
Become(this); // Set initial behavior to self
}
void Receive(InitMessage&& msg, TBlob blob, TActorContext::TPtr ctx) {
// Initialize and potentially switch to a different behavior
if (msg.mode == "advanced") {
Become(&advancedBehavior_);
}
}
void HandleUnknownMessage(TMessageId messageId, TBlob blob, TActorContext::TPtr ctx) {
// Handle unknown messages
}
private:
AdvancedBehavior advancedBehavior_;
};
Actor that delegates message handling to a pluggable behavior.
Definition actor.hpp:522
Template for type-safe behavior implementations.
Definition actor.hpp:413
Definition messages.hpp:84

Member Function Documentation

◆ Become()

void NNet::NActors::IBehaviorActor::Become ( IBehavior behavior)
inline

Switch to a new behavior.

Parameters
behaviorPointer to the new behavior to use

After calling Become(), all subsequent messages will be handled by the new behavior until Become() is called again.

◆ Receive()

void NNet::NActors::IBehaviorActor::Receive ( TMessageId  messageId,
TBlob  blob,
TActorContext::TPtr  ctx 
)
inlineoverridevirtual

Delegate message handling to the current behavior.

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

Implements NNet::NActors::IActor.


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