TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
Public Member Functions | Protected Member Functions | List of all members
cpid::ZeroMQBufferedProducer< T > Class Template Reference

A buffered producer that obtains data via ZeroMQ. More...

#include <zmqbufferedproducer.h>

Public Member Functions

 ZeroMQBufferedProducer (uint8_t nthreads, size_t maxQueueSize, std::string endpoint=std::string())
 
 ~ZeroMQBufferedProducer ()
 
std::optional< T > get ()
 
std::string endpoint () const
 
void stop ()
 

Protected Member Functions

void handleRequest (void const *buf, size_t len, ReqRepServer::ReplyFn reply)
 

Detailed Description

template<typename T>
class cpid::ZeroMQBufferedProducer< T >

A buffered producer that obtains data via ZeroMQ.

The intended use-case is for this class to be used together with ZeroMQBufferedConsumer to implement distributed producer-consumer setups. Suppose you have an existing setup that looks like this, with sections of your code producing items of type T and other sections consuming them:

[Producer] -> [Consumer]

Then, assuming that items can be serialized with cereal, the ZeroMQBufferedConsumer/Producer classes enable the following design:

[Producer] -> [ZeroMQBufferedConsumer] | TCP | [ZeroMQBufferedProducer] -> [Consumer]

As in common::BufferedProducer you specify a number of threads in the constructor which will be used to deserialize data. Calling get() returns data. Destructing the object will stop all threads.

Make sure that you're calling get() fast enough; if you expect delays for consumption set maxQueueSize accordingly. If the queue runs full the server will not accept new data from the network.

Constructor & Destructor Documentation

template<typename T >
cpid::ZeroMQBufferedProducer< T >::ZeroMQBufferedProducer ( uint8_t  nthreads,
size_t  maxQueueSize,
std::string  endpoint = std::string() 
)
template<typename T >
cpid::ZeroMQBufferedProducer< T >::~ZeroMQBufferedProducer ( )

Member Function Documentation

template<typename T >
std::string cpid::ZeroMQBufferedProducer< T >::endpoint ( ) const
inline
template<typename T >
std::optional< T > cpid::ZeroMQBufferedProducer< T >::get ( )
template<typename T >
void cpid::ZeroMQBufferedProducer< T >::handleRequest ( void const *  buf,
size_t  len,
ReqRepServer::ReplyFn  reply 
)
protected
template<typename T >
void cpid::ZeroMQBufferedProducer< T >::stop ( )

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