ReCodEx - Task Broker
ReCodEx is complex programmer testing solution, primary targeted to technical universities. It's highly customizable and based on modern technologies.
reactor Class Reference

#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"
 

Detailed Description

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.

Definition at line 123 of file reactor.h.

Constructor & Destructor Documentation

§ reactor()

reactor::reactor ( std::shared_ptr< zmq::context_t >  context)
Parameters
contextA ZeroMQ context used to create sockets for asynchronous communication

Definition at line 7 of file reactor.cpp.

Member Function Documentation

§ add_async_handler()

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).

Parameters
origins
handler

Definition at line 28 of file reactor.cpp.

§ add_handler()

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).

Parameters
originssubscribed origins
handler

Definition at line 19 of file reactor.cpp.

§ add_socket()

void reactor::add_socket ( const std::string &  name,
std::shared_ptr< socket_wrapper_base socket 
)

Add a socket to be polled by the reactor

Parameters
namea name used as the key for messages transmitted through the socket
socket

Definition at line 14 of file reactor.cpp.

§ process_message()

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.

Parameters
messageframes of the message

Definition at line 49 of file reactor.cpp.

§ send_message()

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.

Parameters
messageframes of the message

Definition at line 37 of file reactor.cpp.

§ start_loop()

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.

§ terminate()

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.

Member Data Documentation

§ KEY_TIMER

const std::string reactor::KEY_TIMER = "timer"
static

An origin identifier for messages about elapsed time

Definition at line 129 of file reactor.h.

§ unique_id

const std::string reactor::unique_id

A unique identifier for the asynchronous handler socket

Definition at line 134 of file reactor.h.


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