|
CppZmqZoltanExt 0.0.1
|
Class that implements the Actor pattern using ZMQ PAIR sockets. More...
#include <actor.h>
Public Member Functions | |
| actor_t (zmq::context_t &context) | |
| Constructs a new actor_t object. | |
| actor_t (actor_t const &)=delete | |
| Copy constructor is deleted. | |
| actor_t & | operator= (actor_t const &)=delete |
| Copy assignment operator is deleted. | |
| actor_t (actor_t &&other) noexcept | |
| Move constructor. | |
| actor_t & | operator= (actor_t &&other) noexcept |
| Move assignment operator. | |
| ~actor_t () noexcept | |
| Destroys the actor_t object. | |
| void | start (actor_fn_t func) |
| Starts the actor thread with the provided function. | |
| bool | stop (std::chrono::milliseconds timeout=std::chrono::milliseconds{-1}) |
| Stops the actor thread. | |
| zmq::socket_t & | socket () noexcept |
| Gets the parent socket for external communication. | |
| bool | is_started () const noexcept |
| Checks if the actor thread was started. | |
| bool | is_stopped () const noexcept |
| Checks if the actor thread was stopped. | |
| void | set_destructor_timeout (std::chrono::milliseconds timeout) noexcept |
| Sets the timeout value used in the destructor. | |
| std::chrono::milliseconds | get_destructor_timeout () const noexcept |
| Gets the current timeout value used in the destructor. | |
Class that implements the Actor pattern using ZMQ PAIR sockets.
The Actor provides the functionality of running a user-provided function in a new thread and keeping a pair of zmq sockets for communication between the parent thread and the child thread. It synchronizes the start of the function execution in its start method and the stop of the thread in its stop method.
|
explicit |
Constructs a new actor_t object.
Creates a pair of zmq::sockets of type pair, one for the parent side and other for the child. The parent socket is bound to an automatic self-generated address that is unique for each instance. The child socket is connected to the parent's bound address.
| context | The ZMQ context to be used for creating the sockets |
|
delete |
Copy constructor is deleted.
Actors cannot be copied because they maintain exclusive ownership of the communication sockets and represent a unique execution thread. Copying would violate the single ownership principle and lead to resource conflicts. Use move semantics instead to transfer actor ownership.
|
noexcept |
Move constructor.
Transfers ownership of the actor's communication sockets and execution state from the source actor to this newly constructed actor. The actor object can be moved before or after being started. If moved before start(), the new actor can be started normally. If called after start(), the new actor continues the execution of the original actor's thread. The source actor is left in a valid but empty state where is_started() and is_stopped() return true. Calling stop() on the moved-from actor is a no-op so it can be called in ins destructor.
| other | The source actor to move from. After the move, other is in a valid but empty state. |
|
noexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Move assignment operator.
Transfers ownership of the actor's communication sockets and execution state from the source actor to this actor. The actor object can be moved before or after being started. If moved before start(), the new actor can be started normally. If called after start(), the new actor continues the execution of the original actor's thread. The source actor is left in a valid but empty state where is_started() and is_stopped() return true. Calling stop() on the moved-from actor is a no-op so it can be called in ins destructor.
| other | The source actor to move from. After the move, other is in a valid but empty state. |
Copy assignment operator is deleted.
Actors cannot be copy-assigned because they maintain exclusive ownership of the communication sockets and represent a unique execution thread. Copying would violate the single ownership principle and lead to resource conflicts. Use move semantics instead to transfer actor ownership.
|
inlinenoexcept |
|
inlinenoexcept |
| void zmqzext::actor_t::start | ( | actor_fn_t | func | ) |
Starts the actor thread with the provided function.
Launches a new thread executing the provided function and blocks until receiving a success or failure signal. On success signal, returns normally. On failure signal, rethrows any saved exception from the execute method or throws std::runtime_error.
| func | The function to be executed in the new thread. Must take a zmq::socket_t& and return bool |
| std::runtime_error | If the thread was already started or if the function signals failure during function initialization |
| Rethrows | any exception caught during function initialization |
| bool zmqzext::actor_t::stop | ( | std::chrono::milliseconds | timeout = std::chrono::milliseconds{-1} | ) |
Stops the actor thread.
Sends a stop request message and waits for a response signal using the provided timeout. If timeout is 0, returns immediately after trying to send the stop request. If timeout is negative, blocks indefinitely waiting for the response.
| timeout_ms | The timeout in milliseconds. 0 for non-blocking, negative for infinite |