TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
Loading...
Searching...
No Matches
tec::Actor Class Referenceabstract

Abstract base class defining the actor lifecycle and request handling interface. More...

#include <tec_actor.hpp>

Inheritance diagram for tec::Actor:
tec::SocketServer< Params > tec::GrpcClient< TParams, Traits > tec::GrpcServer< TParams, Traits > tec::SocketClient< TParams > tec::SocketServer< TParams > tec::SocketClientNd< TParams > tec::SocketServerNd< TParams >

Public Member Functions

 Actor ()=default
 Default constructor.
 
 Actor (const Actor &)=delete
 Deleted copy constructor.
 
 Actor (Actor &&)=delete
 Deleted move constructor.
 
Actoroperator= (const Actor &)=delete
 Deleted copy assignment operator.
 
Actoroperator= (Actor &&)=delete
 Deleted move assignment operator.
 
virtual ~Actor ()=default
 Virtual destructor.
 
virtual void start (Signal *sig_started, Status *status)=0
 Starts the actor's operation.
 
virtual void shutdown (Signal *sig_stopped)=0
 Initiates graceful shutdown of the actor.
 
virtual Status process_request (Request request, Reply reply)=0
 Processes a single request and produces a reply.
 
virtual Status run ()
 Mimics Daemon's behavior.
 
virtual Status terminate ()
 Mimics Daemon's behavior.
 

Detailed Description

Abstract base class defining the actor lifecycle and request handling interface.

All concrete actors must inherit from this class and implement:

  • start() – asynchronous initialization with completion signal.
  • shutdown() – graceful termination with completion signal.
  • process_request() – core message handling logic.

Actors are typically long-lived services (e.g., gRPC servers, workers) that run in their own thread or event loop until explicitly shut down.

Note
Actors are non-copyable and non-movable to ensure unique ownership.

Constructor & Destructor Documentation

◆ Actor() [1/3]

tec::Actor::Actor ( )
default

Default constructor.

Initializes base actor state. Derived classes should perform minimal setup here and defer heavy initialization to start().

◆ Actor() [2/3]

tec::Actor::Actor ( const Actor )
delete

Deleted copy constructor.

Actors represent unique service instances and must not be copied.

◆ Actor() [3/3]

tec::Actor::Actor ( Actor &&  )
delete

Deleted move constructor.

Prevents accidental transfer of actor ownership.

◆ ~Actor()

virtual tec::Actor::~Actor ( )
virtualdefault

Virtual destructor.

Ensures proper destruction of derived classes when deleted through a base pointer. Derived classes should override if cleanup is needed.

Member Function Documentation

◆ process_request()

virtual Status tec::Actor::process_request ( Request  request,
Reply  reply 
)
pure virtual

Processes a single request and produces a reply.

This is the core message handling entry point. Implementations should:

  • Validate the request
  • Perform necessary work
  • Populate reply with results
  • Return appropriate Status
Parameters
request[in] Input message to process (moved-from if possible).
reply[out] Output message populated with response.
Returns
Status indicating success or specific error condition.
Example
Status s = actor->process_request(req, reply);
if (!s.ok()) { handle_error(s); }
constexpr bool ok() const
Checks if the status indicates success.
Definition tec_status.hpp:120
See also
Request, Reply, Status

Implemented in tec::GrpcClient< TParams, Traits >, tec::SocketClient< TParams >, tec::SocketClientNd< TParams >, tec::SocketServer< TParams >, tec::SocketServer< Params >, and tec::GrpcServer< TParams, Traits >.

◆ shutdown()

virtual void tec::Actor::shutdown ( Signal sig_stopped)
pure virtual

Initiates graceful shutdown of the actor.

Requests the actor to stop processing new requests, complete in-flight work, and terminate cleanly. Completion is signaled via sig_stopped.

Parameters
sig_stopped[in,out] Signal set when shutdown is fully complete. Must remain valid until triggered.
Note
This is typically called from a separate thread.
See also
start()

Implemented in tec::GrpcClient< TParams, Traits >, tec::GrpcServer< TParams, Traits >, tec::SocketClient< TParams >, tec::SocketServer< TParams >, and tec::SocketServer< Params >.

◆ start()

virtual void tec::Actor::start ( Signal sig_started,
Status status 
)
pure virtual

Starts the actor's operation.

This method initiates the actor's internal service (e.g., binding ports, starting threads, entering event loop). It must not block indefinitely unless the actor is designed to run until shutdown() is called.

Completion (success or failure) is signaled via sig_started.

Parameters
sig_started[in,out] Signal set when startup completes. Must remain valid until the signal is triggered.
status[out] Filled with result:
  • Status::Ok() on success
  • Status::Error(Error::Kind::Timeout) on timeout
  • Other errors as defined by implementation
Note
This function may return before startup completes. Use sig_started->wait() to synchronize.
Warning
In long-running actors (e.g. gRPC), this call may not return until shutdown() is invoked from another thread.
See also
shutdown(), Status

Implemented in tec::GrpcClient< TParams, Traits >, tec::GrpcServer< TParams, Traits >, tec::SocketClient< TParams >, tec::SocketServer< TParams >, and tec::SocketServer< Params >.


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