ZeroEQ
0.6.0
ZeroEQ - Zero Event Queue
|
Brokers subscription requests for a zeroeq::Receiver. More...
#include <broker.h>
Public Types | |
enum | PortSelection { PORT_FIXED, PORT_FIXED_OR_RANDOM } |
Public Member Functions | |
Broker (const std::string &name, Receiver &receiver, const PortSelection mode) | |
Convenience constructor to create a new subscription broker. More... | |
Broker (const std::string &address, Receiver &receiver) | |
Create a new subscription broker. More... | |
~Broker () | |
Destroy this broker. More... | |
std::string | getAddress () const |
Public Member Functions inherited from zeroeq::Receiver | |
Receiver () | |
Create a new standalone receiver. More... | |
Receiver (Receiver &shared) | |
Create a shared receiver. More... | |
virtual | ~Receiver () |
Destroy this receiver. More... | |
bool | receive (const uint32_t timeout=TIMEOUT_INDEFINITE) |
Receive at least one event from all shared receivers. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from zeroeq::Receiver | |
virtual void | addSockets (std::vector< detail::Socket > &entries)=0 |
Add this receiver's sockets to the given list. | |
virtual void | process (detail::Socket &socket, uint32_t timeout)=0 |
Process data on a signalled socket. More... | |
virtual void | update () |
Update the internal connection list. More... | |
void * | getZMQContext () |
Brokers subscription requests for a zeroeq::Receiver.
Example:
zeroeq::connection::Broker::Broker | ( | const std::string & | name, |
Receiver & | receiver, | ||
const PortSelection | mode | ||
) |
Convenience constructor to create a new subscription broker.
This constructor will try to bind to INADDR_ANY and a fixed port derived from the given name. If that fails, it will throw a std::runtime_error (if mode is PORT_FIXED) or allocate a random port (if mode is PORT_FIXED_OR_RANDOM).
The name should be a string of the application's namespace, e.g., "livre". The same string should be used by Service::subscribe(). A hashing algorithm is used to derive the port from the name. This yields a fixed port number, therefore only a single application per machine can run one broker. If the random port fallback is enabled, this constructor will allocate a random available port.
name | the application namespace. |
receiver | the Receiver to manage. |
mode | the allocation strategy if the fixed port is unavailable. |
std::runtime_error | when the zmq setup failed. |
zeroeq::connection::Broker::Broker | ( | const std::string & | address, |
Receiver & | receiver | ||
) |
Create a new subscription broker.
The given receiver has to have at least the same lifetime as this broker. The receiver and broker are automatically shared.
For simplicity, only a single Receiver is handled by a Broker. The implementation should be extended if multiple receivers shall be handled.
address | the zmq reply socket address to be used. |
receiver | the Receiver to manage. |
std::runtime_error | when the zmq setup failed. |
zeroeq::connection::Broker::~Broker | ( | ) |
Destroy this broker.