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) final
 Delegate message handling to the current behavior.
Public Member Functions inherited from NNet::NActors::IActor
virtual void AfterRegister (TActorContext::TPtr)
 Called once right after the actor is registered in the system.
virtual void BeforeUnregister (TActorContext::TPtr)
 Called once on PoisonPill, right before the actor is destroyed.

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.

Enables runtime behavior switching — useful for state machines and protocol handlers. Most commonly the actor itself is the initial behavior (Become(this)), but separate TBehavior objects can be stored as members and swapped in.

Usage example:

struct IdleBehavior;
struct ActiveBehavior;
class Connection : public IBehaviorActor,
public TBehavior<Connection, Connect, Data, Disconnect> {
public:
Connection() { Become(this); }
void Receive(Connect&&, TBlob, TActorContext::TPtr ctx) {
connected_ = true;
// next message will already use this actor as behavior (no switch needed)
}
void Receive(Data&& msg, TBlob, TActorContext::TPtr ctx) {
if (!connected_) return;
process(msg.payload);
}
void Receive(Disconnect&&, TBlob, TActorContext::TPtr) {
connected_ = false;
}
void HandleUnknownMessage(TMessageId, TBlob, TActorContext::TPtr) {}
private:
bool connected_ = false;
};
Actor that delegates message handling to a pluggable behavior.
Definition actor.hpp:636
void Receive(TMessageId messageId, TBlob blob, TActorContext::TPtr ctx) final
Delegate message handling to the current behavior.
Definition actor.hpp:657
void Become(IBehavior *behavior)
Switch to a new behavior.
Definition actor.hpp:647
Template for type-safe behavior implementations.
Definition actor.hpp:520
Opaque message payload with Near/Far duality.
Definition messages.hpp:99

Member Function Documentation

◆ Become()

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

Switch to a new behavior.

The switch takes effect on the next incoming message. The behavior pointer must remain valid for the lifetime of the actor — storing behaviors as member variables is the typical pattern.

Parameters
behaviorNon-owning pointer to the new behavior; must not be null

◆ Receive()

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

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: