75template <
typename TParams,
typename TActor>
87 std::thread actor_thread_;
102 std::mutex mtx_request_;
124 ,
actor_{std::move(actor)}
127 std::is_base_of_v<Actor, TActor>,
128 "ActorWorker::TActor must derive from tec::Actor");
132 this->
template register_callback<ActorWorker, Payload*>(
157 if (actor_thread_.joinable()) {
158 actor_thread_.join();
178 if (actor_thread_.joinable()) {
184 actor_thread_ = std::thread([
this] {
185 actor_->start(&sig_started_, &status_started_);
191 TEC_TRACE(
"Actor thread {} started with status: {}", actor_thread_.get_id(), status_started_);
192 return status_started_;
210 if (!actor_thread_.joinable()) {
216 std::thread shutdown_thread([
this] {
217 actor_->shutdown(&sig_stopped_);
219 TEC_TRACE(
"Actor thread {} is stopping...", actor_thread_.get_id());
221 TEC_TRACE(
"Actor thread {} stopped.", actor_thread_.get_id());
223 shutdown_thread.join();
224 actor_thread_.join();
247 TEC_TRACE(
"Payload received: {}", msg.type().name());
249 auto payload = std::any_cast<Payload*>(msg);
251 *(payload->status) =
actor_->process_request(
252 std::move(payload->request), std::move(payload->reply));
270 template <
typename WorkerDerived,
typename ActorDerived>
281 std::unique_ptr<Daemon>
284 std::is_base_of_v<ActorWorker, WorkerDerived>,
285 "WorkerDerived must derive from tec::ActorWorker");
287 std::is_base_of_v<Actor, ActorDerived>,
288 "ActorDerived must derive from tec::Actor");
290 return std::make_unique<WorkerDerived>(
292 std::move(std::make_unique<ActorDerived>(
params)));
A Worker that owns and runs an Actor in a dedicated thread.
Definition tec_actor_worker.hpp:76
Status on_init() override
Initializes the worker by starting the actor in a background thread.
Definition tec_actor_worker.hpp:176
Status on_exit() override
Shuts down the actor and joins all threads.
Definition tec_actor_worker.hpp:208
ActorWorker(const ActorWorker &)=delete
Deleted copy constructor.
~ActorWorker() override
Destructor.
Definition tec_actor_worker.hpp:156
ActorWorker(ActorWorker &&)=delete
Deleted move constructor.
ActorWorker(const Params ¶ms, std::unique_ptr< TActor > actor)
Constructs an ActorWorker with parameters and actor ownership.
Definition tec_actor_worker.hpp:122
std::unique_ptr< TActor > actor_
Owned actor instance.
Definition tec_actor_worker.hpp:83
virtual void on_request(const Message &msg)
Handles incoming Payload requests synchronously.
Definition tec_actor_worker.hpp:244
TParams Params
Alias for the parameter type.
Definition tec_actor_worker.hpp:79
A thread-safe signal mechanism for inter-thread synchronization.
Definition tec_signal.hpp:44
void wait() const
Waits indefinitely until the signal is set.
Definition tec_signal.hpp:85
A class implementing message processing as a daemon.
Definition tec_worker.hpp:70
constexpr const Params & params() const
Retrieves the worker's configuration parameters.
Definition tec_worker.hpp:161
std::lock_guard< std::mutex > Lock
Type alias for mutex lock guard.
Definition tec_worker.hpp:74
#define TEC_ENTER(name)
Logs an entry message for a named context (e.g., function).
Definition tec_trace.hpp:211
#define TEC_TRACE(...)
Logs a formatted trace message.
Definition tec_trace.hpp:222
Factory for constructing ActorWorker as a Daemon pointer.
Definition tec_actor_worker.hpp:271
std::unique_ptr< Daemon > operator()(const typename WorkerDerived::Params ¶ms) const
Creates a std::unique_ptr<Daemon> owning the worker.
Definition tec_actor_worker.hpp:282
@ RuntimeErr
Runtime error during execution.
Helper struct to signal termination on exit.
Definition tec_signal.hpp:110
Core interface for TEC actors with lifecycle management and request processing.
Common definitions and utilities for the tec namespace.
std::any Message
Type alias for a message that can hold any object.
Definition tec_message.hpp:43
Defines a thread-safe signal implementation using mutex and condition variable.
Defines error handling types and utilities for the tec namespace.
Provides a thread-safe tracing utility for debugging in the tec namespace.
Defines a worker class for processing messages in the tec namespace.