|
ReCodEx - Task Broker
ReCodEx is complex programmer testing solution, primary targeted to technical universities. It's highly customizable and based on modern technologies.
|
#include <reactor.h>
Public Member Functions | |
| reactor (std::shared_ptr< zmq::context_t > context) | |
| void | add_socket (const std::string &name, std::shared_ptr< socket_wrapper_base > socket) |
| void | add_handler (const std::vector< std::string > &origins, std::shared_ptr< handler_interface > handler) |
| void | add_async_handler (const std::vector< std::string > &origins, std::shared_ptr< handler_interface > handler) |
| void | send_message (const message_container &message) |
| void | process_message (const message_container &message) |
| void | start_loop () |
| void | terminate () |
Public Attributes | |
| const std::string | unique_id |
Static Public Attributes | |
| static const std::string | KEY_TIMER = "timer" |
Provides an event-based API for ZeroMQ network communication. Messages are transferred through registered sockets and processed by handlers who don't have to use ZeroMQ directly. Running the handlers asynchronously is also supported.
| reactor::reactor | ( | std::shared_ptr< zmq::context_t > | context | ) |
| context | A ZeroMQ context used to create sockets for asynchronous communication |
Definition at line 7 of file reactor.cpp.
| void reactor::add_async_handler | ( | const std::vector< std::string > & | origins, |
| std::shared_ptr< handler_interface > | handler | ||
| ) |
Add a handler for messages from given origins that is invoked asynchronously (messages are passed to it through an in-process socket pair, which is also used by the response callback).
| origins | |
| handler |
Definition at line 28 of file reactor.cpp.
| void reactor::add_handler | ( | const std::vector< std::string > & | origins, |
| std::shared_ptr< handler_interface > | handler | ||
| ) |
Add a handler for messages from given origins that is invoked directly (reactor waits for its completion, any calls to a response callback are processed immediately).
| origins | subscribed origins |
| handler |
Definition at line 19 of file reactor.cpp.
| void reactor::add_socket | ( | const std::string & | name, |
| std::shared_ptr< socket_wrapper_base > | socket | ||
| ) |
Add a socket to be polled by the reactor
| name | a name used as the key for messages transmitted through the socket |
| socket |
Definition at line 14 of file reactor.cpp.
| void reactor::process_message | ( | const message_container & | message | ) |
Pass a message received from one of the sockets to the handlers. Public for easier testing and extensibility.
| message | frames of the message |
Definition at line 49 of file reactor.cpp.
| void reactor::send_message | ( | const message_container & | message | ) |
Send a message through one of the sockets. This method is mostly called indirectly by the handlers.
| message | frames of the message |
Definition at line 37 of file reactor.cpp.
| void reactor::start_loop | ( | ) |
Start polling the underlying sockets and invoking handlers if needed. Handlers that need to keep track of elapsed time should subscribe to messages from ORIGIN_TIMER - it will notify them periodically.
The loop can be interrupted using the terminate method. When this happens, all handlers will be destroyed.
Definition at line 58 of file reactor.cpp.
| void reactor::terminate | ( | ) |
Tell the reactor to terminate as soon as possible. This method is thread-safe.
Definition at line 132 of file reactor.cpp.
|
static |
| const std::string reactor::unique_id |