RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
#include <zmq_endpoint.h>
Public Types | |
typedef std::function< void(std::vector < std::string >)> | AsyncMessageHandler |
typedef std::function < std::vector< std::string > std::vector< std::string >)> | SyncMessageHandler |
typedef std::mutex | SocketLock |
Public Member Functions | |
ZmqEventSource (zmq::socket_t &socket, SocketLock *lock=nullptr) | |
template<typename T > | |
ZmqEventSource (zmq::socket_t &socket, const T &handler, SocketLock *lock=nullptr, typename std::enable_if<!std::is_convertible< decltype(std::declval< T >()(std::declval< std::vector< std::string > >())), std::vector< std::string > >::value, void >::type *=0) | |
template<typename T > | |
ZmqEventSource (zmq::socket_t &socket, const T &handler, SocketLock *lock=nullptr, typename std::enable_if< std::is_convertible< decltype(std::declval< T >()(std::declval< std::vector< std::string > >())), std::vector< std::string > >::value, void >::type *=0) | |
void | init (zmq::socket_t &socket, SocketLock *lock=nullptr) |
virtual int | selectFd () const |
virtual bool | poll () const |
virtual bool | processOne () |
virtual void | handleMessage (const std::vector< std::string > &message) |
virtual std::vector< std::string > | handleSyncMessage (const std::vector< std::string > &message) |
zmq::socket_t & | socket () const |
SocketLock * | socketLock () const |
Public Attributes | |
AsyncMessageHandler | asyncMessageHandler |
SyncMessageHandler | syncMessageHandler |
zmq::socket_t * | socket_ |
SocketLock * | socketLock_ |
Adaptor that allows any zeromq socket to hook into an event loop.
Definition at line 32 of file zmq_endpoint.h.
Datacratic::ZmqEventSource::ZmqEventSource | ( | zmq::socket_t & | socket, |
const T & | handler, | ||
SocketLock * | lock = nullptr , |
||
typename std::enable_if<!std::is_convertible< decltype(std::declval< T >()(std::declval< std::vector< std::string > >())), std::vector< std::string > >::value, void >::type * | = 0 |
||
) | [inline] |
Construct the event source from a function object that returns something that is not convertible to a std::vector<std::string>. This will cause the asynchronous message handler to be replaced by the passed function.
Definition at line 54 of file zmq_endpoint.h.
Datacratic::ZmqEventSource::ZmqEventSource | ( | zmq::socket_t & | socket, |
const T & | handler, | ||
SocketLock * | lock = nullptr , |
||
typename std::enable_if< std::is_convertible< decltype(std::declval< T >()(std::declval< std::vector< std::string > >())), std::vector< std::string > >::value, void >::type * | = 0 |
||
) | [inline] |
Construct the event source from a function object that returns a std::vector<std::string>. This will cause the synchronous message handler to be replaced by the passed function.
Definition at line 69 of file zmq_endpoint.h.
void Datacratic::ZmqEventSource::handleMessage | ( | const std::vector< std::string > & | message | ) | [virtual] |
Handle a message. The default implementation will call syncMessageHandler if it is defined; otherwise it calls handleSyncMessage and writes back the response to the socket.
Reimplemented in Datacratic::ZmqTypedEventSource< T >, and Datacratic::ZmqMessageRouter.
Definition at line 112 of file zmq_endpoint.cc.
std::vector< std::string > Datacratic::ZmqEventSource::handleSyncMessage | ( | const std::vector< std::string > & | message | ) | [virtual] |
Handle a message and write a synchronous response. This will forward to asyncMessageHandler if defined, or otherwise throw an exception.
Definition at line 127 of file zmq_endpoint.cc.
bool Datacratic::ZmqEventSource::poll | ( | ) | const [virtual] |
Returns true if there is work to be done. May be called from more than one thread. Should never block.
Reimplemented from Datacratic::AsyncEventSource.
Definition at line 62 of file zmq_endpoint.cc.
bool Datacratic::ZmqEventSource::processOne | ( | ) | [virtual] |
Process a single message and return true if there are more to be processed.
This may be called from more than one thread if singleThreaded() is false.
NOTE: poll() will only work after we've tried (and failed) to pull a message off.
Implements Datacratic::AsyncEventSource.
Definition at line 82 of file zmq_endpoint.cc.
int Datacratic::ZmqEventSource::selectFd | ( | ) | const [virtual] |
Return the file descriptor on which one should select() for messages from this source. The source should organize itself such that if the fd indicates ready for a read, there is something to do.
Should return -1 if it requires polling.
Should never block.
Reimplemented from Datacratic::AsyncEventSource.
Definition at line 48 of file zmq_endpoint.cc.