TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
Classes | Public Types | Public Member Functions | List of all members
cpid::ReqRepClient Class Referencefinal

A request-reply client backed by ZeroMQ. More...

#include <reqrepserver.h>

Public Types

using Clock = std::chrono::steady_clock
 
using TimePoint = std::chrono::time_point< Clock >
 
using Blob = std::vector< char >
 

Public Member Functions

 ReqRepClient (size_t maxConcurrentRequests, std::vector< std::string > endpoints, std::shared_ptr< zmq::context_t > context=nullptr)
 
 ~ReqRepClient ()
 
std::future< std::vector< char > > request (std::vector< char > msg)
 
bool updateEndpoints (std::vector< std::string > endpoints)
 Returns true if the endpoints changed. More...
 
void setReplyTimeout (std::chrono::milliseconds timeout)
 
void setReplyTimeoutMs (size_t timeoutMs)
 
void setMaxRetries (size_t count)
 

Detailed Description

A request-reply client backed by ZeroMQ.

This class provides a futures-based interface to the request-reply pattern. You call request() and get a future fo your (future) reply. Note that requests() will always happily accept the request and move into in internal queue. This queue is unbounded – if this is a concern you should add some manual blocking logic; see ZeroMQBufferedConsumer() for an example.

The client can be connected to multiple ReqRepServers and will send out requests in a round-robin fashion. The number of concurrent replies that can be sent is controlled with the maxConcurrentRequests parameter. There are some basic robustness guarantees regarding slow or crashing servers: if a server does not send a reply in time, retries will be attempted. The number of retries can be limited; in this case, the future will be fulfilled with an exception. The server list can be updated loss of messages.

Member Typedef Documentation

using cpid::ReqRepClient::Blob = std::vector<char>
using cpid::ReqRepClient::Clock = std::chrono::steady_clock
using cpid::ReqRepClient::TimePoint = std::chrono::time_point<Clock>

Constructor & Destructor Documentation

cpid::ReqRepClient::ReqRepClient ( size_t  maxConcurrentRequests,
std::vector< std::string >  endpoints,
std::shared_ptr< zmq::context_t >  context = nullptr 
)
cpid::ReqRepClient::~ReqRepClient ( )

Member Function Documentation

std::future< std::vector< char > > cpid::ReqRepClient::request ( std::vector< char >  msg)
void cpid::ReqRepClient::setMaxRetries ( size_t  count)
void cpid::ReqRepClient::setReplyTimeout ( std::chrono::milliseconds  timeout)
inline
void cpid::ReqRepClient::setReplyTimeoutMs ( size_t  timeoutMs)
bool cpid::ReqRepClient::updateEndpoints ( std::vector< std::string >  endpoints)

Returns true if the endpoints changed.


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